[llvm-commits] [llvm] r47061 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp

2008-02-13 Thread Wojciech Matyjewicz
Author: wmat
Date: Wed Feb 13 05:51:34 2008
New Revision: 47061

URL: http://llvm.org/viewvc/llvm-project?rev=47061view=rev
Log:
Add comments as per review feedback.

Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=47061r1=47060r2=47061view=diff

==
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Feb 13 05:51:34 2008
@@ -2525,18 +2525,26 @@
 return UnknownValue;
 
   if (AddRec-isAffine()) {
-// The number of iterations for {n,+,1}  m, is m-n.  However, we don't
-// know that m is = n on input to the loop.  If it is, the condition
-// returns true zero times.  To handle both cases, we return SMAX(m, n)-n.
-
 // FORNOW: We only support unit strides.
 SCEVHandle One = SE.getIntegerSCEV(1, RHS-getType());
 if (AddRec-getOperand(1) != One)
   return UnknownValue;
 
+// We know the LHS is of the form {n,+,1} and the RHS is some 
loop-invariant
+// m.  So, we count the number of iterations in which {n,+,1}  m is true.
+// Note that we cannot simply return max(m-n,0) because it's not safe to
+// treat m-n as signed nor unsinged due to overflow possibility.
+
+// First, we get the value of the LHS in the first iteration: n
 SCEVHandle Start = AddRec-getOperand(0);
-SCEVHandle End = isSigned ? SE.getSMaxExpr(RHS, Start) : (SCEVHandle)RHS;
 
+// Then, we get the value of the LHS in the first iteration in which the
+// above condition doesn't hold.  This equals to max(m,n).
+// FIXME (PR2003): we should have an umax operator as well.
+SCEVHandle End = isSigned ? SE.getSMaxExpr(RHS,Start) : (SCEVHandle)RHS;
+
+// Finally, we subtract these two values to get the number of times the
+// backedge is executed: max(m,n)-n.
 return SE.getMinusSCEV(End, Start);
   }
 


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] [llvm] r47061 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp

2008-02-13 Thread Duncan Sands
 +// treat m-n as signed nor unsinged due to overflow possibility.

unsinged - unsigned

Ciao,

D.
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits