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

LoopStrengthReduce generates incorrect IR

Open annamthomas opened this issue 9 years ago • 1 comments

Bugzilla Link 32289
Version trunk
OS All
Attachments Original IR, IR produced with opt -loop-reduce on the original IR
CC @zmodem,@hfinkel,@sanjoy

Extended Description

Steps to reproduce (on trunk): opt -loop-reduce test2.ll -S > test2_lsr.ll

Source code snippet: vMeth1(long longarg, int intarg) {

    int ivar, jvar;
    boolean bArr[]=new boolean[N];

    ivar = 1;

    do {
        intarg += (((ivar * ivar) + intarg) - Test.instanceCount);
        bArr[ivar] = (((Test.dFld - Test.instanceCount) / (((long)(-(Test.fFld
  • Test.instanceCount))) | 1)) != (--intarg)); Test.iArrFld[ivar] = (int)(intarg *= (int)longarg); longarg += (++Test.iArrFld[ivar]); } while (++ivar < 98);

      jvar = 68;
    
      while (--jvar > 0) {
          intarg += (int)(intarg -= (int)(-(++Test.fFld)));
          try {
              intarg = (Test.iArrFld[jvar - 1] % -82);
          } catch (ArithmeticException a_e) {}
    
      }
    
      sum += longarg + ivar + jvar;
    

} This is in effect: sum += longarg + 98 + 0.

Both the loops above are transformed through LSR. When LSR is enabled, the longarg value for the sum is calculated incorrectly.

I have attached the original and transformed IR, along with detailed comments on how the value is calculated (and where the difference occurs). The result (sum) is calculated in the ResultBB.

annamthomas avatar Mar 15 '17 18:03 annamthomas

Is this still an issue, and do you know if it's a regression?

zmodem avatar Aug 07 '17 22:08 zmodem