The following short program demonstrates an optimizer bug that was first encountered in a ~800 line program.
program tmb11
implicit none
double precision A(2,5)
integer :: j,n=5
DOUBLE PRECISION RMAX,RSUM
INTRINSIC ABS
data A/1d0,2d0,2d0,4d0,3d0,6d0,1d0,0d0,0d0,2d0/
RMAX = 0.0D0
RSUM = 0.0D0
do j = 1, n
RSUM = RSUM + a(1,j)**2
if (RMAX >= ABS(a(1,j))) cycle
RMAX = ABS(a(1,j))
end do
write(*,'(A,F4.1)')'RSUM = ',RSUM
stop
end
Compiled with /opt, the program gives the incorrect output
RSUM = 5.0
instead of the correct output, which is
RSUM = 15.0
P.S.: Paul, I have further narrowed down the location of the bug by looking at the assembly listing (see my post of Fri Apr 17, 2015 6:14 am, below). The optimized code calculates SUM(a(1,1)**2) instead of SUM(a(1,j)**2).
[Added 3 August 2015]: The bug is still present in the 7.20 compiler release.