Skip to content

Commit f969a79

Browse files
committed
[LoopVectorize] Use predicated version of getSmallConstantMaxTripCount
There are a number of places where we call getSmallConstantMaxTripCount without passing a vector of predicates: getSmallBestKnownTC isIndvarOverflowCheckKnownFalse computeMaxVF isMoreProfitable I've changed all of these to now pass in a predicate vector so that we get the benefit of making better vectorisation choices when we know the max trip count for loops that require SCEV predicate checks. I've tried to add tests that cover all the cases affected by these changes.
1 parent 96e6d12 commit f969a79

File tree

2 files changed

+56
-327
lines changed

2 files changed

+56
-327
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ static std::optional<unsigned> getSmallBestKnownTC(ScalarEvolution &SE,
422422
return *EstimatedTC;
423423

424424
// Check if upper bound estimate is known.
425-
if (unsigned ExpectedTC = SE.getSmallConstantMaxTripCount(L))
425+
SmallVector<const SCEVPredicate *, 2> Predicates;
426+
if (unsigned ExpectedTC = SE.getSmallConstantMaxTripCount(L, &Predicates))
426427
return ExpectedTC;
427428

428429
return std::nullopt;
@@ -2298,8 +2299,9 @@ static bool isIndvarOverflowCheckKnownFalse(
22982299
// We know the runtime overflow check is known false iff the (max) trip-count
22992300
// is known and (max) trip-count + (VF * UF) does not overflow in the type of
23002301
// the vector loop induction variable.
2301-
if (unsigned TC =
2302-
Cost->PSE.getSE()->getSmallConstantMaxTripCount(Cost->TheLoop)) {
2302+
SmallVector<const SCEVPredicate *, 2> Predicates;
2303+
if (unsigned TC = Cost->PSE.getSE()->getSmallConstantMaxTripCount(
2304+
Cost->TheLoop, &Predicates)) {
23032305
uint64_t MaxVF = VF.getKnownMinValue();
23042306
if (VF.isScalable()) {
23052307
std::optional<unsigned> MaxVScale =
@@ -3994,7 +3996,10 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
39943996
}
39953997

39963998
unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
3997-
unsigned MaxTC = PSE.getSE()->getSmallConstantMaxTripCount(TheLoop);
3999+
4000+
SmallVector<const SCEVPredicate *, 2> Predicates;
4001+
unsigned MaxTC =
4002+
PSE.getSE()->getSmallConstantMaxTripCount(TheLoop, &Predicates);
39984003
LLVM_DEBUG(dbgs() << "LV: Found trip count: " << TC << '\n');
39994004
if (TC != MaxTC)
40004005
LLVM_DEBUG(dbgs() << "LV: Found maximum trip count: " << MaxTC << '\n');
@@ -4285,7 +4290,9 @@ bool LoopVectorizationPlanner::isMoreProfitable(
42854290
InstructionCost CostA = A.Cost;
42864291
InstructionCost CostB = B.Cost;
42874292

4288-
unsigned MaxTripCount = PSE.getSE()->getSmallConstantMaxTripCount(OrigLoop);
4293+
SmallVector<const SCEVPredicate *, 2> Predicates;
4294+
unsigned MaxTripCount =
4295+
PSE.getSE()->getSmallConstantMaxTripCount(OrigLoop, &Predicates);
42894296

42904297
// Improve estimate for the vector width if it is scalable.
42914298
unsigned EstimatedWidthA = A.Width.getKnownMinValue();

0 commit comments

Comments
 (0)