llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Loop Strength Reduction generating incorrect result

Open annamthomas opened this issue 9 years ago • 2 comments

Bugzilla Link 32374
Version trunk
OS All
Attachments original IR, Optimized IR after loop reduce
CC @annamthomas,@choikwa,@zmodem,@qcolombet

Extended Description

When running loop strength reduce on an IR, it generates the incorrect result.

Source code snippet: intarg = longarg = 0; for (firstiv = 117; firstiv > 3; --firstiv) { var = dummy_call(); } for (secondiv = 6; secondiv < 126; secondiv++) { intarg+= (secondiv * secondiv); Test.iArrFld[secondiv + 1] -= (int)(--f1); } sum = intarg+ longarg+ firstiv + secondiv;

Here sum should be intarg + 0 + 3 + 126, where intarg = sum of squares from 6 to 125 (inclusive) [1] Quick calculation shows sum = 659202

I will attached the original IR and LSR optimized IR for this code. Reproduce the problem as: lli test.ll 659202

opt -loop-reduce -S test.ll > testlsr.ll lli testlsr.ll 659455

[1] FYI: Can use sum of squares of first n numbers to calculate the sum of (6*6 + 7 7 +.. + 125125) as S(125) - S(5)

annamthomas avatar Mar 22 '17 15:03 annamthomas

I'm getting different result from the test.ll

a.c a.ll test testbad.ll testbd test.ll testlsr testlsr.ll kchoi@kchoi-vbox:~/work/loopreduc$ ./testlsr 658949 kchoi@kchoi-vbox:~/work/loopreduc$ ./test 658949 <-- same result before/after loop-reduc with trunk clang/llvm build kchoi@kchoi-vbox:~/work/loopreduc$ ./testbd 659202 kchoi@kchoi-vbox:~/work/loopreduc$

testbd is from 2nd attachment and testlsr is after opt -loop-reduce -S test.ll >testlsr.ll

binaries are generated from clang $f -o

lli crashes for me when invoking on .ll Do you have another reproducible file?

choikwa avatar Sep 09 '17 16:09 choikwa

Does this still reproduce, and if so does it appear to be a regression that can be bisected?

zmodem avatar Aug 07 '17 23:08 zmodem