Skip to content

Commit 3cf65dd

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 3072e43 commit 3cf65dd

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;
@@ -2291,8 +2292,9 @@ static bool isIndvarOverflowCheckKnownFalse(
22912292
// We know the runtime overflow check is known false iff the (max) trip-count
22922293
// is known and (max) trip-count + (VF * UF) does not overflow in the type of
22932294
// the vector loop induction variable.
2294-
if (unsigned TC =
2295-
Cost->PSE.getSE()->getSmallConstantMaxTripCount(Cost->TheLoop)) {
2295+
SmallVector<const SCEVPredicate *, 2> Predicates;
2296+
if (unsigned TC = Cost->PSE.getSE()->getSmallConstantMaxTripCount(
2297+
Cost->TheLoop, &Predicates)) {
22962298
uint64_t MaxVF = VF.getKnownMinValue();
22972299
if (VF.isScalable()) {
22982300
std::optional<unsigned> MaxVScale =
@@ -3987,7 +3989,10 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
39873989
}
39883990

39893991
unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
3990-
unsigned MaxTC = PSE.getSE()->getSmallConstantMaxTripCount(TheLoop);
3992+
3993+
SmallVector<const SCEVPredicate *, 2> Predicates;
3994+
unsigned MaxTC =
3995+
PSE.getSE()->getSmallConstantMaxTripCount(TheLoop, &Predicates);
39913996
LLVM_DEBUG(dbgs() << "LV: Found trip count: " << TC << '\n');
39923997
if (TC != MaxTC)
39933998
LLVM_DEBUG(dbgs() << "LV: Found maximum trip count: " << MaxTC << '\n');
@@ -4278,7 +4283,9 @@ bool LoopVectorizationPlanner::isMoreProfitable(
42784283
InstructionCost CostA = A.Cost;
42794284
InstructionCost CostB = B.Cost;
42804285

4281-
unsigned MaxTripCount = PSE.getSE()->getSmallConstantMaxTripCount(OrigLoop);
4286+
SmallVector<const SCEVPredicate *, 2> Predicates;
4287+
unsigned MaxTripCount =
4288+
PSE.getSE()->getSmallConstantMaxTripCount(OrigLoop, &Predicates);
42824289

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

0 commit comments

Comments
 (0)