summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2013-10-22 05:09:40 +0000
committerAndrew Trick <atrick@apple.com>2013-10-22 05:09:40 +0000
commitd5990ad9b61d26fd87334f063b3c47e4b1e205e7 (patch)
treecba91abb6e011b07d8bbdc5b51e61f74f8a46f7e /llvm/lib/Analysis/ScalarEvolution.cpp
parentf7290f7194c8b873d6c1019d759faa074022ac89 (diff)
downloadbcm5719-llvm-d5990ad9b61d26fd87334f063b3c47e4b1e205e7.tar.gz
bcm5719-llvm-d5990ad9b61d26fd87334f063b3c47e4b1e205e7.zip
Clarify SCEV comments.
We handle for(i=n; i>0; i -= s) by canonicalizing within SCEV to for(i=-n; i<0; i += s). llvm-svn: 193147
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 0512429ad8a..ca959ab4378 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6394,11 +6394,14 @@ ScalarEvolution::HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
// With unit stride, the iteration never steps past the limit value.
} else if (isKnownPositive(Step)) {
// Test whether a positive iteration can step past the limit value and
- // past the maximum value for its type in a single step. The NSW/NUW flags
- // can imply that stepping past RHS would immediately result in undefined
- // behavior. No self-wrap is not useful here because the loop counter may
- // signed or unsigned wrap but continue iterating and terminate with
- // defined behavior without ever self-wrapping.
+ // past the maximum value for its type in a single step. Constant negative
+ // stride should be rare because LHS > RHS comparisons are canonicalized
+ // to -LHS < -RHS.
+ //
+ // NSW/NUW flags imply that stepping past RHS would immediately result in
+ // undefined behavior. No self-wrap is not useful here because the loop
+ // counter may signed or unsigned wrap but continue iterating and
+ // terminate with defined behavior without ever self-wrapping.
const SCEV *One = getConstant(Step->getType(), 1);
if (isSigned) {
if (!AddRec->getNoWrapFlags(SCEV::FlagNSW)) {
@@ -6413,10 +6416,10 @@ ScalarEvolution::HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
.ult(getUnsignedRange(RHS).getUnsignedMax()))
return getCouldNotCompute();
}
- } else
- // TODO: Handle negative strides here and below.
+ } else {
+ // Cannot handle variable stride.
return getCouldNotCompute();
-
+ }
// We know the LHS is of the form {n,+,s} and the RHS is some loop-invariant
// m. So, we count the number of iterations in which {n,+,s} < m is true.
// Note that we cannot simply return max(m-n,0)/s because it's not safe to
OpenPOWER on IntegriCloud