Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppc32 always reserves r2 #38903

Open
shenki mannequin opened this issue Nov 5, 2018 · 4 comments
Open

ppc32 always reserves r2 #38903

shenki mannequin opened this issue Nov 5, 2018 · 4 comments
Labels
backend:PowerPC bugzilla Issues migrated from bugzilla

Comments

@shenki
Copy link
Mannequin

shenki mannequin commented Nov 5, 2018

Bugzilla Link 39555
Version trunk
OS Linux
CC @hfinkel,@nickdesaulniers,@nemanjai

Extended Description

The PowerPC 32-bit port always reserves r2:

lib/Target/PowerPC/PPCRegisterInfo.cpp:

// The SVR4 ABI reserves r2 and r13
if (Subtarget.isSVR4ABI()) {
// We only reserve r2 if we need to use the TOC pointer. If we have no
// explicit uses of the TOC pointer (meaning we're a leaf function with
// no constant-pool loads, etc.) and we have no potential uses inside an
// inline asm block, then we can treat r2 has an ordinary callee-saved
// register.
const PPCFunctionInfo *FuncInfo = MF.getInfo();
if (!TM.isPPC64() || FuncInfo->usesTOCBasePtr() || MF.hasInlineAsm())
markSuperRegs(Reserved, PPC::R2); // System-reserved register
markSuperRegs(Reserved, PPC::R13); // Small Data Area pointer register
}

This is useful for eg. Linux kernel, but other programs many not need to reserve r2 and could instead allow the compiler to use it.

In order to support this clang would need a -ffixed-r2 flag (similar to GCC) that allows programs such Linux to reserve r2.

@nemanjai
Copy link
Member

I am not sure what conditions you are referring to where we need not reserve R2 on PPC32. Can you elaborate a bit? Also, can you provide a link to the GCC option? I can't find it in the GCC manual.

@shenki
Copy link
Mannequin Author

shenki mannequin commented May 27, 2020

Here's the context from the kernel patch:

https://lore.kernel.org/linuxppc-dev/20181105231207.GB5994@gate.crashing.org/

The option is called -ffixed-reg in the gcc manual.

@nemanjai
Copy link
Member

Correct me if I am misunderstanding the linked discussion as well as the purpose of this PR. It seems that clang's behaviour is correct but conservative.

Basically, if we had -ffixed-r2, it would simply do what we currently do without the option.

And the purpose of this PR is to relax this "always reserved" behaviour to respect -ffixed-r2 so that the register allocator would have one more register to work with?

@nemanjai
Copy link
Member

According to the ELF 32-bit ABI:
Register r2 is reserved for system use and should not be changed by application code.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

1 participant