i386: Update preferred stack boundary for leaf functions
authorH.J. Lu <hongjiu.lu@intel.com>
Sun, 17 Sep 2017 21:11:04 +0000 (21:11 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Sun, 17 Sep 2017 21:11:04 +0000 (14:11 -0700)
preferred_stack_boundary may not be the minimum stack alignment.  For
leaf functions without TLS access, max_used_stack_slot_alignment may be
smaller.  We should update preferred_stack_boundary for leaf functions.

gcc/

PR target/82166
* config/i386/i386.c (ix86_finalize_stack_frame_flags): Properly
compute the minimum stack alignment.  Also update preferred stack
boundary for leaf functions.

gcc/testsuite/

PR target/82166
* gcc.target/i386/pr82166.c: New test.

From-SVN: r252895

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr82166.c [new file with mode: 0644]

index e213db6e2a07b52a71aab1d1cc054a267bfd0db5..b09c7ce581292c610c6ed18b9c83a66a2c106ad1 100644 (file)
@@ -1,3 +1,10 @@
+2017-09-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/82166
+       * config/i386/i386.c (ix86_finalize_stack_frame_flags): Properly
+       compute the minimum stack alignment.  Also update preferred stack
+       boundary for leaf functions.
+
 2017-09-16  Richard Sandiford  <richard.sandiford@linaro.org>
 
        PR tree-optimization/82228
index fa79762a9229999d1b9b3dcc418cfa9923405ae2..4f0414ffa9d6e6521e55ed00f2da3316d2e9d693 100644 (file)
@@ -14257,11 +14257,12 @@ ix86_finalize_stack_frame_flags (void)
   unsigned int incoming_stack_boundary
     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
+  unsigned int stack_alignment
+    = (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor
+       ? crtl->max_used_stack_slot_alignment
+       : crtl->stack_alignment_needed);
   unsigned int stack_realign
-    = (incoming_stack_boundary
-       < (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor
-         ? crtl->max_used_stack_slot_alignment
-         : crtl->stack_alignment_needed));
+    = (incoming_stack_boundary < stack_alignment);
   bool recompute_frame_layout_p = false;
 
   if (crtl->stack_realign_finalized)
@@ -14306,7 +14307,9 @@ ix86_finalize_stack_frame_flags (void)
                           HARD_FRAME_POINTER_REGNUM);
 
       /* The preferred stack alignment is the minimum stack alignment.  */
-      unsigned int stack_alignment = crtl->preferred_stack_boundary;
+      if (stack_alignment > crtl->preferred_stack_boundary)
+       stack_alignment = crtl->preferred_stack_boundary;
+
       bool require_stack_frame = false;
 
       FOR_EACH_BB_FN (bb, cfun)
@@ -14349,6 +14352,10 @@ ix86_finalize_stack_frame_flags (void)
                = incoming_stack_boundary;
              crtl->stack_alignment_needed
                = incoming_stack_boundary;
+             /* Also update preferred_stack_boundary for leaf
+                functions.  */
+             crtl->preferred_stack_boundary
+               = incoming_stack_boundary;
            }
        }
       else
index d40f08e13cf091985df7d3f4328ac32c410106ce..47de348eb516ca95fe85a08e6b6065f433fdad4d 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/82166
+       * gcc.target/i386/pr82166.c: New test.
+
 2017-09-17  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/82173
diff --git a/gcc/testsuite/gcc.target/i386/pr82166.c b/gcc/testsuite/gcc.target/i386/pr82166.c
new file mode 100644 (file)
index 0000000..8bc63e1
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+
+void foo (void);
+int a, b, c;
+int
+main (void)
+{
+  int j;
+  for (; c;)
+    a = b;
+  for (; j;)
+    foo ();
+}