flang
flang copied to clipboard
Wrong results with O2 when compile do loop statement
Please consider this simple test program:
PROGRAM TEST
INTEGER :: INT, IDX
INT = 1
DO IDX=1,65
INT = ISHFT(INT,1)
IF(INT.EQ.0) GOTO 10
ENDDO
10 IF(IDX.NE.32) GOTO 900
PRINT *, 'PASS'
RETURN
900 PRINT *, 'ERROR 900'
END
LLVM and Flang version:
LLVM 10.0.1, flang_20201023
Compile this case with O2, I got the error result:
$ flang -O2 test.f90 -o test
ERROR 900
And when compiling with O0, the result is correct.
$ flang -O0 test.f90 -o test
PASS
Using following command line to get unoptimized IR:
flang -O2 -mllvm -opt-bisect-limit=0 test-sim.f90 -S -emit-llvm -o test-sim.noopt.ll
I can see that the following instruction was generated by flang2:
%3 = shl nsw i32 %2, 1 // nsw property
ISHFT performs the logical shift function. The generated instruction should not assume the nsw property.
So flang2 should generate llvm ir like %3 = shl i32 %2, 1.
Am I right?