[llvm-bugs] [Bug 32374] New: Loop Strength Reduction generating incorrect result

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 22 08:22:26 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=32374

            Bug ID: 32374
           Summary: Loop Strength Reduction generating incorrect result
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: anna at azul.com
                CC: llvm-bugs at lists.llvm.org

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 +.. + 125*125) as S(125) - S(5)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170322/49519900/attachment.html>


More information about the llvm-bugs mailing list