forked from OSchip/llvm-project
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
This commit is contained in:
parent
f7290f7194
commit
d5990ad9b6
|
@ -6394,11 +6394,14 @@ ScalarEvolution::HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
|
||||||
// With unit stride, the iteration never steps past the limit value.
|
// With unit stride, the iteration never steps past the limit value.
|
||||||
} else if (isKnownPositive(Step)) {
|
} else if (isKnownPositive(Step)) {
|
||||||
// Test whether a positive iteration can step past the limit value and
|
// 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
|
// past the maximum value for its type in a single step. Constant negative
|
||||||
// can imply that stepping past RHS would immediately result in undefined
|
// stride should be rare because LHS > RHS comparisons are canonicalized
|
||||||
// behavior. No self-wrap is not useful here because the loop counter may
|
// to -LHS < -RHS.
|
||||||
// signed or unsigned wrap but continue iterating and terminate with
|
//
|
||||||
// defined behavior without ever self-wrapping.
|
// 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);
|
const SCEV *One = getConstant(Step->getType(), 1);
|
||||||
if (isSigned) {
|
if (isSigned) {
|
||||||
if (!AddRec->getNoWrapFlags(SCEV::FlagNSW)) {
|
if (!AddRec->getNoWrapFlags(SCEV::FlagNSW)) {
|
||||||
|
@ -6413,10 +6416,10 @@ ScalarEvolution::HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
|
||||||
.ult(getUnsignedRange(RHS).getUnsignedMax()))
|
.ult(getUnsignedRange(RHS).getUnsignedMax()))
|
||||||
return getCouldNotCompute();
|
return getCouldNotCompute();
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
// TODO: Handle negative strides here and below.
|
// Cannot handle variable stride.
|
||||||
return getCouldNotCompute();
|
return getCouldNotCompute();
|
||||||
|
}
|
||||||
// We know the LHS is of the form {n,+,s} and the RHS is some loop-invariant
|
// 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.
|
// 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
|
// Note that we cannot simply return max(m-n,0)/s because it's not safe to
|
||||||
|
|
Loading…
Reference in New Issue