https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79720
Bug ID: 79720 Summary: floating point result depends on optimization level Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: tkoenig at gcc dot gnu.org Target Milestone: --- The following test case $ cat recip.f90 module try implicit none contains complex function r1(a) complex, value :: a r1 = 1./a; end function r1 complex function r2(a) complex, value :: a real :: a_real, a_imag; real :: v_6, v_7, v_9, v_10, v_11, v_12, v_13, v_14, v_15, v_16, v_17, & & v_18, v_19, v_20, v_21, v_22, v_23, v_24, v_27, v_28, & & v_29, v_30, v_31, v_32 logical :: v_8 a_real = real(a) a_imag = aimag(a) v_6 = abs(a_real); v_7 = abs(a_imag) v_8 = v_6 < v_7; if (.not.v_8) then v_9 = a_real / a_imag; v_10 = a_real * v_9; v_11 = a_imag + v_10; v_12 = v_9 + 0.0; v_13 = v_9 * 0.0; v_14 = v_13 - 1.0e+0; v_15 = v_12 / v_11; v_16 = v_14 / v_11; v_31 = v_15; v_32 = v_16; v_27 = v_31; v_28 = v_32; else v_17 = a_imag / a_real; v_18 = a_imag * v_17; v_19 = a_real + v_18; v_20 = v_17 * 0.0; v_21 = v_20 + 1.0e+0; v_22 = 0.0 - v_17; v_23 = v_21 / v_19; v_24 = v_22 / v_19; v_29 = v_23; v_30 = v_24; v_27 = v_29; v_28 = v_30; end if r2 = cmplx(v_27, v_28); end function r2 end module try program main use try implicit none complex :: c, a1, a2 c = (1.2e10, -3.2) a1 = r1(c) a2 = r2(c) print *,a1, a2 print *,a1-a2 end program main gives different results without optimization and with -O on x86_64 with a reasonably current trunk: ig25@linux-d6cw:~/Krempel/Complex> gfortran recip.f90 && ./a.out (8.333333329E-11,2.222222170E-20) (8.333333329E-11,2.222222331E-20) (0.00000000,-1.615587134E-27) ig25@linux-d6cw:~/Krempel/Complex> gfortran -O recip.f90 && ./a.out (8.333333329E-11,2.222222331E-20) (8.333333329E-11,2.222222331E-20) (0.00000000,0.00000000) It does not appear to be processor-specific, POWER7 exhibits the same behavior: [tkoenig@gcc1-power7 ~]$ gfortran recip.f90 && ./a.out ( 8.33333333E-11, 2.22222217E-20) ( 8.33333333E-11, 2.22222233E-20) ( 0.00000000 , -1.61558713E-27) [tkoenig@gcc1-power7 ~]$ gfortran -O recip.f90 && ./a.out ( 8.33333333E-11, 2.22222233E-20) ( 8.33333333E-11, 2.22222233E-20) ( 0.00000000 , 0.00000000 ) In the absence of -funsafe-math-optimizations, this is not supposed to happen. I would assume that this is not a dup of PR 72824; at least -fno-tree-loop-distribute-patterns has no effect.