https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111107

--- Comment #19 from LIU Hao <lh_mouse at 126 dot com> ---
test.c:

```
void foo(int* p);

int bar(int x, int y) {
  _Alignas(16) int t[4] = { x, y, x, y };
  foo(t);
  return 42;
}
```

With SSE (not default):

```
E:\lh_mouse\Desktop>gcc test.c -O2 -c -msse && objdump -drw -Mintel test.o

test.o:     file format pe-i386


Disassembly of section .text:

00000000 <_bar>:
   0:   55                      push   ebp
   1:   89 e5                   mov    ebp,esp
   3:   83 e4 f0                and    esp,0xfffffff0
   6:   8d 64 24 e0             lea    esp,[esp-0x20]
   a:   66 0f 6e 45 08          movd   xmm0,DWORD PTR [ebp+0x8]
   f:   8d 44 24 10             lea    eax,[esp+0x10]
  13:   66 0f 3a 22 45 0c 01    pinsrd xmm0,DWORD PTR [ebp+0xc],0x1
  1a:   89 04 24                mov    DWORD PTR [esp],eax
  1d:   66 0f 6c c0             punpcklqdq xmm0,xmm0
  21:   f3 0f 7f 44 24 10       movdqu XMMWORD PTR [esp+0x10],xmm0
  27:   e8 00 00 00 00          call   2c <_bar+0x2c>   28: DISP32      _foo
  2c:   89 ec                   mov    esp,ebp
  2e:   b8 2a 00 00 00          mov    eax,0x2a
  33:   5d                      pop    ebp
  34:   c3                      ret
```

Without SSE (default):

```
E:\lh_mouse\Desktop>gcc test.c -O2 -c -mno-sse && objdump -drw -Mintel test.o

test.o:     file format pe-i386


Disassembly of section .text:

00000000 <_bar>:
   0:   8d 64 24 d4             lea    esp,[esp-0x2c]
   4:   8b 44 24 34             mov    eax,DWORD PTR [esp+0x34]
   8:   8b 54 24 30             mov    edx,DWORD PTR [esp+0x30]
   c:   89 44 24 14             mov    DWORD PTR [esp+0x14],eax
  10:   89 44 24 1c             mov    DWORD PTR [esp+0x1c],eax
  14:   8d 44 24 10             lea    eax,[esp+0x10]
  18:   89 04 24                mov    DWORD PTR [esp],eax
  1b:   89 54 24 10             mov    DWORD PTR [esp+0x10],edx
  1f:   89 54 24 18             mov    DWORD PTR [esp+0x18],edx
  23:   e8 00 00 00 00          call   28 <_bar+0x28>   24: DISP32      _foo
  28:   b8 2a 00 00 00          mov    eax,0x2a
  2d:   8d 64 24 2c             lea    esp,[esp+0x2c]
  31:   c3                      ret
```

So it looks like enabling SSE somehow forces realigning ESP. But in this case
we declare a variable that requires the realignment, which is the bug.. ?

Reply via email to