Bug 53485 - gcc -O -mavx generates illegal instruction on win64
Summary: gcc -O -mavx generates illegal instruction on win64
Status: WAITING
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.6.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-25 15:09 UTC by Ian McConnell
Modified: 2016-08-14 18:14 UTC (History)
3 users (show)

See Also:
Host:
Target: x86_64-w64-mingw32
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-08-14 00:00:00


Attachments
preprocessed source (21.06 KB, text/plain)
2012-05-25 15:09 UTC, Ian McConnell
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ian McConnell 2012-05-25 15:09:18 UTC
Created attachment 27495 [details]
preprocessed source

Compiling the attached program with optimization and AVX for Win64 generates an illegal instruction. The same code runs correctly on Win32 and on Linux64.

$ x86_64-w64-mingw32-gcc -m64 -mavx bug.c -O -g -o bug.exe -Wall -Wextra -save-temps
$ ./bug.exe
BUG PROGRAM START: We should get this message once.
DEBUG fun1 start...
Illegal instruction
$ gdb bug.exe
(gdb) r
Starting program: C:\cygwin\home\nas/bug.exe
[New Thread 2436.0x38c]
BUG PROGRAM START: We should get this message once.
DEBUG fun1 start...

Program received signal SIGILL, Illegal instruction.
fun1 () at bug.c:95
95         v1 = vfone;
(gdb) x/i $pc
=> 0x4015e7 <fun1+54>:  vmovaps 0x7b11(%rip),%ymm0        # 0x409100
(gdb) p $rip
$1 = (void (*)()) 0x4015e7 <fun1+54>
(gdb) info frame
Stack level 0, frame at 0x22fe40:
 rip = 0x4015e7 in fun1 (bug.c:95); saved rip 0x40171b
 called by frame at 0x22fe70
 source language c.
 Arglist at 0x22fe30, args:
 Locals at 0x22fe30, Previous frame's sp is 0x22fe40
 Saved registers:
  rbx at 0x22fe20, rsi at 0x22fe28, rbp at 0x22fe30, rip at 0x22fe38, xmm15 at 0x22fe38

$ x86_64-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=C:\cygwin\home\nas\mingw64\bin\x86_64-w64-mingw32-gcc.exe
COLLECT_LTO_WRAPPER=c:/cygwin/home/nas/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.6.3/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: /home/drangon/work/mingw-w64-dgn/source/gcc/configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-nls --enable-languages=c,c++,objc,obj-c++ --with-gmp=/home/drangon/work/mingw-w64-dgn/build/for_target --enable-twoprocess --disable-libstdcxx-pch --disable-win32-registry --prefix=/home/drangon/work/mingw-w64-dgn/target --with-sysroot=/home/drangon/work/mingw-w64-dgn/target
Thread model: win32
gcc version 4.6.3 20120225 (prerelease) (GCC)


I have also tried the mingw64 cross compiler from
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/
gcc version 4.8.0 20120509 (experimental) (GCC) 
and I get the same error (though I need to use -O3)

If I download an older version,
gcc version 4.5.4 20111030 (prerelease) [svn/rev.180676 - mingw-w64/oz] (GCC) 
then I don't get the illegal instruction.
Comment 1 H.J. Lu 2012-05-25 15:49:05 UTC
(In reply to comment #0)
> Created attachment 27495 [details]
> preprocessed source
> 
> Compiling the attached program with optimization and AVX for Win64 generates an
> illegal instruction. The same code runs correctly on Win32 and on Linux64.
> 
> $ x86_64-w64-mingw32-gcc -m64 -mavx bug.c -O -g -o bug.exe -Wall -Wextra
> -save-temps
> $ ./bug.exe
> BUG PROGRAM START: We should get this message once.
> DEBUG fun1 start...
> Illegal instruction
> $ gdb bug.exe
> (gdb) r
> Starting program: C:\cygwin\home\nas/bug.exe
> [New Thread 2436.0x38c]
> BUG PROGRAM START: We should get this message once.
> DEBUG fun1 start...
> 
> Program received signal SIGILL, Illegal instruction.
> fun1 () at bug.c:95
> 95         v1 = vfone;
> (gdb) x/i $pc
> => 0x4015e7 <fun1+54>:  vmovaps 0x7b11(%rip),%ymm0        # 0x409100
> (gdb) p $rip
> $1 = (void (*)()) 0x4015e7 <fun1+54>
> (gdb) info frame
> Stack level 0, frame at 0x22fe40:
>  rip = 0x4015e7 in fun1 (bug.c:95); saved rip 0x40171b

It looks like 0x7b11(%rip) isn't aligned to 16 byte.
Comment 2 Kai Tietz 2013-09-10 10:45:34 UTC
yes, it is an alignment issue.  Try to set explicit alignment for this global.
That it doesn't fail for 32-bit is just by chance.
This seems to me an OP issue.
Comment 3 Andrew Pinski 2016-08-14 18:14:42 UTC
Does this work now with a newer version of GCC?