https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120870

--- Comment #54 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 64441
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64441&action=edit
Untested patch

Untested patch that fixes the stack issue in the testcase.

Please note that the patched compiler still emits:

caller:
        pushq   %rbx
...
        popq    %rbx
        jmp     tail

This can be avoided with:

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index e73c2d7f7d0..fcbe3d1841f 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -9404,7 +9410,10 @@ ix86_expand_prologue (void)
               "around by avoiding functions with aggregate return.");

       /* Only need to push parameter pointer reg if it is caller saved.  */
-      if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
+      if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg))
+         && (cfun->machine->call_saved_registers
+             != TYPE_NO_CALLEE_SAVED_REGISTERS)
+         && cfun->machine->call_saved_registers != TYPE_PRESERVE_NONE)
        {
          /* Push arg pointer reg */
          insn = emit_insn (gen_push (crtl->drap_reg));
@@ -10647,7 +10656,10 @@ ix86_expand_epilogue (int style)
                                   param_ptr_offset));
       RTX_FRAME_RELATED_P (insn) = 1;

-      if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
+      if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg))
+         && (cfun->machine->call_saved_registers
+             != TYPE_NO_CALLEE_SAVED_REGISTERS)
+         && cfun->machine->call_saved_registers != TYPE_PRESERVE_NONE)
        ix86_emit_restore_reg_using_pop (crtl->drap_reg);
     }

but unnecessary push/pop should go away once call_used_or_fixed_reg_p is
updated for RBX.

HJ, can you please take the patch from here?

Reply via email to