Bug 57927 - -march=core-avx2 different than -march=native on INTEL Haswell (i7-4700K)
Summary: -march=core-avx2 different than -march=native on INTEL Haswell (i7-4700K)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.8.2
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-18 17:23 UTC by vincenzo Innocente
Modified: 2013-08-28 08:42 UTC (History)
4 users (show)

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


Attachments
Patch to add Ivy Bridge/Haswell detection (378 bytes, patch)
2013-08-27 03:43 UTC, Christian Widmer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description vincenzo Innocente 2013-07-18 17:23:56 UTC
for instance

mkdir scimark2TMP
cd scimark2TMP
wget http://math.nist.gov/scimark2/scimark2_1c.zip .
unzip scimark2_1c.zip
c++ -S LU.c -O3 -march=native -o LU.native -v
c++ -S LU.c -O3 -march=core-avx2 -o LU.avx2 -v
diff LU.native LU.avx2

if you run the benchmark
gcc -O3 -march=core-avx2 *.c -lm; ./a.out 5 
gcc -O3 -march=native *.c -lm; ./a.out 5 
"core-avx2" is better than "native"
Comment 1 Jakub Jelinek 2013-07-18 17:49:11 UTC
So what exactly does the -v print?
Comment 2 vincenzo Innocente 2013-07-18 19:30:28 UTC
COLLECT_GCC_OPTIONS='-S' '-O3' '-march=native' '-o' 'LU.native' '-v' '-shared-libgcc'
 /afs/cern.ch/user/i/innocent/w2/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/cc1plus -quiet -v -D_GNU_SOURCE LU.c -march=corei7-avx -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mmovbe -maes -mpclmul -mpopcnt -mabm -mno-lwp -mfma -mno-fma4 -mno-xop -mbmi -mbmi2 -mno-tbm -mavx -mavx2 -msse4.2 -msse4.1 -mlzcnt -mno-rtm -mno-hle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=8192 -mtune=generic -quiet -dumpbase LU.c -auxbase-strip LU.native -O3 -version -o LU.native
GNU C++ (GCC) version 4.9.0 20130718 (experimental) [trunk revision 201034] (x86_64-unknown-linux-gnu)

versus

COLLECT_GCC_OPTIONS='-S' '-O3' '-march=core-avx2' '-o' 'LU.avx2' '-v' '-shared-libgcc'
 /afs/cern.ch/user/i/innocent/w2/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/cc1plus -quiet -v -D_GNU_SOURCE LU.c -quiet -dumpbase LU.c -march=core-avx2 -auxbase-strip LU.avx2 -O3 -version -o LU.avx2
GNU C++ (GCC) version 4.9.0 20130718 (experimental) [trunk revision 201034] (x86_64-unknown-linux-gnu)
Comment 3 Marc Glisse 2013-07-18 19:51:48 UTC
gcc/config/i386/driver-i386.c host processor detection apparently hasn't been updated for those recent processors yet. You could look for this code:

        case 0x2d:
          /* Sandy Bridge.  */
          cpu = "corei7-avx";
          break;

and add nearby:

        case 0x3a:
          /* Ivy Bridge.  */
          cpu = "core-avx2";
          break;

Also, a few lines below, before "if (has_avx)", one could test has_avx2 and use core-avx2 as a default in that case.
Comment 4 Christian Widmer 2013-08-27 03:43:45 UTC
Created attachment 30703 [details]
Patch to add Ivy Bridge/Haswell detection

Here is a short patch adding Ivy Bridge and Haswell detection. Because Ivy Bridge does not support AVX2 it differs a bit from the suggestion above.
Comment 5 Uroš Bizjak 2013-08-27 06:45:11 UTC
(In reply to Christian Widmer from comment #4)
 
> Here is a short patch adding Ivy Bridge and Haswell detection. Because Ivy
> Bridge does not support AVX2 it differs a bit from the suggestion above.

Please post patches to gcc-patches@ mailing list, following the procedure outlined in [1].

[1] http://gcc.gnu.org/contribute.html
Comment 6 H.J. Lu 2013-08-27 16:20:08 UTC
(In reply to Christian Widmer from comment #4)
> Created attachment 30703 [details]
> Patch to add Ivy Bridge/Haswell detection
> 
> Here is a short patch adding Ivy Bridge and Haswell detection. Because Ivy
> Bridge does not support AVX2 it differs a bit from the suggestion above.

Ivy Bridge is core-avx-i, not corei7-avx.
Comment 7 Christian Widmer 2013-08-27 20:20:08 UTC
(In reply to H.J. Lu from comment #6)
> (In reply to Christian Widmer from comment #4)
> > Created attachment 30703 [details]
> > Patch to add Ivy Bridge/Haswell detection
> > 
> > Here is a short patch adding Ivy Bridge and Haswell detection. Because Ivy
> > Bridge does not support AVX2 it differs a bit from the suggestion above.
> 
> Ivy Bridge is core-avx-i, not corei7-avx.

Indeed it is. Although I have sent my wrong version to the mailing list a corrected version has been committed to trunk in the meantime which has later been amended by further model numbers. This bug can probably be closed now.
Comment 8 Jakub Jelinek 2013-08-27 21:16:23 UTC
Fixed.
Comment 9 Uroš Bizjak 2013-08-28 08:42:39 UTC
Also backported to 4.8 (and in part to 4.7) branch.