Revision 235876 inadvertently caused the TOC reg to be marked as set up in prologue, which prevents shrink-wrapping from moving the prologue past a TOC reference. The following patch corrects the situation.
Bootstrap/regtest on powerpc64le-linux and powerpc64-linux(-m32/-m64) with no new regressions. Ok for trunk? -Pat 2017-09-14 Pat Haugen <pthau...@us.ibm.com> * config/rs6000/rs6000.c (rs6000_set_up_by_prologue): Make sure the TOC reg (r2) isn't in the set of registers defined in the prologue. testsuite/ChangeLog: 2017-09-14 Pat Haugen <pthau...@us.ibm.com> * gcc.target/powerpc/r2_shrink-wrap.c: New.
Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 252029) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -37807,6 +37807,11 @@ rs6000_set_up_by_prologue (struct hard_r add_to_hard_reg_set (&set->set, Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); if (cfun->machine->split_stack_argp_used) add_to_hard_reg_set (&set->set, Pmode, 12); + + /* Make sure the hard reg set doesn't include r2, which was possibly added + via PIC_OFFSET_TABLE_REGNUM. */ + if (TARGET_TOC) + remove_from_hard_reg_set (&set->set, Pmode, TOC_REGNUM); } Index: gcc/testsuite/gcc.target/powerpc/r2_shrink-wrap.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/r2_shrink-wrap.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/r2_shrink-wrap.c (working copy) @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-pro_and_epilogue" } */ + +void bar(); +int j; +void foo(int i) +{ + j = i; + if (i > 0) + { + bar(); + } +} + +/* { dg-final { scan-rtl-dump-times "Performing shrink-wrapping" 1 "pro_and_epilogue" } } */