derived from CP2K and discussed in PR 29975, the following is miscompiled with the current 4.2 branch :
[EMAIL PROTECTED]:/scratch/vondele/clean/cp2k/src> cat test.f90 SUBROUTINE T(nsubcell,sab_max,subcells) INTEGER, PARAMETER :: dp=KIND(0.0D0) REAL(dp) :: sab_max(3), subcells,nsubcell(3) nsubcell(:) = MIN(MAX(1,NINT(0.5_dp*subcells/sab_max(:))),20) write(6,*) nsubcell END SUBROUTINE INTEGER, PARAMETER :: dp=KIND(0.0D0) REAL(dp) :: sab_max(3), subcells,nsubcell(3) subcells=2.00000000000000 sab_max=0.590060749244805_dp write(6,*) NINT(0.5_dp*subcells/sab_max(1)) CALL T(nsubcell,sab_max,subcells) END [EMAIL PROTECTED]:/scratch/vondele/clean/cp2k/src> gfortran -v -O3 -ffast-math -ftree-vectorize -march=native test.f90 Driving: gfortran -v -O3 -ffast-math -ftree-vectorize -march=native test.f90 -lgfortranbegin -lgfortran -lm -shared-libgcc Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: /data03/vondele/gcc_4_2_branch/gcc/configure --prefix=/data03/vondele/gcc_4_2_branch/build --with-gmp=/data03/vondele/ --with-mpfr=/data03/vondele/ --enable-languages=c,fortran Thread model: posix gcc version 4.2.1 20070627 (prerelease) /data03/vondele/gcc_4_2_branch/build/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/f951 test.f90 -march=k8 -mtune=k8 -quiet -dumpbase test.f90 -auxbase test -O3 -version -ffast-math -ftree-vectorize -I /data03/vondele/gcc_4_2_branch/build/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/finclude -o /tmp/ccTYHMGd.s GNU F95 version 4.2.1 20070627 (prerelease) (x86_64-unknown-linux-gnu) compiled by GNU C version 4.2.1 20070627 (prerelease). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 as -V -Qy -o /tmp/ccs8OyYj.o /tmp/ccTYHMGd.s GNU assembler version 2.16.91.0.5 (x86_64-suse-linux) using BFD version 2.16.91.0.5 20051219 (SUSE Linux) /data03/vondele/gcc_4_2_branch/build/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /data03/vondele/gcc_4_2_branch/build/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/crtbegin.o -L/data03/vondele/gcc_4_2_branch/build/lib/gcc/x86_64-unknown-linux-gnu/4.2.1 -L/data03/vondele/gcc_4_2_branch/build/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/data03/vondele/gcc_4_2_branch/build/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../.. /tmp/ccs8OyYj.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /data03/vondele/gcc_4_2_branch/build/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/crtfastmath.o /data03/vondele/gcc_4_2_branch/build/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/crtend.o /usr/lib/../lib64/crtn.o [EMAIL PROTECTED]:/scratch/vondele/clean/cp2k/src> ./a.out 2 20.0000000000000 20.0000000000000 20.0000000000000 [EMAIL PROTECTED]:/scratch/vondele/clean/cp2k/src> gfortran -O0 test.f90 [EMAIL PROTECTED]:/scratch/vondele/clean/cp2k/src> ./a.out 2 2.00000000000000 2.00000000000000 2.00000000000000 the result is incorrectly 20.0 instead of 2.0 with optimization -- Summary: [4.2] miscompilation at -O3 -ffast-math -ftree-vectorize -march=native Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jv244 at cam dot ac dot uk http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32533