rs6000: Save the PIC reg when needed
authorsegher <segher@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Oct 2015 19:27:22 +0000 (19:27 +0000)
committersegher <segher@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Oct 2015 19:27:22 +0000 (19:27 +0000)
The PIC reg (r30) needs to be saved whenever the prologue sets it up,
not just if it is used elsewhere in the function.  Without this patch
the prologue for such a function will modify r30 without saving it
first, leading to disaster back in its callers.  This happened in the
testsuite for -m32 libgfortran and libstdc++, bootstrapped with -mlra,
many hundred times.

2015-10-29  Segher Boessenkool  <segher@kernel.crashing.org>

* config/rs6000/rs6000.c (rs6000_reg_live_or_pic_offset_p): Move this
function earlier in the file.
(first_reg_to_save): Use rs6000_reg_live_or_pic_offset_p instead of
df_regs_ever_live_p.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229552 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/rs6000/rs6000.c

index 75ba2e8..50fc56f 100644 (file)
@@ -1,5 +1,12 @@
 2015-10-29  Segher Boessenkool  <segher@kernel.crashing.org>
 
+       * config/rs6000/rs6000.c (rs6000_reg_live_or_pic_offset_p): Move this
+       function earlier in the file.
+       (first_reg_to_save): Use rs6000_reg_live_or_pic_offset_p instead of
+       df_regs_ever_live_p.
+
+2015-10-29  Segher Boessenkool  <segher@kernel.crashing.org>
+
        * lra-constraints.c (process_address_1): Handle (mem:BLK (scratch))
        by ignoring it.
 
index 21b4347..bbdd142 100644 (file)
@@ -22016,6 +22016,27 @@ save_reg_p (int r)
   return !call_used_regs[r] && df_regs_ever_live_p (r);
 }
 
+/* Determine whether the gp REG is really used.  */
+
+static bool
+rs6000_reg_live_or_pic_offset_p (int reg)
+{
+  /* If the function calls eh_return, claim used all the registers that would
+     be checked for liveness otherwise.  This is required for the PIC offset
+     register with -mminimal-toc on AIX, as it is advertised as "fixed" for
+     register allocation purposes in this case.  */
+
+  return (((crtl->calls_eh_return || df_regs_ever_live_p (reg))
+           && (!call_used_regs[reg]
+               || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM
+                  && !TARGET_SINGLE_PIC_BASE
+                   && TARGET_TOC && TARGET_MINIMAL_TOC)))
+          || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM
+             && !TARGET_SINGLE_PIC_BASE
+              && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
+                  || (DEFAULT_ABI == ABI_DARWIN && flag_pic))));
+}
+
 /* Return the first fixed-point register that is required to be
    saved. 32 if none.  */
 
@@ -22033,7 +22054,7 @@ first_reg_to_save (void)
       && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
          || (DEFAULT_ABI == ABI_DARWIN && flag_pic)
          || (TARGET_TOC && TARGET_MINIMAL_TOC))
-      && df_regs_ever_live_p (RS6000_PIC_OFFSET_TABLE_REGNUM))
+      && rs6000_reg_live_or_pic_offset_p (RS6000_PIC_OFFSET_TABLE_REGNUM))
     first_reg = RS6000_PIC_OFFSET_TABLE_REGNUM;
 
 #if TARGET_MACHO
@@ -24232,27 +24253,6 @@ rs6000_emit_move_from_cr (rtx reg)
   emit_insn (gen_movesi_from_cr (reg));
 }
 
-/* Determine whether the gp REG is really used.  */
-
-static bool
-rs6000_reg_live_or_pic_offset_p (int reg)
-{
-  /* If the function calls eh_return, claim used all the registers that would
-     be checked for liveness otherwise.  This is required for the PIC offset
-     register with -mminimal-toc on AIX, as it is advertised as "fixed" for
-     register allocation purposes in this case.  */
-
-  return (((crtl->calls_eh_return || df_regs_ever_live_p (reg))
-           && (!call_used_regs[reg]
-               || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM
-                  && !TARGET_SINGLE_PIC_BASE
-                   && TARGET_TOC && TARGET_MINIMAL_TOC)))
-          || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM
-             && !TARGET_SINGLE_PIC_BASE
-              && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
-                  || (DEFAULT_ABI == ABI_DARWIN && flag_pic))));
-}
-
 /* Return whether the split-stack arg pointer (r12) is used.  */
 
 static bool