https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70255
Bug ID: 70255 Summary: change of the order of summation of floating point numbers despite no-associative-math Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: shatz at dsit dot co.il Target Milestone: --- Created attachment 37989 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37989&action=edit minimal test case of change of the order of summation Under certain very specific combination of factor gcc optimizer disregards order of summation specified in the source code despite "no-associative-math" option specified by means of function attribute. The bug does not happen when -fno-associative-math option specified on the command line. In the file, attached below there are 3 very similar versions of the function foo(). Only variant foo1() shows the bug. Here is a asm code generated for foo1(): foo1: .seh_endprologue vmovsd .LC0(%rip), %xmm2 vaddsd %xmm2, %xmm0, %xmm3 vsubsd %xmm3, %xmm0, %xmm0 vaddsd %xmm1, %xmm0, %xmm1 ; order of summation changed!!!! vaddsd %xmm2, %xmm1, %xmm0 ret .seh_endproc Here is an output of gcc -v: Using built-in specs. COLLECT_GCC=D:\bin\msys64\mingw64\bin\gcc.exe Target: x86_64-w64-mingw32 Configured with: ../gcc-5.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --with-gxx-include-dir=/mingw64/include/c++/5.2.0 --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-version-specific-runtime-libs --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev4, Built by MSYS2 project' --with-bugurl=http://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld Thread model: posix gcc version 5.2.0 (Rev4, Built by MSYS2 project) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-Ofast' '-Wall' '-mavx' '-mtune=generic' '-march=x86-64' D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/cc1.exe -E -quiet -v -iprefix D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/ -D_REENTRANT foo.c -mavx -mtune=generic -march=x86-64 -Wall -Ofast -fpch-preprocess -o foo.i ignoring duplicate directory "D:/bin/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/5.2.0/include" ignoring nonexistent directory "C:/building/msys64/mingw64/include" ignoring nonexistent directory "/mingw64/include" ignoring duplicate directory "D:/bin/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/5.2.0/include-fixed" ignoring duplicate directory "D:/bin/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/include" ignoring nonexistent directory "C:/building/msys64/mingw64/x86_64-w64-mingw32/include" #include "..." search starts here: #include <...> search starts here: D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/include D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../include D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/include-fixed D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-Ofast' '-Wall' '-mavx' '-mtune=generic' '-march=x86-64' D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/cc1.exe -fpreprocessed foo.i -quiet -dumpbase foo.c -mavx -mtune=generic -march=x86-64 -auxbase foo -Ofast -Wall -version -o foo.s GNU C11 (Rev4, Built by MSYS2 project) version 5.2.0 (x86_64-w64-mingw32) compiled by GNU C version 5.2.0, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C11 (Rev4, Built by MSYS2 project) version 5.2.0 (x86_64-w64-mingw32) compiled by GNU C version 5.2.0, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 6d1a96b0d4d4a024cf53bcf4b7004358 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-Ofast' '-Wall' '-mavx' '-mtune=generic' '-march=x86-64' D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/bin/as.exe -v -o foo.o foo.s GNU assembler version 2.25.1 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.25.1 COMPILER_PATH=D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/;D:/bin/msys64/mingw64/bin/../lib/gcc/;D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/bin/ LIBRARY_PATH=D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/;D:/bin/msys64/mingw64/bin/../lib/gcc/;D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../lib/;D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/lib/;D:/bin/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-Ofast' '-Wall' '-mavx' '-mtune=generic' '-march=x86-64'