Bug 39315 - Unaligned move used on aligned stack variable
Summary: Unaligned move used on aligned stack variable
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords:
: 43124 (view as bug list)
Depends on: 39323
Blocks:
  Show dependency treegraph
 
Reported: 2009-02-26 16:56 UTC by H.J. Lu
Modified: 2010-02-20 14:08 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0
Known to fail:
Last reconfirmed:


Attachments
A patch (286 bytes, patch)
2009-02-26 17:13 UTC, H.J. Lu
Details | Diff
A new patch (1.07 KB, patch)
2009-02-28 00:03 UTC, H.J. Lu
Details | Diff
An updated patch (1.08 KB, patch)
2009-02-28 02:03 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2009-02-26 16:56:51 UTC
[hjl@gnu-6 pr]$ cat x.c
typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
extern void bar (__m128 *);
void
foo (__m128 *x)
{
  __m128 b = *x;
  bar (&b);
}
[hjl@gnu-6 pr]$ make x.s
/export/build/gnu/gcc-work/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-work/build-x86_64-linux/gcc/ -S -o x.s -O2 -fno-asynchronous-unwind-tables x.c
[hjl@gnu-6 pr]$ cat x.s
	.file	"x.c"
	.text
	.p2align 4,,15
.globl foo
	.type	foo, @function
foo:
	subq	$24, %rsp
	movaps	(%rdi), %xmm0
	movq	%rsp, %rdi
	movlps	%xmm0, (%rsp)
	movhps	%xmm0, 8(%rsp)
	call	bar
	addq	$24, %rsp
	ret

expand_one_stack_var_at has

  /* Set alignment we actually gave this decl.  */
  offset -= frame_phase;
  align = offset & -offset;
  align *= BITS_PER_UNIT;
  if (align > STACK_BOUNDARY || align == 0)
    align = STACK_BOUNDARY;
  DECL_ALIGN (decl) = align;
  DECL_USER_ALIGN (decl) = 0;

  set_mem_attributes (x, decl, true);

That is we always set alignment attribute of a stack variable
to <= STACK_BOUNDARY even if we can align it properly.  One
consequence is unaligned move is used on aligned memory.
Comment 1 H.J. Lu 2009-02-26 17:01:12 UTC
Gcc 4.3 generates aligned move since it doesn't check the
alignment attribute.
Comment 2 H.J. Lu 2009-02-26 17:13:23 UTC
Created attachment 17368 [details]
A patch

Does this patch make sense?
Comment 3 Joey Ye 2009-02-27 02:53:33 UTC
(In reply to comment #2)
> Created an attachment (id=17368) [edit]
> A patch
> Does this patch make sense?
It works fine.
Comment 4 H.J. Lu 2009-02-27 03:37:28 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Created an attachment (id=17368) [edit]
> > A patch
> > Does this patch make sense?
> It works fine.
> 

It failed for me in libgcc during bootstrap on Linux/ia32.
Comment 5 H.J. Lu 2009-02-28 00:03:44 UTC
Created attachment 17373 [details]
A new patch

This patch may work better.
Comment 6 H.J. Lu 2009-02-28 02:03:55 UTC
Created attachment 17375 [details]
An updated patch

When align == 0, we should align variable to STACK_BOUNDARY.
Comment 7 H.J. Lu 2009-02-28 18:41:33 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2009-02/msg01267.html
Comment 8 hjl@gcc.gnu.org 2009-02-28 18:55:20 UTC
Subject: Bug 39315

Author: hjl
Date: Sat Feb 28 18:55:06 2009
New Revision: 144492

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144492
Log:
gcc/

2009-02-28  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-28  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.

Added:
    branches/stack/gcc/testsuite/gcc.target/i386/pr39315-1.c
    branches/stack/gcc/testsuite/gcc.target/i386/pr39315-2.c
    branches/stack/gcc/testsuite/gcc.target/i386/pr39315-3.c
    branches/stack/gcc/testsuite/gcc.target/i386/pr39315-4.c
    branches/stack/gcc/testsuite/gcc.target/i386/pr39315-check.c
Modified:
    branches/stack/gcc/ChangeLog.stackalign
    branches/stack/gcc/cfgexpand.c
    branches/stack/gcc/testsuite/ChangeLog.stackalign

Comment 9 hjl@gcc.gnu.org 2009-03-27 22:37:53 UTC
Subject: Bug 39315

Author: hjl
Date: Fri Mar 27 22:37:39 2009
New Revision: 145138

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145138
Log:
gcc/

2009-03-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-03-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.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr39315-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr39315-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr39315-3.c
    trunk/gcc/testsuite/gcc.target/i386/pr39315-4.c
    trunk/gcc/testsuite/gcc.target/i386/pr39315-check.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cfgexpand.c
    trunk/gcc/testsuite/ChangeLog

Comment 10 Andrew Pinski 2009-04-16 18:33:38 UTC
Stop setting the target milestone unless it is a regression.
Comment 11 H.J. Lu 2009-07-23 13:43:06 UTC
*** Bug 40838 has been marked as a duplicate of this bug. ***
Comment 12 hjl@gcc.gnu.org 2009-10-31 16:58:30 UTC
Subject: Bug 39315

Author: hjl
Date: Sat Oct 31 16:58:17 2009
New Revision: 153780

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153780
Log:
gcc/

2009-10-31  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-03-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-10-31  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-03-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.

Added:
    branches/ix86/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr39315-1.c
    branches/ix86/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr39315-2.c
    branches/ix86/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr39315-3.c
    branches/ix86/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr39315-4.c
    branches/ix86/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr39315-check.c
Modified:
    branches/ix86/gcc-4_4-branch/gcc/ChangeLog.ix86
    branches/ix86/gcc-4_4-branch/gcc/cfgexpand.c
    branches/ix86/gcc-4_4-branch/gcc/testsuite/ChangeLog.ix86

Comment 13 H.J. Lu 2010-02-20 01:05:56 UTC
*** Bug 43124 has been marked as a duplicate of this bug. ***
Comment 14 Richard Biener 2010-02-20 14:08:49 UTC
On trunk I get:

foo:
        subl    $44, %esp
        movl    48(%esp), %eax
        movaps  (%eax), %xmm0
        leal    16(%esp), %eax
        movl    %eax, (%esp)
        movaps  %xmm0, 16(%esp)
        call    bar
        addl    $44, %esp
        ret

thus, fixed.