Hi, <br><br>I'm using pass ScalarEvolution to analyze the loop trip count on my application.<br>And I found a possible bug in the code, that is in function SCEVAddRecExpr::getNumIterationsInRange(),<br>Line 2905:<br><br>
2904     // The exit value should be (End+A)/A.<br>2905     APInt ExitVal = (End + A).udiv(A);<br>2906     ConstantInt *ExitValue = ConstantInt::get(ExitVal);<br><br>The divide should be sdiv, right? otherwise, the ExitVal will be zero when A = -1<br>
<br>For example,   for (int i = 15; i > 7; --i) {}   the exit value should be 7 not zero.<br><br><br><br>Also, I think we should consider the possible overflow situation,<br><br>for example,  for (uint7 i = 0; i < 64; i += 2) {}<br>
<br>The Range should be [0, 64)  (type i7), so<br><br>End = 63,  A = 2,<br><br>(End + A).sdiv(A) will be 97  instead of 32.<br><br>This is due to overflow of the addition of  End and A. They both are positive value, and the result should be 65 which in i7 type may be negative.<br>
<br>Any comments?<br>