@@ -12862,11 +12862,10 @@ const SCEV *ScalarEvolution::getUDivCeilSCEV(const SCEV *N, const SCEV *D) {
12862
12862
return getAddExpr(MinNOne, getUDivExpr(NMinusOne, D));
12863
12863
}
12864
12864
12865
- const SCEV *ScalarEvolution::computeMaxBECountForLT(const SCEV *Start,
12866
- const SCEV *Stride,
12867
- const SCEV *End,
12868
- unsigned BitWidth,
12869
- bool IsSigned) {
12865
+ const SCEV *
12866
+ ScalarEvolution::computeMaxBECountForLT(const SCEV *Start, const SCEV *Stride,
12867
+ const SCEV *End, const Loop *L,
12868
+ unsigned BitWidth, bool IsSigned) {
12870
12869
// The logic in this function assumes we can represent a positive stride.
12871
12870
// If we can't, the backedge-taken count must be zero.
12872
12871
if (IsSigned && BitWidth == 1)
@@ -12900,8 +12899,10 @@ const SCEV *ScalarEvolution::computeMaxBECountForLT(const SCEV *Start,
12900
12899
// the case End = RHS of the loop termination condition. This is safe because
12901
12900
// in the other case (End - Start) is zero, leading to a zero maximum backedge
12902
12901
// taken count.
12903
- APInt MaxEnd = IsSigned ? APIntOps::smin(getSignedRangeMax(End), Limit)
12904
- : APIntOps::umin(getUnsignedRangeMax(End), Limit);
12902
+ const SCEV *GuardedEnd = applyLoopGuards(End, L);
12903
+ APInt MaxEnd = IsSigned
12904
+ ? APIntOps::smin(getSignedRangeMax(GuardedEnd), Limit)
12905
+ : APIntOps::umin(getUnsignedRangeMax(GuardedEnd), Limit);
12905
12906
12906
12907
// MaxBECount = ceil((max(MaxEnd, MinStart) - MinStart) / Stride)
12907
12908
MaxEnd = IsSigned ? APIntOps::smax(MaxEnd, MinStart)
@@ -13155,7 +13156,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
13155
13156
// loop (RHS), and the fact that IV does not overflow (which is
13156
13157
// checked above).
13157
13158
const SCEV *MaxBECount = computeMaxBECountForLT(
13158
- Start, Stride, RHS, getTypeSizeInBits(LHS->getType()), IsSigned);
13159
+ Start, Stride, RHS, L, getTypeSizeInBits(LHS->getType()), IsSigned);
13159
13160
return ExitLimit(getCouldNotCompute() /* ExactNotTaken */, MaxBECount,
13160
13161
MaxBECount, false /*MaxOrZero*/, Predicates);
13161
13162
}
@@ -13339,7 +13340,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
13339
13340
MaxOrZero = true;
13340
13341
} else {
13341
13342
ConstantMaxBECount = computeMaxBECountForLT(
13342
- Start, Stride, RHS, getTypeSizeInBits(LHS->getType()), IsSigned);
13343
+ Start, Stride, RHS, L, getTypeSizeInBits(LHS->getType()), IsSigned);
13343
13344
}
13344
13345
13345
13346
if (isa<SCEVCouldNotCompute>(ConstantMaxBECount) &&
0 commit comments