Re: PowerPC prologue and epilogue 5

2012-04-24 Thread David Edelsohn
On Thu, Apr 19, 2012 at 11:36 AM, Alan Modra amo...@gmail.com wrote:
 On Thu, Apr 19, 2012 at 08:00:15PM +0930, Alan Modra wrote:
 On Wed, Apr 18, 2012 at 12:45:16AM +0930, Alan Modra wrote:
  This enables out-of-line save and restore for large frames, and for
  ABI_AIX when using the static chain.

 Further testing revealed two problems when compiling nested
 functions.
 1) The logic I had for cr_save_regno is wrong, resulting in one of my
    NOT_INUSE asserts triggering.

 Fixed in this revised patch.  Bootstrapped etc. powerpc-linux.

 2) In some cases the prologue uses in-line saves while the epilogue
    uses out-of-line restores.  This can lead to restoring regs that
    haven't been saved.

 This turned out to be a pre-existing problem, patch in PR50340.

        * config/rs6000/rs6000.c (rs6000_savres_strategy): Allow
        out-of-line save/restore for large frames.  Don't disable
        out-of-line saves on ABI_AIX when using static chain reg.
        (rs6000_emit_prologue): Adjust cr_save_regno on ABI_AIX to not
        clobber static chain reg, and tweak for out-of-line gpr saves
        that use r1.

This patch is okay.

Thanks, David


Re: PowerPC prologue and epilogue 5

2012-04-19 Thread Alan Modra
On Wed, Apr 18, 2012 at 12:45:16AM +0930, Alan Modra wrote:
 This enables out-of-line save and restore for large frames, and for
 ABI_AIX when using the static chain.

Further testing revealed two problems when compiling nested
functions.
1) The logic I had for cr_save_regno is wrong, resulting in one of my
   NOT_INUSE asserts triggering.
2) In some cases the prologue uses in-line saves while the epilogue
   uses out-of-line restores.  This can lead to restoring regs that
   haven't been saved.

Patch withdrawn.

-- 
Alan Modra
Australia Development Lab, IBM


Re: PowerPC prologue and epilogue 5

2012-04-19 Thread Alan Modra
On Thu, Apr 19, 2012 at 08:00:15PM +0930, Alan Modra wrote:
 On Wed, Apr 18, 2012 at 12:45:16AM +0930, Alan Modra wrote:
  This enables out-of-line save and restore for large frames, and for
  ABI_AIX when using the static chain.
 
 Further testing revealed two problems when compiling nested
 functions.
 1) The logic I had for cr_save_regno is wrong, resulting in one of my
NOT_INUSE asserts triggering.

Fixed in this revised patch.  Bootstrapped etc. powerpc-linux.

 2) In some cases the prologue uses in-line saves while the epilogue
uses out-of-line restores.  This can lead to restoring regs that
haven't been saved.

This turned out to be a pre-existing problem, patch in PR50340.

* config/rs6000/rs6000.c (rs6000_savres_strategy): Allow
out-of-line save/restore for large frames.  Don't disable
out-of-line saves on ABI_AIX when using static chain reg.
(rs6000_emit_prologue): Adjust cr_save_regno on ABI_AIX to not
clobber static chain reg, and tweak for out-of-line gpr saves
that use r1.

diff -urp gcc-alan5a/gcc/config/rs6000/rs6000.c 
gcc-alan5/gcc/config/rs6000/rs6000.c
--- gcc-alan5a/gcc/config/rs6000/rs6000.c   2012-04-19 21:24:46.643632761 
+0930
+++ gcc-alan5/gcc/config/rs6000/rs6000.c2012-04-19 20:55:02.214727782 
+0930
@@ -17432,8 +17432,7 @@ rs6000_savres_strategy (rs6000_stack_t *
 strategy |= SAVRES_MULTIPLE;
 
   if (crtl-calls_eh_return
-  || cfun-machine-ra_need_lr
-  || info-total_size  32767)
+  || cfun-machine-ra_need_lr)
 strategy |= (SAVE_INLINE_FPRS | REST_INLINE_FPRS
 | SAVE_INLINE_GPRS | REST_INLINE_GPRS);
 
@@ -17454,8 +17453,8 @@ rs6000_savres_strategy (rs6000_stack_t *
   /* Don't bother to try to save things out-of-line if r11 is occupied
  by the static chain.  It would require too much fiddling and the
  static chain is rarely used anyway.  FPRs are saved w.r.t the stack
- pointer on Darwin.  */
-  if (using_static_chain_p)
+ pointer on Darwin, and AIX uses r1 or r12.  */
+  if (using_static_chain_p  DEFAULT_ABI != ABI_AIX)
 strategy |= ((DEFAULT_ABI == ABI_DARWIN
  ? 0 : SAVE_INLINE_FPRS | REST_INLINE_FPRS)
 | SAVE_INLINE_GPRS);
@@ -19555,11 +19554,16 @@ rs6000_emit_prologue (void)
}
 }
 
-  /* If we need to save CR, put it into r12 or r11.  */
-  cr_save_regno = DEFAULT_ABI == ABI_AIX  !saving_GPRs_inline ? 11 : 12;
+  /* If we need to save CR, put it into r12 or r11.  Choose r12 except when
+ r12 will be needed by out-of-line gpr restore.  */
+  cr_save_regno = (DEFAULT_ABI == ABI_AIX
+   !(strategy  (SAVE_INLINE_GPRS
+   | SAVE_NOINLINE_GPRS_SAVES_LR))
+  ? 11 : 12);
   if (!WORLD_SAVE_P (info)
info-cr_save_p
-   REGNO (frame_reg_rtx) != cr_save_regno)
+   REGNO (frame_reg_rtx) != cr_save_regno
+   !(using_static_chain_p  cr_save_regno == 11))
 {
   rtx set;
 
-- 
Alan Modra
Australia Development Lab, IBM


PowerPC prologue and epilogue 5

2012-04-17 Thread Alan Modra
This enables out-of-line save and restore for large frames, and for
ABI_AIX when using the static chain.

* config/rs6000/rs6000.c (rs6000_savres_strategy): Allow
out-of-line save/restore for large frames.  Don't disable
out-of-line saves on ABI_AIX when using static chain reg.
(rs6000_emit_prologue): Adjust cr_save_regno on ABI_AIX to not
clobber static chain reg, and tweak for out-of-line gpr saves
that use r1.

diff -urp gcc-alan4/gcc/config/rs6000/rs6000.c 
gcc-alan5/gcc/config/rs6000/rs6000.c
--- gcc-alan4/gcc/config/rs6000/rs6000.c2012-04-17 09:11:31.760669589 
+0930
+++ gcc-alan5/gcc/config/rs6000/rs6000.c2012-04-17 11:16:09.369537832 
+0930
@@ -17432,8 +17432,7 @@ rs6000_savres_strategy (rs6000_stack_t *
 strategy |= SAVRES_MULTIPLE;
 
   if (crtl-calls_eh_return
-  || cfun-machine-ra_need_lr
-  || info-total_size  32767)
+  || cfun-machine-ra_need_lr)
 strategy |= (SAVE_INLINE_FPRS | REST_INLINE_FPRS
 | SAVE_INLINE_GPRS | REST_INLINE_GPRS);
 
@@ -17454,10 +17453,10 @@ rs6000_savres_strategy (rs6000_stack_t *
   /* Don't bother to try to save things out-of-line if r11 is occupied
  by the static chain.  It would require too much fiddling and the
  static chain is rarely used anyway.  FPRs are saved w.r.t the stack
- pointer on Darwin.  */
-  if (using_static_chain_p)
-strategy |= (DEFAULT_ABI == ABI_DARWIN ? 0 : SAVE_INLINE_FPRS)
-   | SAVE_INLINE_GPRS;
+ pointer on Darwin, and AIX uses r1 or r12.  */
+  if (using_static_chain_p  DEFAULT_ABI != ABI_AIX)
+strategy |= ((DEFAULT_ABI == ABI_DARWIN ? 0 : SAVE_INLINE_FPRS)
+| SAVE_INLINE_GPRS);
 
   /* If we are going to use store multiple, then don't even bother
  with the out-of-line routines, since the store-multiple
@@ -19555,7 +19554,10 @@ rs6000_emit_prologue (void)
 }
 
   /* If we need to save CR, put it into r12 or r11.  */
-  cr_save_regno = DEFAULT_ABI == ABI_AIX  !saving_GPRs_inline ? 11 : 12;
+  cr_save_regno = (DEFAULT_ABI == ABI_AIX
+   (strategy  SAVE_INLINE_GPRS) == 0
+   (strategy  SAVE_NOINLINE_GPRS_SAVES_LR) == 0
+   !using_static_chain_p ? 11 : 12);
   if (!WORLD_SAVE_P (info)
info-cr_save_p
REGNO (frame_reg_rtx) != cr_save_regno)

-- 
Alan Modra
Australia Development Lab, IBM