https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69471
Bug ID: 69471 Summary: "-march=native" unintentionally breaks further -march/-mtune flags Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: wavexx at thregr dot org Target Milestone: --- On a haswell host, the following: gcc -march=native -march=opteron or gcc -march=opteron -march=native both emit code which is illegal for the opteron ISA. Specifying -march=opteron alone works as intended. By running gcc -v I see: % g++ -MD -D_FILE_OFFSET_BITS=64 -O3 -march=native -pipe -fvisibility-inlines-hidden -O3 -pipe -march=opteron -mtune=generic -ggdb3 -std=gnu++11 -Wall -Wextra -Wpedantic -Wno-unused-parameter -c -o metasplit.o metasplit.cc -v Using built-in specs. COLLECT_GCC=g++ Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 6-20160117-1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 6.0.0 20160117 (experimental) [trunk revision 232481] (Debian 6-20160117-1) COLLECT_GCC_OPTIONS='-MD' '-D' '_FILE_OFFSET_BITS=64' '-O3' '-march=native' '-pipe' '-fvisibility-inlines-hidden' '-O3' '-pipe' '-march=opteron' '-mtune=generic' '-ggdb3' '-std=gnu++11' '-Wall' '-Wextra' '-Wpedantic' '-Wno-unused-parameter' '-c' '-o' 'metasplit.o' '-v' '-shared-libgcc' /usr/lib/gcc/x86_64-linux-gnu/6/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -MD metasplit.d -MQ metasplit.o -dD -D_GNU_SOURCE -D _FILE_OFFSET_BITS=64 metasplit.cc -march=haswell -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mmovbe -maes -mno-sha -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 -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-clwb -mno-pcommit -mno-mwaitx -mno-clzero -mno-pku -quiet -dumpbase metasplit.cc -march=opteron -mtune=generic -auxbase-strip metasplit.o -ggdb3 -O3 -O3 -Wall -Wextra -Wpedantic -Wno-unused-parameter -std=gnu++11 -version -fvisibility-inlines-hidden -o - | as -v --64 -o metasplit.o It becomes obvious why is that: -march=native gets expanded to all host-specific instructions, while the next -march=opteron doesn't reset them. Since I generally override the default flags in makefiles by appending exceptions where needed, I expect the regular behavior where the last flags overrides previous ones and thus found the current behavior unexpected. I originally discovered this problem in gcc 5.2, but it's still present in all further versions.