]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Update stack alignment in ix86_update_stack_boundary
authorH.J. Lu <hongjiu.lu@intel.com>
Tue, 26 Jan 2016 12:51:07 +0000 (12:51 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Tue, 26 Jan 2016 12:51:07 +0000 (04:51 -0800)
Stack alignment adjustment for __tls_get_addr should be done in
ix86_update_stack_boundary, not ix86_compute_frame_layout.  Also
there is no need to over-align stack for __tls_get_addr and function
with __tls_get_addr call isn't a leaf function.

gcc/

PR target/68986
* config/i386/i386.c (ix86_compute_frame_layout): Move stack
alignment adjustment to ...
(ix86_update_stack_boundary): Here.  Don't over-align stack for
__tls_get_addr.
(ix86_finalize_stack_realign_flags): Use stack_alignment_needed
if __tls_get_addr is called.

gcc/testsuite/

PR target/68986
* gcc.target/i386/pr68986-1.c: New test.
* gcc.target/i386/pr68986-2.c: Likewise.
* gcc.target/i386/pr68986-3.c: Likewise.

From-SVN: r232825

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr68986-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr68986-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr68986-3.c [new file with mode: 0644]

index 800b75c12622078ed50ca02b995dc21ecbde9496..28cb00c745124b025e207fdf8606ce6f8d7064f1 100644 (file)
@@ -1,3 +1,13 @@
+2016-01-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/68986
+       * config/i386/i386.c (ix86_compute_frame_layout): Move stack
+       alignment adjustment to ...
+       (ix86_update_stack_boundary): Here.  Don't over-align stack for
+       __tls_get_addr.
+       (ix86_finalize_stack_realign_flags): Use stack_alignment_needed
+       if __tls_get_addr is called.
+
 2016-01-26  Christian Bruel  <christian.bruel@st.com>
 
        * doc/sourcebuild.texi (arm_crypto_pragma_ok): Remove.
index 34b57a4266080bd97926356e8ba159c00c2ec8f5..cfbdf0f1734260fd54b96f6876dbc325c1c2894c 100644 (file)
@@ -11360,18 +11360,6 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
       crtl->preferred_stack_boundary = 128;
       crtl->stack_alignment_needed = 128;
     }
-  /* preferred_stack_boundary is never updated for call
-     expanded from tls descriptor. Update it here. We don't update it in
-     expand stage because according to the comments before
-     ix86_current_function_calls_tls_descriptor, tls calls may be optimized
-     away.  */
-  else if (ix86_current_function_calls_tls_descriptor
-          && crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
-    {
-      crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
-      if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
-       crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
-    }
 
   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
@@ -12043,6 +12031,15 @@ ix86_update_stack_boundary (void)
       && cfun->stdarg
       && crtl->stack_alignment_estimated < 128)
     crtl->stack_alignment_estimated = 128;
+
+  /* __tls_get_addr needs to be called with 16-byte aligned stack.  */
+  if (ix86_tls_descriptor_calls_expanded_in_cfun
+      && crtl->preferred_stack_boundary < 128)
+    {
+      crtl->preferred_stack_boundary = 128;
+      if (crtl->stack_alignment_needed < 128)
+       crtl->stack_alignment_needed = 128;
+    }
 }
 
 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
@@ -12505,10 +12502,11 @@ ix86_finalize_stack_realign_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_realign = (incoming_stack_boundary
-                               < (crtl->is_leaf
-                                  ? 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));
 
   if (crtl->stack_realign_finalized)
     {
index 040a2f841224a2d6bd31d16f176d32b64d921c60..ebee72c3e8651e28e57867490756cf841a8e8ecd 100644 (file)
@@ -1,3 +1,10 @@
+2016-01-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/68986
+       * gcc.target/i386/pr68986-1.c: New test.
+       * gcc.target/i386/pr68986-2.c: Likewise.
+       * gcc.target/i386/pr68986-3.c: Likewise.
+
 2016-01-26  Christian Bruel  <christian.bruel@st.com>
 
        * lib/target-supports.exp
diff --git a/gcc/testsuite/gcc.target/i386/pr68986-1.c b/gcc/testsuite/gcc.target/i386/pr68986-1.c
new file mode 100644 (file)
index 0000000..998f34f
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-fPIC -mno-accumulate-outgoing-args -mpreferred-stack-boundary=5 -mincoming-stack-boundary=4" } */
+
+extern __thread int msgdata;
+int
+foo ()
+{
+  return msgdata;
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr68986-2.c b/gcc/testsuite/gcc.target/i386/pr68986-2.c
new file mode 100644 (file)
index 0000000..23f9a52
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-fPIC -mno-accumulate-outgoing-args -mpreferred-stack-boundary=2 -m32" } */
+
+extern __thread int msgdata;
+int
+foo ()
+{
+  return msgdata;
+}
+
+/* { dg-final { scan-assembler "andl\[\\t \]*\\$-16,\[\\t \]*%esp" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr68986-3.c b/gcc/testsuite/gcc.target/i386/pr68986-3.c
new file mode 100644 (file)
index 0000000..5744cf2
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-fPIC -mno-sse -mpreferred-stack-boundary=3 -mincoming-stack-boundary=3" } */
+
+extern __thread int msgdata;
+int
+foo ()
+{
+  return msgdata;
+}
+
+/* { dg-final { scan-assembler "and\[lq\]\[\\t \]*\\$-16,\[\\t \]*%\[re\]?sp" } } */