Skip to content

Commit 207e485

Browse files
committed
[VPlan] Track VectorPH during skeleton creation. (NFC)
Split off from llvm#108378. This ensures that the logic works even if now vector region exits.
1 parent 1fa0302 commit 207e485

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ class InnerLoopVectorizer {
479479
AC(AC), ORE(ORE), VF(VecWidth),
480480
MinProfitableTripCount(MinProfitableTripCount), UF(UnrollFactor),
481481
Builder(PSE.getSE()->getContext()), Legal(LVL), Cost(CM), BFI(BFI),
482-
PSI(PSI), RTChecks(RTChecks), Plan(Plan) {
482+
PSI(PSI), RTChecks(RTChecks), Plan(Plan),
483+
VectorPHVPB(Plan.getEntry()->getSingleSuccessor()) {
483484
// Query this against the original loop and save it here because the profile
484485
// of the original loop header may change as the transformation happens.
485486
OptForSizeBasedOnProfile = llvm::shouldOptimizeForSize(
@@ -582,6 +583,11 @@ class InnerLoopVectorizer {
582583
virtual void printDebugTracesAtStart() {}
583584
virtual void printDebugTracesAtEnd() {}
584585

586+
/// Introduces a new VPIRBasicBlock for \p CheckIRBB to Plan between the
587+
/// vector preheader and its predecessor, also connecting the new block to the
588+
/// scalar preheader.
589+
void introduceCheckBlockInVPlan(BasicBlock *CheckIRBB);
590+
585591
/// The original loop.
586592
Loop *OrigLoop;
587593

@@ -676,6 +682,10 @@ class InnerLoopVectorizer {
676682
BasicBlock *AdditionalBypassBlock = nullptr;
677683

678684
VPlan &Plan;
685+
686+
/// The vector preheader block of \p Plan, used as target for check blocks
687+
/// introduced during skeleton creation.
688+
VPBlockBase *VectorPHVPB;
679689
};
680690

681691
/// Encapsulate information regarding vectorization of a loop and its epilogue.
@@ -2443,19 +2453,15 @@ InnerLoopVectorizer::getOrCreateVectorTripCount(BasicBlock *InsertBlock) {
24432453
return VectorTripCount;
24442454
}
24452455

2446-
/// Introduces a new VPIRBasicBlock for \p CheckIRBB to \p Plan between the
2447-
/// vector preheader and its predecessor, also connecting the new block to the
2448-
/// scalar preheader.
2449-
static void introduceCheckBlockInVPlan(VPlan &Plan, BasicBlock *CheckIRBB) {
2456+
void InnerLoopVectorizer::introduceCheckBlockInVPlan(BasicBlock *CheckIRBB) {
24502457
VPBlockBase *ScalarPH = Plan.getScalarPreheader();
2451-
VPBlockBase *VectorPH = Plan.getVectorPreheader();
2452-
VPBlockBase *PreVectorPH = VectorPH->getSinglePredecessor();
2458+
VPBlockBase *PreVectorPH = VectorPHVPB->getSinglePredecessor();
24532459
if (PreVectorPH->getNumSuccessors() != 1) {
24542460
assert(PreVectorPH->getNumSuccessors() == 2 && "Expected 2 successors");
24552461
assert(PreVectorPH->getSuccessors()[0] == ScalarPH &&
24562462
"Unexpected successor");
24572463
VPIRBasicBlock *CheckVPIRBB = Plan.createVPIRBasicBlock(CheckIRBB);
2458-
VPBlockUtils::insertOnEdge(PreVectorPH, VectorPH, CheckVPIRBB);
2464+
VPBlockUtils::insertOnEdge(PreVectorPH, VectorPHVPB, CheckVPIRBB);
24592465
PreVectorPH = CheckVPIRBB;
24602466
}
24612467
VPBlockUtils::connectBlocks(PreVectorPH, ScalarPH);
@@ -2544,7 +2550,7 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
25442550
LoopBypassBlocks.push_back(TCCheckBlock);
25452551

25462552
// TODO: Wrap LoopVectorPreHeader in VPIRBasicBlock here.
2547-
introduceCheckBlockInVPlan(Plan, TCCheckBlock);
2553+
introduceCheckBlockInVPlan(TCCheckBlock);
25482554
}
25492555

25502556
BasicBlock *InnerLoopVectorizer::emitSCEVChecks(BasicBlock *Bypass) {
@@ -2562,7 +2568,7 @@ BasicBlock *InnerLoopVectorizer::emitSCEVChecks(BasicBlock *Bypass) {
25622568
LoopBypassBlocks.push_back(SCEVCheckBlock);
25632569
AddedSafetyChecks = true;
25642570

2565-
introduceCheckBlockInVPlan(Plan, SCEVCheckBlock);
2571+
introduceCheckBlockInVPlan(SCEVCheckBlock);
25662572
return SCEVCheckBlock;
25672573
}
25682574

@@ -2599,7 +2605,7 @@ BasicBlock *InnerLoopVectorizer::emitMemRuntimeChecks(BasicBlock *Bypass) {
25992605

26002606
AddedSafetyChecks = true;
26012607

2602-
introduceCheckBlockInVPlan(Plan, MemCheckBlock);
2608+
introduceCheckBlockInVPlan(MemCheckBlock);
26032609
return MemCheckBlock;
26042610
}
26052611

@@ -7952,7 +7958,7 @@ EpilogueVectorizerMainLoop::emitIterationCountCheck(BasicBlock *Bypass,
79527958
setBranchWeights(BI, MinItersBypassWeights, /*IsExpected=*/false);
79537959
ReplaceInstWithInst(TCCheckBlock->getTerminator(), &BI);
79547960

7955-
introduceCheckBlockInVPlan(Plan, TCCheckBlock);
7961+
introduceCheckBlockInVPlan(TCCheckBlock);
79567962
return TCCheckBlock;
79577963
}
79587964

@@ -8092,7 +8098,7 @@ EpilogueVectorizerEpilogueLoop::emitMinimumVectorEpilogueIterCountCheck(
80928098
Plan.setEntry(NewEntry);
80938099
// OldEntry is now dead and will be cleaned up when the plan gets destroyed.
80948100

8095-
introduceCheckBlockInVPlan(Plan, Insert);
8101+
introduceCheckBlockInVPlan(Insert);
80968102
return Insert;
80978103
}
80988104

0 commit comments

Comments
 (0)