get_frame_size () returns used stack slots during compilation, which
may be optimized out later.  Since ix86_find_max_used_stack_alignment
checks if stack frame is required, it can set a bit in machine_function
to let ix86_compute_frame_layout know that stack frame isn't required.

Tested on i686 and x86-64 with

--with-arch=native --with-cpu=native

on AVX512 machine.  Tested on i686 and x86-64 without

--with-arch=native --with-cpu=native

on x86-64 machine.  OK for trunk?

Thanks.

H.J.
---
gcc/

        PR target/88496
        * config/i386/i386.c (ix86_compute_frame_layout): Set frame size
        to 0 if the function doesn't need a stack frame.
        (ix86_find_max_used_stack_alignment): Set no_stack_frame to 1 if
        stack frame isn't required.
        * config/i386/i386.h (machine_function): Add no_stack_frame.

gcc/testsuite/

        PR target/88496
        * gcc.target/i386/pr88496.c: New test.
---
 gcc/config/i386/i386.c                  | 10 +++++++++-
 gcc/config/i386/i386.h                  |  3 +++
 gcc/testsuite/gcc.target/i386/pr88496.c | 17 +++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88496.c

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index b6dea0c061d..3ef9c967bd6 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -11164,9 +11164,14 @@ ix86_compute_frame_layout (void)
   unsigned HOST_WIDE_INT stack_alignment_needed;
   HOST_WIDE_INT offset;
   unsigned HOST_WIDE_INT preferred_alignment;
-  HOST_WIDE_INT size = get_frame_size ();
+  HOST_WIDE_INT size;
   HOST_WIDE_INT to_allocate;
 
+  if (cfun->machine->no_stack_frame)
+    size = HOST_WIDE_INT_C (0);
+  else
+    size = get_frame_size ();
+
   /* m->call_ms2sysv is initially enabled in ix86_expand_call for all 64-bit
    * ms_abi functions that call a sysv function.  We now need to prune away
    * cases where it should be disabled.  */
@@ -12830,6 +12835,9 @@ ix86_find_max_used_stack_alignment (unsigned int 
&stack_alignment,
          }
     }
 
+  if (!require_stack_frame)
+    cfun->machine->no_stack_frame = 1;
+
   return require_stack_frame;
 }
 
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 64fc5d4058a..4ee86973977 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2754,6 +2754,9 @@ struct GTY(()) machine_function {
   /* If true, ENDBR is queued at function entrance.  */
   BOOL_BITFIELD endbr_queued_at_entrance : 1;
 
+  /* Nonzero if the function doesn't need a stack frame.  */
+  BOOL_BITFIELD no_stack_frame : 1;
+
   /* The largest alignment, in bytes, of stack slot actually used.  */
   unsigned int max_used_stack_alignment;
 
diff --git a/gcc/testsuite/gcc.target/i386/pr88496.c 
b/gcc/testsuite/gcc.target/i386/pr88496.c
new file mode 100644
index 00000000000..c07ab594414
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88496.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f" } */
+
+struct B
+{
+  char a[12];
+  int b;
+};
+
+struct B
+f2 (void)
+{
+  struct B x = {};
+  return x;
+}
+
+/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t 
\]*%\[re\]?sp" } } */
-- 
2.19.2

Reply via email to