]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
x86: Replace ix86_red_zone_size with ix86_red_zone_used
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 11 Jun 2021 14:31:29 +0000 (07:31 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 13 Jun 2021 12:15:24 +0000 (05:15 -0700)
Add red_zone_used to machine_function to track if red zone is used.
When expanding function prologue, set red_zone_used to true if red
zone is used.

gcc/

PR target/101023
* config/i386/i386.c (ix86_expand_prologue): Set red_zone_used
to true if red zone is used.
(ix86_output_indirect_jmp): Replace ix86_red_zone_size with
ix86_red_zone_used.
* config/i386/i386.h (machine_function): Add red_zone_used.
(ix86_red_zone_size): Removed.
(ix86_red_zone_used): New.
* config/i386/i386.md (peephole2 patterns): Replace
ix86_red_zone_size with ix86_red_zone_used.

gcc/testsuite/

PR target/101023
* g++.target/i386/pr101023a.C: New test.
* g++.target/i386/pr101023b.C: Likewise.

gcc/config/i386/i386.c
gcc/config/i386/i386.h
gcc/config/i386/i386.md
gcc/testsuite/g++.target/i386/pr101023a.C [new file with mode: 0644]
gcc/testsuite/g++.target/i386/pr101023b.C [new file with mode: 0644]

index 05b8dc806cd45af991e5a8f3ca30f2a166cbbdd3..a61255857ff112b9bbd5607a42ef9ed5204f0038 100644 (file)
@@ -8401,10 +8401,14 @@ ix86_expand_prologue (void)
                   || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
        {
          ix86_emit_save_regs_using_mov (frame.reg_save_offset);
+         cfun->machine->red_zone_used = true;
          int_registers_saved = true;
        }
     }
 
+  if (frame.red_zone_size != 0)
+    cfun->machine->red_zone_used = true;
+
   if (stack_realign_fp)
     {
       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
@@ -15915,7 +15919,7 @@ ix86_output_indirect_jmp (rtx call_op)
     {
       /* We can't have red-zone since "call" in the indirect thunk
          pushes the return address onto stack, destroying red-zone.  */
-      if (ix86_red_zone_size != 0)
+      if (ix86_red_zone_used)
        gcc_unreachable ();
 
       ix86_output_indirect_branch (call_op, "%0", true);
index 919d0b2418ac2dd53eeb3251f2a7697273370bc3..182b3275991c2dbf638dcee1c2a16b97dddc9b03 100644 (file)
@@ -2663,6 +2663,9 @@ struct GTY(()) machine_function {
      invalid calls.  */
   BOOL_BITFIELD silent_p : 1;
 
+  /* True if red zone is used.  */
+  BOOL_BITFIELD red_zone_used : 1;
+
   /* The largest alignment, in bytes, of stack slot actually used.  */
   unsigned int max_used_stack_alignment;
 
@@ -2693,7 +2696,7 @@ extern GTY(()) tree ms_va_list_type_node;
 #define ix86_current_function_calls_tls_descriptor \
   (ix86_tls_descriptor_calls_expanded_in_cfun && df_regs_ever_live_p (SP_REG))
 #define ix86_static_chain_on_stack (cfun->machine->static_chain_on_stack)
-#define ix86_red_zone_size (cfun->machine->frame.red_zone_size)
+#define ix86_red_zone_used (cfun->machine->red_zone_used)
 
 /* Control behavior of x86_file_start.  */
 #define X86_FILE_START_VERSION_DIRECTIVE false
index 7743c61ec865493dde5736a9d4c2ff426492cb34..6e4abf32e7cb528f9aaa9b13808c083f80f604ef 100644 (file)
              (clobber (mem:BLK (scratch)))])]
   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
-   && ix86_red_zone_size == 0"
+   && !ix86_red_zone_used"
   [(clobber (match_dup 1))
    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
              (clobber (mem:BLK (scratch)))])])
              (clobber (mem:BLK (scratch)))])]
   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
-   && ix86_red_zone_size == 0"
+   && !ix86_red_zone_used"
   [(clobber (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
              (clobber (reg:CC FLAGS_REG))])]
   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
-   && ix86_red_zone_size == 0"
+   && !ix86_red_zone_used"
   [(clobber (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
 
              (clobber (reg:CC FLAGS_REG))])]
   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
-   && ix86_red_zone_size == 0"
+   && !ix86_red_zone_used"
   [(clobber (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
diff --git a/gcc/testsuite/g++.target/i386/pr101023a.C b/gcc/testsuite/g++.target/i386/pr101023a.C
new file mode 100644 (file)
index 0000000..04fb8b0
--- /dev/null
@@ -0,0 +1,63 @@
+// PR target/101023
+// { dg-do run { target { ! ia32 } } }
+// { dg-options "-O2 -mtune=opteron -mstackrealign --param=hot-bb-frequency-fraction=1" }
+
+struct S {
+  __attribute__((noipa)) int m1 ();
+  __attribute__((noipa)) void m2 ();
+};
+struct T {
+  __attribute__((noipa)) virtual S m3 ();
+};
+struct U : T {
+  int u;
+  __attribute__((noipa)) U (int);
+};
+int *a;
+S *b;
+int c;
+
+int
+S::m1 ()
+{
+  return 0;
+}
+
+void
+S::m2 ()
+{
+}
+
+S
+T::m3 ()
+{
+  return S ();
+}
+
+U::U (int) : u (4)
+{
+}
+
+__attribute__((noipa)) int
+foo ()
+{
+  if (a)
+    return 0;
+  U d(c);
+  S *e = b;
+  e->m2 ();
+  return e->m1();
+}
+
+int
+main ()
+{
+  register int r12 __asm ("r12") = 1;
+  register int rax __asm ("rax") = 2;
+  asm volatile ("" : "+r" (r12), "+r" (rax));
+  foo ();
+  asm volatile ("" : "+r" (r12));
+  if (r12 != 1)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/g++.target/i386/pr101023b.C b/gcc/testsuite/g++.target/i386/pr101023b.C
new file mode 100644 (file)
index 0000000..b19791c
--- /dev/null
@@ -0,0 +1,5 @@
+// PR target/101023
+// { dg-do run { target { ! ia32 } } }
+// { dg-options "-O2 -mno-red-zone -mtune=opteron -mstackrealign --param=hot-bb-frequency-fraction=1" }
+
+#include "pr101023a.C"