If a parameter is passed on stack, caller is responsible to align
the stack frame to at least the alignment of the parameter. But gcc
will align the stack even when it has been aligned already by caller.

bash-3.2$ cat 1.i
typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
int
__attribute__ ((noinline))
foo(__m128 x, int size, ...)
{
  volatile char * ptr=__builtin_alloca(size);
  volatile int __attribute((aligned(16))) xxx;

  xxx = 2;
  ptr [1]= 30;
  return xxx;
}

int
bar ()
{
  __m128 x = { 1.0 };
  foo (x, 30);
  return 0;
}
bash-3.2$  /export/build/gnu/gcc-avx/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc-stack/build-x86_64-linux/gcc/ -msse2 -m32
-mpreferred-stack-boundary=2 -S -o 1.s 1.i
bash-3.2$ cat 1.s
        .file   "1.i"
        .text
.globl foo
        .type   foo, @function
foo:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $36, %esp
        movl    16(%ecx), %eax
        addl    $15, %eax
        addl    $3, %eax
        shrl    $2, %eax
        sall    $2, %eax
        subl    %eax, %esp
        movl    %esp, -28(%ebp)
        movl    -28(%ebp), %eax
        addl    $15, %eax
        shrl    $4, %eax
        sall    $4, %eax
        movl    %eax, -28(%ebp)
        movl    -28(%ebp), %eax
        movl    %eax, -12(%ebp)
        movl    $2, -24(%ebp)
        movl    -12(%ebp), %eax
        addl    $1, %eax
        movb    $30, (%eax)
        movl    -24(%ebp), %eax
        movl    -4(%ebp), %ecx
        leave
        leal    -4(%ecx), %esp
        ret
        .size   foo, .-foo
.globl bar
        .type   bar, @function
bar:
        pushl   %ebp
        movl    %esp, %ebp
        andl    $-16, %esp
        subl    $48, %esp
        movss   .LC0, %xmm0
        movlps  %xmm0, 32(%esp)
        movhps  %xmm0, 40(%esp)
        movl    $30, 16(%esp)
        xorps   %xmm0, %xmm0
        movlps  32(%esp), %xmm0
        movhps  40(%esp), %xmm0
        movlps  %xmm0, (%esp)
        movhps  %xmm0, 8(%esp)
        call    foo
        movl    $0, %eax
        leave
        ret
        .size   bar, .-bar
        .section        .rodata
        .align 16
.LC0:
        .long   1065353216
        .long   0
        .long   0
        .long   0
        .ident  "GCC: (GNU) 4.4.0 20080802 (experimental) [stack revision
138551]"
        .section        .note.GNU-stack,"",@progbits
bash-3.2$


-- 
           Summary: No need to align stack when incoming stack is aligned
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hjl dot tools at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37009

Reply via email to