On 7/16/23 10:40 PM, P Jeevitha via Gcc-patches wrote: > Normally, GPR2 is the TOC pointer and is defined as a fixed and non-volatile > register. However, it can be used as volatile for PCREL addressing. Therefore, > modified r2 to be non-fixed in FIXED_REGISTERS and set it to fixed if it is > not > PCREL and also when the user explicitly requests TOC or fixed. If the register > r2 is fixed, it is made as non-volatile. Changes in register preservation > roles > can be accomplished with the help of available target hooks > (TARGET_CONDITIONAL_REGISTER_USAGE). > > 2023-07-12 Jeevitha Palanisamy <jeevi...@linux.ibm.com> > > gcc/ > PR target/PR110320 > * config/rs6000/rs6000.cc (rs6000_conditional_register_usage): Change > GPR2 to volatile and non-fixed register for PCREL. > > gcc/testsuite/ > PR target/PR110320 > * gcc.target/powerpc/pr110320-1.c: New testcase. > * gcc.target/powerpc/pr110320-2.c: New testcase. > * gcc.target/powerpc/pr110320-3.c: New testcase. > > diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc > index 44b448d2ba6..9aa04ec5d57 100644 > --- a/gcc/config/rs6000/rs6000.cc > +++ b/gcc/config/rs6000/rs6000.cc > @@ -10193,9 +10193,13 @@ rs6000_conditional_register_usage (void) > for (i = 32; i < 64; i++) > fixed_regs[i] = call_used_regs[i] = 1; > > + /* For non PC-relative code, GPR2 is unavailable for register allocation. > */ > + if (FIXED_R2 && !rs6000_pcrel_p ()) > + fixed_regs[2] = 1; > + > /* The TOC register is not killed across calls in a way that is > visible to the compiler. */ > - if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) > + if (fixed_regs[2] && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)) > call_used_regs[2] = 0;
Segher and Ke Wen, As we discussed on my PR111045 patch that disabled PCREL on everything other than ELFv2 and Segher said, well, it should work on ELFv1, modulo fixing bugs. Segher said we should attempt to fix those bugs before we ship the next release and if we miss that, we can push my PR111045 patch then to disable it. On a related note, Jeevitha's patch above allows using r2 for normal register allocation if r2 is not fixed and pcrel is enabled. Given pcrel with this patch enables pcrel on ELFv1, that means this patch can also enable using r2 for normal register allocation on ELFv1. Is that safe? Should we add a check above where we set fixed_regs[2] = 1, to also check for whether this is not an ELFv2 compile? ...or Segher, should we leave this as is and add it to the things to check for non-ELFv2 compiles before the next release and possible disable it then if we know/aren't sure whether it legal? So I guessing I'm wondering, should Jeevitha push the above approved patch as is, or should we modify it so r2 is only available for RA on ELFv2 and pcrel? Peter