Skip to content

Commit a51e282

Browse files
authored
[LV] Check if plan has an early exit via plan's exit blocks. (NFC) (#134720)
Add a dedicated function to check if a plan is for a loop with an early exit. This can easily be determined by checking the exit blocks. This allows removing a use of Legal->hasUncountableEarlyExit() from InnerLoopVectorizer. PR: #134720
1 parent 69c4e17 commit a51e282

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7566,14 +7566,10 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
75667566
VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), CM,
75677567
CM.CostKind);
75687568
precomputeCosts(BestPlan, BestFactor.Width, CostCtx);
7569-
// Set PlanForEarlyExitLoop to true if the BestPlan has been built from a
7570-
// loop with an uncountable early exit. The legacy cost model doesn't
7571-
// properly model costs for such loops.
7572-
bool PlanForEarlyExitLoop =
7573-
BestPlan.getVectorLoopRegion() &&
7574-
BestPlan.getVectorLoopRegion()->getSingleSuccessor() !=
7575-
BestPlan.getMiddleBlock();
7576-
assert((BestFactor.Width == LegacyVF.Width || PlanForEarlyExitLoop ||
7569+
// Verify that the VPlan-based and legacy cost models agree, except for VPlans
7570+
// with early exits and plans with additional VPlan simplifications. The
7571+
// legacy cost model doesn't properly model costs for such loops.
7572+
assert((BestFactor.Width == LegacyVF.Width || BestPlan.hasEarlyExit() ||
75777573
planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width),
75787574
CostCtx, OrigLoop) ||
75797575
planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width),
@@ -7784,7 +7780,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
77847780
// 2.5 When vectorizing the epilogue, fix reduction resume values from the
77857781
// additional bypass block.
77867782
if (VectorizingEpilogue) {
7787-
assert(!ILV.Legal->hasUncountableEarlyExit() &&
7783+
assert(!BestVPlan.hasEarlyExit() &&
77887784
"Epilogue vectorisation not yet supported with early exits");
77897785
BasicBlock *PH = OrigLoop->getLoopPreheader();
77907786
BasicBlock *BypassBlock = ILV.getAdditionalBypassBlock();

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,6 +3768,14 @@ class VPlan {
37683768
/// successors of the block in VPlan. The returned block is owned by the VPlan
37693769
/// and deleted once the VPlan is destroyed.
37703770
VPIRBasicBlock *createVPIRBasicBlock(BasicBlock *IRBB);
3771+
3772+
/// Returns true if the VPlan is based on a loop with an early exit. That is
3773+
/// the case if the VPlan has either more than one exit block or a single exit
3774+
/// block with multiple predecessors (one for the exit via the latch and one
3775+
/// via the other early exit).
3776+
bool hasEarlyExit() const {
3777+
return ExitBlocks.size() > 1 || ExitBlocks[0]->getNumPredecessors() > 1;
3778+
}
37713779
};
37723780

37733781
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

0 commit comments

Comments
 (0)