mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Add comments as per review feedback.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47061 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cdbcfccece
commit
3a4cbe2a41
@ -2525,18 +2525,26 @@ HowManyLessThans(SCEV *LHS, SCEV *RHS, const Loop *L, bool isSigned) {
|
|||||||
return UnknownValue;
|
return UnknownValue;
|
||||||
|
|
||||||
if (AddRec->isAffine()) {
|
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.
|
// FORNOW: We only support unit strides.
|
||||||
SCEVHandle One = SE.getIntegerSCEV(1, RHS->getType());
|
SCEVHandle One = SE.getIntegerSCEV(1, RHS->getType());
|
||||||
if (AddRec->getOperand(1) != One)
|
if (AddRec->getOperand(1) != One)
|
||||||
return UnknownValue;
|
return UnknownValue;
|
||||||
|
|
||||||
SCEVHandle Start = AddRec->getOperand(0);
|
// We know the LHS is of the form {n,+,1} and the RHS is some loop-invariant
|
||||||
SCEVHandle End = isSigned ? SE.getSMaxExpr(RHS, Start) : (SCEVHandle)RHS;
|
// 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);
|
||||||
|
|
||||||
|
// 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);
|
return SE.getMinusSCEV(End, Start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user