Skip to content

Commit 2861ab8

Browse files
mrdaybirdhiraditya
authored andcommitted
Update howManyLessThans
1 parent b7768c5 commit 2861ab8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13000,12 +13000,16 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1300013000
return RHS;
1300113001
}
1300213002

13003-
// When the RHS is not invariant, we do not know the end bound of the loop and
13004-
// cannot calculate the ExactBECount needed by ExitLimit. However, we can
13005-
// calculate the MaxBECount, given the start, stride and max value for the end
13006-
// bound of the loop (RHS), and the fact that IV does not overflow (which is
13007-
// checked above).
1300813003
if (!isLoopInvariant(RHS, L)) {
13004+
// If RHS is an add recurrence, try again with lhs=lhs-rhs and rhs=0
13005+
if(auto RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS)){
13006+
return howManyLessThans(getMinusSCEV(IV, RHSAddRec),
13007+
getZero(IV->getType()), L, true, ControlsOnlyExit, AllowPredicates);
13008+
}
13009+
// If we cannot calculate ExactBECount, we can calculate the MaxBECount,
13010+
// given the start, stride and max value for the end bound of the
13011+
// loop (RHS), and the fact that IV does not overflow (which is
13012+
// checked above).
1300913013
const SCEV *MaxBECount = computeMaxBECountForLT(
1301013014
Start, Stride, RHS, getTypeSizeInBits(LHS->getType()), IsSigned);
1301113015
return ExitLimit(getCouldNotCompute() /* ExactNotTaken */, MaxBECount,

0 commit comments

Comments
 (0)