public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: PATCH: PR target/40838: gcc shouldn't assume that the stack is  aligned
@ 2009-08-07  0:54 Mikulas Patocka
  2009-08-07  7:13 ` Jakub Jelinek
  0 siblings, 1 reply; 59+ messages in thread
From: Mikulas Patocka @ 2009-08-07  0:54 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, ubizjak

> > In 32bit, the incoming stack may not be 16 byte aligned.  This patch
> > assumes the incoming stack is 4 byte aligned and realigns stack if any
> > SSE variable is put on stack. Any comments?
>
> IMHO this is wrong, I could live with a non-default option for those who 
> don't care about performance and think a SCO document from 1996 has any 
> relevance to Linux these days.  In reality a Linux ABI for years assumes 
> 16 byte stack alignment for 32-bit code.
> 
>        Jakub

Tell me which Linux distribution did you run with 16-byte stack alignment 
checking (as proposed in bug 40838) and what was the result?

For me, the result was that 75% of binaries in /bin in Debian Lenny do not 
align the stack on 16-byte boundary.

Mikulas

^ permalink raw reply	[flat|nested] 59+ messages in thread
* PATCH: PR target/40838: gcc shouldn't assume that the stack is  aligned
@ 2009-08-06 21:42 H.J. Lu
  2009-08-06 22:26 ` Jakub Jelinek
  2009-10-15 15:58 ` H.J. Lu
  0 siblings, 2 replies; 59+ messages in thread
From: H.J. Lu @ 2009-08-06 21:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: ubizjak

Hi,

In 32bit, the incoming stack may not be 16 byte aligned.  This patch
assumes the incoming stack is 4 byte aligned and realigns stack if any
SSE variable is put on stack. Any comments?

Thanks.


H.J.
---
gcc/

2009-08-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/40838
	* config/i386/i386.c (ix86_update_stack_boundary): Use
	STACK_BOUNDARY if use_stack_boundary_for_incoming_stack_boundary
	is set.
	(VALID_SSE_VECTOR_MODE): New.
	(ix86_minimum_alignment): In 32bit, set
	use_stack_boundary_for_incoming_stack_boundary if any SSE
	variables are put on stack.

	* config/i386/i386.h (machine_function): Add
	use_stack_boundary_for_incoming_stack_boundary.

gcc/testsuite/

2009-08-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/40838
	* gcc.target/i386/incoming-6.c: New.
	* gcc.target/i386/incoming-7.c: Likewise.
	* gcc.target/i386/incoming-8.c: Likewise.
	* gcc.target/i386/incoming-9.c: Likewise.

Index: gcc/testsuite/gcc.target/i386/incoming-7.c
===================================================================
--- gcc/testsuite/gcc.target/i386/incoming-7.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/incoming-7.c	(revision 0)
@@ -0,0 +1,16 @@
+/* PR target/40838 */
+/* { dg-do compile { target { { ! *-*-darwin* } && ilp32 } } } */
+/* { dg-options "-w -O2 -msse2 -mpreferred-stack-boundary=4" } */
+
+typedef int v4si __attribute__ ((vector_size (16)));
+
+extern v4si y(v4si, v4si, v4si, v4si, v4si);
+
+extern v4si s1, s2;
+
+v4si x(void)
+{
+  return y(s1, s2, s1, s2, s2);
+}
+
+/* { dg-final { scan-assembler "andl\[\\t \]*\\$-16,\[\\t \]*%esp" } } */
Index: gcc/testsuite/gcc.target/i386/incoming-9.c
===================================================================
--- gcc/testsuite/gcc.target/i386/incoming-9.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/incoming-9.c	(revision 0)
@@ -0,0 +1,18 @@
+/* PR target/40838 */
+/* { dg-do compile { target { { ! *-*-darwin* } && ilp32 } } } */
+/* { dg-options "-w -O3 -mno-sse -mpreferred-stack-boundary=4" } */
+
+float
+foo (float f)
+{
+  float array[128];
+  float x;
+  int i;
+  for (i = 0; i < sizeof(array) / sizeof(*array); i++)
+    array[i] = f;
+  for (i = 0; i < sizeof(array) / sizeof(*array); i++)
+    x += array[i];
+  return x;
+}
+
+/* { dg-final { scan-assembler-not "andl\[\\t \]*\\$-16,\[\\t \]*%esp" } } */
Index: gcc/testsuite/gcc.target/i386/incoming-6.c
===================================================================
--- gcc/testsuite/gcc.target/i386/incoming-6.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/incoming-6.c	(revision 0)
@@ -0,0 +1,17 @@
+/* PR target/40838 */
+/* { dg-do compile { target { { ! *-*-darwin* } && ilp32 } } } */
+/* { dg-options "-w -O2 -msse2 -mpreferred-stack-boundary=4" } */
+
+typedef int v4si __attribute__ ((vector_size (16)));
+
+extern v4si y(v4si *s3);
+
+extern v4si s1, s2;
+
+v4si x(void)
+{
+  v4si s3 = s1 + s2;
+  return y(&s3);
+}
+
+/* { dg-final { scan-assembler "andl\[\\t \]*\\$-16,\[\\t \]*%esp" } } */
Index: gcc/testsuite/gcc.target/i386/incoming-8.c
===================================================================
--- gcc/testsuite/gcc.target/i386/incoming-8.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/incoming-8.c	(revision 0)
@@ -0,0 +1,18 @@
+/* PR target/40838 */
+/* { dg-do compile { target { { ! *-*-darwin* } && ilp32 } } } */
+/* { dg-options "-w -O3 -msse2 -mpreferred-stack-boundary=4" } */
+
+float
+foo (float f)
+{
+  float array[128];
+  float x;
+  int i;
+  for (i = 0; i < sizeof(array) / sizeof(*array); i++)
+    array[i] = f;
+  for (i = 0; i < sizeof(array) / sizeof(*array); i++)
+    x += array[i];
+  return x;
+}
+
+/* { dg-final { scan-assembler "andl\[\\t \]*\\$-16,\[\\t \]*%esp" } } */
Index: gcc/config/i386/i386.h
===================================================================
--- gcc/config/i386/i386.h	(revision 150532)
+++ gcc/config/i386/i386.h	(working copy)
@@ -2389,6 +2389,8 @@ struct GTY(()) machine_function {
   /* This value is used for amd64 targets and specifies the current abi
      to be used. MS_ABI means ms abi. Otherwise SYSV_ABI means sysv abi.  */
   enum calling_abi call_abi;
+  /* Use STACK_BOUNDARY for incoming stack boundary.  */
+  int use_stack_boundary_for_incoming_stack_boundary;
   struct machine_cfa_state cfa;
 };
 #endif
Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 150532)
+++ gcc/config/i386/i386.c	(working copy)
@@ -8230,11 +8230,19 @@ find_drap_reg (void)
 static void
 ix86_update_stack_boundary (void)
 {
+  /* Should we use STACK_BOUNDARY for incoming stack boundary?  */
+  unsigned int incoming_stack_boundary;
+
+  if (cfun->machine->use_stack_boundary_for_incoming_stack_boundary)
+    incoming_stack_boundary = STACK_BOUNDARY;
+  else
+    incoming_stack_boundary = ix86_default_incoming_stack_boundary;
+
   /* Prefer the one specified at command line. */
   ix86_incoming_stack_boundary 
     = (ix86_user_incoming_stack_boundary
        ? ix86_user_incoming_stack_boundary
-       : ix86_default_incoming_stack_boundary);
+       : incoming_stack_boundary);
 
   /* Incoming stack alignment can be changed on individual functions
      via force_align_arg_pointer attribute.  We use the smallest
@@ -20069,6 +20077,10 @@ ix86_local_alignment (tree exp, enum mac
   return align;
 }
 
+#define VALID_SSE_VECTOR_MODE(MODE) \
+  ((MODE) == V4SFmode || (MODE) == V4SImode || (MODE) == V2DFmode \
+   || (MODE) == V16QImode || (MODE) == V8HImode || (MODE) == V2DImode)
+
 /* Compute the minimum required alignment for dynamic stack realignment
    purposes for a local variable, parameter or a stack slot.  EXP is
    the data type or decl itself, MODE is its mode and ALIGN is the
@@ -20080,7 +20092,7 @@ ix86_minimum_alignment (tree exp, enum m
 {
   tree type, decl;
 
-  if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
+  if (TARGET_64BIT)
     return align;
 
   if (exp && DECL_P (exp))
@@ -20094,6 +20106,15 @@ ix86_minimum_alignment (tree exp, enum m
       decl = NULL;
     }
 
+  /* In 32bit, use STACK_BOUNDARY for incoming stack boundary if any
+     SSE variables are put on stack.  */
+  if (VALID_SSE_VECTOR_MODE (mode)
+      || (type && VALID_SSE_VECTOR_MODE (TYPE_MODE (type))))
+     cfun->machine->use_stack_boundary_for_incoming_stack_boundary = 1;
+
+  if (align != 64 || ix86_preferred_stack_boundary >= 64)
+    return align;
+
   /* Don't do dynamic stack realignment for long long objects with
      -mpreferred-stack-boundary=2.  */
   if ((mode == DImode || (type && TYPE_MODE (type) == DImode))

^ permalink raw reply	[flat|nested] 59+ messages in thread

end of thread, other threads:[~2009-10-30  9:51 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-07  0:54 PATCH: PR target/40838: gcc shouldn't assume that the stack is aligned Mikulas Patocka
2009-08-07  7:13 ` Jakub Jelinek
2009-08-07 12:53   ` H.J. Lu
2009-08-07 22:30     ` H.J. Lu
2009-08-08 17:35       ` Mikulas Patocka
2009-08-16 21:25         ` H.J. Lu
2009-08-24 17:39       ` H.J. Lu
2009-09-12 23:32         ` Mikulas Patocka
2009-09-12 23:42           ` Mikulas Patocka
2009-09-13  1:55           ` H.J. Lu
2009-09-13 14:10             ` Mikulas Patocka
2009-08-07 21:08   ` Mikulas Patocka
2009-08-07 21:25     ` Richard Guenther
  -- strict thread matches above, loose matches on Subject: below --
2009-08-06 21:42 H.J. Lu
2009-08-06 22:26 ` Jakub Jelinek
2009-08-06 22:52   ` H.J. Lu
2009-10-15 15:58 ` H.J. Lu
2009-10-15 18:45   ` Uros Bizjak
2009-10-15 19:22     ` H.J. Lu
2009-10-15 19:32       ` Uros Bizjak
2009-10-15 19:43         ` H.J. Lu
2009-10-15 19:48           ` Jakub Jelinek
2009-10-15 20:11             ` H.J. Lu
2009-10-15 19:53           ` Uros Bizjak
2009-10-15 21:01             ` H.J. Lu
2009-10-15 21:41               ` Uros Bizjak
2009-10-16 20:27     ` H.J. Lu
2009-10-17  1:03       ` Ian Lance Taylor
2009-10-17 18:22         ` H.J. Lu
2009-10-17 19:02           ` Richard Guenther
2009-10-17 19:21             ` H.J. Lu
2009-10-17 19:29               ` Richard Guenther
2009-10-17 19:35                 ` H.J. Lu
2009-10-17 19:46                   ` Richard Guenther
2009-10-17 20:01                     ` H.J. Lu
2009-10-17 20:59                       ` Richard Guenther
2009-10-18 19:21                         ` Michael Matz
2009-10-18 19:45                           ` Richard Guenther
2009-10-19 16:36                             ` H.J. Lu
2009-10-20  1:12                               ` Michael Matz
2009-10-20 19:10                                 ` H.J. Lu
2009-10-19 16:38                           ` H.J. Lu
2009-10-19 17:08                             ` Ian Lance Taylor
2009-10-19 17:26                               ` H.J. Lu
2009-10-19 17:33                                 ` Ian Lance Taylor
2009-10-19 17:46                                   ` H.J. Lu
2009-10-19 17:55                                     ` Ian Lance Taylor
2009-10-19 19:16                                       ` H.J. Lu
2009-10-19 21:15                                         ` Ian Lance Taylor
2009-10-20 19:00                                           ` H.J. Lu
2009-10-20  1:23                                         ` Michael Matz
2009-10-20 19:12                                           ` H.J. Lu
2009-10-20  1:53                             ` Michael Matz
2009-10-20 21:15                               ` H.J. Lu
2009-10-21  1:10                                 ` H.J. Lu
2009-10-21  9:54                                   ` Michael Matz
2009-10-21 16:56                                     ` H.J. Lu
2009-10-30 10:08                                       ` Richard Guenther
2009-10-17  7:09       ` Uros Bizjak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).