The expected output of this short program:
program bugchk
implicit none
integer, parameter :: N = 5
integer :: i,m,m1
integer :: ia(N+1), wn(N)
ia = (/ 1, 11, 21, 31, 41, 51 /)
!
m1 = ia(1)
do i = 1 , n
m = m1
m1 = ia(i+1)
wn(i) = m1 - m ! BAD CODE GENERATED FOR THIS
end do
print '(1x,A,5i4)','WN : ',wn
end program
is
WN : 10 10 10 10 10
Compiling and running the program with FTN95 8.30.279 produces the correct output except when the /opt and /64 options are both specified, in which case the output is
WN : 0 0 0 0 0
Examination of the /exp listing shows how the bug occurs (please see comments added to the relevant lines of the listing):
0011 m = m1 AT 67
0012 m1 = ia(i+1) AT 67
0013 wn(i) = m1 - m ! BAD CODE GENERATED FOR THIS AT 67
0014 end do AT 67
0015 print '(1x,A,5i4)','WN : ',wn AT 67
0016 AT 67
0017 end program AT 67
00000067(#1,51,17): Loading variables and other into registers prior to loop
00000067(#1,52,17): MOVSX_Q R8,I
0000006c(#1,53,17): MOVSX_Q RDI,M
00000071(#1,54,17): MOVSX_Q RSI,M1
00000076(#43,14,10): ALIGN16
00000080(#43,15,10): N_3:
00000080(#50,16,11): Removed instruction
00000080(#50,17,11): MOV_Q RDI,RSI # m = m1
00000083(#110,18,12): Removed instruction
00000083(#56,19,12): MOVSX_Q R14,IA[4*R8] # IA(I+1)
00000088(#56,20,12): MOV_Q RSI,R14 # m1 = IA(I+1)
0000008b(#117,21,13): SUB_Q R14,RSI # BUG HERE, should have been SUB_Q R14, RDI