@@ -13000,12 +13000,16 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
13000
13000
return RHS;
13001
13001
}
13002
13002
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).
13008
13003
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).
13009
13013
const SCEV *MaxBECount = computeMaxBECountForLT(
13010
13014
Start, Stride, RHS, getTypeSizeInBits(LHS->getType()), IsSigned);
13011
13015
return ExitLimit(getCouldNotCompute() /* ExactNotTaken */, MaxBECount,
0 commit comments