Bootstrap and regression tested powerpc64le-linux.  Fixes 771 Go
testsuite regressions.  OK to apply everywhere?

The alternative of adding all parameter regs used by cfun to the
__morestack CALL_INSN_FUNCTION_USAGE and uses for cfun return value
regs seems overkill when all we need to do is protect a very small
sequence of insns.

        PR target/70947
        * config/rs6000/rs6000.c (rs6000_expand_split_stack_prologue): Stop
        regrename modifying insns saving lr before __morestack call.
        * config/rs6000/rs6000.md (split_stack_return): Similarly for
        insns restoring lr after __morestack call.

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index ceb3705..0660427 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -27970,6 +27970,11 @@ rs6000_expand_split_stack_prologue (void)
                                   const0_rtx, const0_rtx));
   call_fusage = NULL_RTX;
   use_reg (&call_fusage, r12);
+  /* Say the call uses r0, even though it doesn't, to stop regrename
+     from twiddling with the insns saving lr, trashing args for cfun.
+     The insns restoring lr are similarly protected by making
+     split_stack_return use r0.  */
+  use_reg (&call_fusage, r0);
   add_function_usage_to (insn, call_fusage);
   emit_insn (gen_frame_load (r0, r1, info->lr_save_offset));
   insn = emit_move_insn (lr, r0);
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index a6f219c..87e7879 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -12587,8 +12587,10 @@
    (set_attr "indexed" "no")])
 
 ;; A return instruction which the middle-end doesn't see.
+;; Use r0 to stop regrename twiddling with lr restore insns emitted
+;; after the call to __morestack.
 (define_insn "split_stack_return"
-  [(unspec_volatile [(const_int 0)] UNSPECV_SPLIT_STACK_RETURN)]
+  [(unspec_volatile [(use (reg:SI 0))] UNSPECV_SPLIT_STACK_RETURN)]
   ""
   "blr"
   [(set_attr "type" "jmpreg")])

-- 
Alan Modra
Australia Development Lab, IBM

Reply via email to