This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[4.5] PATCH: PR middle-end/39315: Unaligned move used on aligned stack variable
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 28 Feb 2009 10:34:20 -0800
- Subject: [4.5] PATCH: PR middle-end/39315: Unaligned move used on aligned stack variable
expand_one_stack_var_at limits alignment of stack variable to
STACK_BOUNDARY although we can align stack variable with alignment
up to MAX_SUPPORTED_STACK_ALIGNMENT. Tested on Linux/ia32,
Linux/ia64 and Linux/x86-64. OK for 4.5?
Thanks.
H.J.
-----
gcc/
2009-02-27 H.J. Lu <hongjiu.lu@intel.com>
PR middle-end/39315
* cfgexpand.c (expand_one_stack_var_at): Change alignment
limit to MAX_SUPPORTED_STACK_ALIGNMENT.
gcc/testsuite/
2009-02-27 H.J. Lu <hongjiu.lu@intel.com>
PR middle-end/39315
* gcc.target/i386/pr39315-1.c: New.
* gcc.target/i386/pr39315-2.c: Likewise.
* gcc.target/i386/pr39315-3.c: Likewise.
* gcc.target/i386/pr39315-4.c: Likewise.
* gcc.target/i386/pr39315-check.c: Likewise.
--- gcc/cfgexpand.c.pr39315 2009-02-21 08:15:48.000000000 -0800
+++ gcc/cfgexpand.c 2009-02-27 18:00:35.000000000 -0800
@@ -867,7 +867,8 @@ dump_stack_var_partition (void)
static void
expand_one_stack_var_at (tree decl, HOST_WIDE_INT offset)
{
- HOST_WIDE_INT align;
+ /* Alignment is unsigned. */
+ unsigned HOST_WIDE_INT align;
rtx x;
/* If this fails, we've overflowed the stack frame. Error nicely? */
@@ -880,8 +881,10 @@ expand_one_stack_var_at (tree decl, HOST
offset -= frame_phase;
align = offset & -offset;
align *= BITS_PER_UNIT;
- if (align > STACK_BOUNDARY || align == 0)
+ if (align == 0)
align = STACK_BOUNDARY;
+ else if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
+ align = MAX_SUPPORTED_STACK_ALIGNMENT;
DECL_ALIGN (decl) = align;
DECL_USER_ALIGN (decl) = 0;
--- gcc/testsuite/gcc.target/i386/pr39315-1.c.pr39315 2009-02-27 13:06:59.000000000 -0800
+++ gcc/testsuite/gcc.target/i386/pr39315-1.c 2009-02-27 13:06:59.000000000 -0800
@@ -0,0 +1,18 @@
+/* PR middle-end/39315 */
+/* { dg-do compile } */
+/* { dg-options "-O -msse2 -mtune=generic" } */
+/* { dg-final { scan-assembler-not "movups" } } */
+/* { dg-final { scan-assembler-not "movlps" } } */
+/* { dg-final { scan-assembler-not "movhps" } } */
+/* { dg-final { scan-assembler "movaps" } } */
+
+typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+extern void bar (__m128 *);
+
+void
+foo (__m128 *x)
+{
+ __m128 b = *x;
+ bar (&b);
+}
--- gcc/testsuite/gcc.target/i386/pr39315-2.c.pr39315 2009-02-27 13:06:59.000000000 -0800
+++ gcc/testsuite/gcc.target/i386/pr39315-2.c 2009-02-27 13:06:59.000000000 -0800
@@ -0,0 +1,15 @@
+/* PR middle-end/39315 */
+/* { dg-do run } */
+/* { dg-options "-O -msse2 -mtune=generic" } */
+/* { dg-additional-sources pr39315-check.c } */
+
+typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+extern void bar (__m128 *, int);
+
+void
+foo (__m128 *x)
+{
+ __m128 b = *x;
+ bar (&b, __alignof__ (x));
+}
--- gcc/testsuite/gcc.target/i386/pr39315-3.c.pr39315 2009-02-27 13:06:59.000000000 -0800
+++ gcc/testsuite/gcc.target/i386/pr39315-3.c 2009-02-27 13:06:59.000000000 -0800
@@ -0,0 +1,19 @@
+/* PR middle-end/39315 */
+/* { dg-do compile } */
+/* { dg-options "-O -msse2 -mtune=generic" } */
+/* { dg-final { scan-assembler-not "movups" } } */
+/* { dg-final { scan-assembler-not "movlps" } } */
+/* { dg-final { scan-assembler-not "movhps" } } */
+/* { dg-final { scan-assembler "and\[lq\]?\[\\t \]*\\$-128,\[\\t \]*%\[re\]?sp" } } */
+/* { dg-final { scan-assembler "movaps" } } */
+
+typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+extern void bar (__m128 *);
+
+void
+foo (__m128 *x)
+{
+ __m128 b __attribute__ ((aligned(128))) = *x;
+ bar (&b);
+}
--- gcc/testsuite/gcc.target/i386/pr39315-4.c.pr39315 2009-02-27 13:06:59.000000000 -0800
+++ gcc/testsuite/gcc.target/i386/pr39315-4.c 2009-02-27 13:06:59.000000000 -0800
@@ -0,0 +1,15 @@
+/* PR middle-end/39315 */
+/* { dg-do run } */
+/* { dg-options "-O -msse2 -mtune=generic" } */
+/* { dg-additional-sources pr39315-check.c } */
+
+typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+extern void bar (__m128 *, int);
+
+void
+foo (__m128 *x)
+{
+ __m128 b __attribute__ ((aligned(128))) = *x;
+ bar (&b, __alignof__ (x));
+}
--- gcc/testsuite/gcc.target/i386/pr39315-check.c.pr39315 2009-02-27 13:06:59.000000000 -0800
+++ gcc/testsuite/gcc.target/i386/pr39315-check.c 2009-02-27 13:06:59.000000000 -0800
@@ -0,0 +1,22 @@
+typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+extern void foo (__m128 *);
+extern void abort (void);
+
+__m128 y = { 0.0, 1.0, 2.0, 3.0 };
+
+void
+bar (__m128 *x, int align)
+{
+ if ((((__PTRDIFF_TYPE__) x) & (align - 1)) != 0)
+ abort ();
+ if (__builtin_memcmp (x, &y, sizeof (y)) != 0)
+ abort ();
+}
+
+int
+main ()
+{
+ foo (&y);
+ return 0;
+}