diff options
author | Wojciech Matyjewicz <wmatyjewicz@fastmail.fm> | 2008-02-13 11:51:34 +0000 |
---|---|---|
committer | Wojciech Matyjewicz <wmatyjewicz@fastmail.fm> | 2008-02-13 11:51:34 +0000 |
commit | 35545fd84d9f0dae173bd800c7307b6041386fe1 (patch) | |
tree | d1e88452216a8330a960a87f27ea355afca0ed97 /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 587c66ed96a2b8f0bbfbb7593570bfd66d94b321 (diff) | |
download | bcm5719-llvm-35545fd84d9f0dae173bd800c7307b6041386fe1.tar.gz bcm5719-llvm-35545fd84d9f0dae173bd800c7307b6041386fe1.zip |
Add comments as per review feedback.
llvm-svn: 47061
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 65cee82a964..4a440df07b2 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2525,18 +2525,26 @@ HowManyLessThans(SCEV *LHS, SCEV *RHS, const Loop *L, bool isSigned) { 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); } |