[LLVMdev] Possible bug in ScalarEvolution
    Dan Gohman 
    gohman at apple.com
       
    Thu Nov 13 10:53:20 PST 2008
    
    
  
On Nov 12, 2008, at 1:30 AM, Zhou Sheng wrote:
> Hi,
>
> I'm using pass ScalarEvolution to analyze the loop trip count on my  
> application.
> And I found a possible bug in the code, that is in function  
> SCEVAddRecExpr::getNumIterationsInRange(),
> Line 2905:
>
> 2904     // The exit value should be (End+A)/A.
> 2905     APInt ExitVal = (End + A).udiv(A);
> 2906     ConstantInt *ExitValue = ConstantInt::get(ExitVal);
>
> The divide should be sdiv, right? otherwise, the ExitVal will be  
> zero when A = -1
>
> For example,   for (int i = 15; i > 7; --i) {}   the exit value  
> should be 7 not zero.
The code immediately after the code you pasted above checks to see
if the result value is out of range. In the case of your example code,
the value is out of range, and ScalarEvolution falls back to a different
algorithm for computing the exit value.
Do you have an example where it ScalarEvolution computes the wrong
exit value, or a specific case you're interested in where it misses
an opportunity to compute an exit value?
Dan
    
    
More information about the llvm-dev
mailing list