@@ -2428,30 +2428,24 @@ InnerLoopVectorizer::getOrCreateVectorTripCount(BasicBlock *InsertBlock) {
2428
2428
return VectorTripCount;
2429
2429
}
2430
2430
2431
- // / Helper to connect both the vector and scalar preheaders to the Plan's
2432
- // / entry. This is used when adjusting \p Plan during skeleton
2433
- // / creation, i.e. adjusting the plan after introducing an initial runtime
2434
- // / check.
2435
- // / TODO: Connect scalar preheader during initial VPlan construction.
2436
- static void connectScalarPreheaderAsBypassInVPlan (VPlan &Plan) {
2437
- VPBlockBase *VectorPH = Plan.getVectorPreheader ();
2438
- VPBlockBase *ScalarPH = Plan.getScalarPreheader ();
2439
- VPBlockBase *Entry = Plan.getEntry ();
2440
- VPBlockUtils::connectBlocks (Entry, ScalarPH);
2441
- std::swap (Entry->getSuccessors ()[0 ], Entry->getSuccessors ()[1 ]);
2442
- }
2443
-
2444
2431
// / Introduces a new VPIRBasicBlock for \p CheckIRBB to \p Plan between the
2445
- // / vector preheader and its predecessor, also connecting to the scalar
2446
- // / preheader.
2432
+ // / vector preheader and its predecessor, also connecting the new block to the
2433
+ // / scalar preheader.
2447
2434
static void introduceCheckBlockInVPlan (VPlan &Plan, BasicBlock *CheckIRBB) {
2435
+
2448
2436
VPBlockBase *ScalarPH = Plan.getScalarPreheader ();
2449
2437
VPBlockBase *VectorPH = Plan.getVectorPreheader ();
2450
2438
VPBlockBase *PreVectorPH = VectorPH->getSinglePredecessor ();
2451
- assert (PreVectorPH->getSuccessors ()[0 ] == ScalarPH && " Unexpected successor" );
2452
- VPIRBasicBlock *CheckVPIRBB = VPIRBasicBlock::fromBasicBlock (CheckIRBB);
2453
- VPBlockUtils::connectBlocks (CheckVPIRBB, ScalarPH);
2454
- VPBlockUtils::insertOnEdge (PreVectorPH, VectorPH, CheckVPIRBB);
2439
+ if (PreVectorPH->getNumSuccessors () != 1 ) {
2440
+ assert (PreVectorPH->getNumSuccessors () == 2 && " Expected 2 successors" );
2441
+ assert (PreVectorPH->getSuccessors ()[0 ] == ScalarPH &&
2442
+ " Unexpected successor" );
2443
+ VPIRBasicBlock *CheckVPIRBB = VPIRBasicBlock::fromBasicBlock (CheckIRBB);
2444
+ VPBlockUtils::insertOnEdge (PreVectorPH, VectorPH, CheckVPIRBB);
2445
+ PreVectorPH = CheckVPIRBB;
2446
+ }
2447
+ VPBlockUtils::connectBlocks (PreVectorPH, ScalarPH);
2448
+ PreVectorPH->swapSuccessors ();
2455
2449
}
2456
2450
2457
2451
void InnerLoopVectorizer::emitIterationCountCheck (BasicBlock *Bypass) {
@@ -2536,7 +2530,7 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
2536
2530
LoopBypassBlocks.push_back (TCCheckBlock);
2537
2531
2538
2532
// TODO: Wrap LoopVectorPreHeader in VPIRBasicBlock here.
2539
- connectScalarPreheaderAsBypassInVPlan (Plan);
2533
+ introduceCheckBlockInVPlan (Plan, nullptr );
2540
2534
}
2541
2535
2542
2536
BasicBlock *InnerLoopVectorizer::emitSCEVChecks (BasicBlock *Bypass) {
@@ -7919,13 +7913,8 @@ EpilogueVectorizerMainLoop::emitIterationCountCheck(BasicBlock *Bypass,
7919
7913
setBranchWeights (BI, MinItersBypassWeights, /* IsExpected=*/ false );
7920
7914
ReplaceInstWithInst (TCCheckBlock->getTerminator (), &BI);
7921
7915
7922
- // Connect the vector preheader to the scalar preheader when creating the trip
7923
- // count for the epilogue loop. Otherwise there is already a runtime check and
7924
- // connection to the scalar preheader, so we introduce it as new check block.
7925
- if (ForEpilogue)
7926
- connectScalarPreheaderAsBypassInVPlan (Plan);
7927
- else
7928
- introduceCheckBlockInVPlan (Plan, TCCheckBlock);
7916
+ // Connect TCCheckblock to the VPlan.
7917
+ introduceCheckBlockInVPlan (Plan, TCCheckBlock);
7929
7918
return TCCheckBlock;
7930
7919
}
7931
7920
@@ -8071,14 +8060,15 @@ EpilogueVectorizerEpilogueLoop::emitMinimumVectorEpilogueIterCountCheck(
8071
8060
ReplaceInstWithInst (Insert->getTerminator (), &BI);
8072
8061
LoopBypassBlocks.push_back (Insert);
8073
8062
8074
- // A new entry block has been created for the epilogue VPlan. Hook it in.
8063
+ // A new entry block has been created for the epilogue VPlan. Hook it in, as
8064
+ // otherwise we would try to modify the entry to the main vector loop.
8075
8065
VPIRBasicBlock *NewEntry = VPIRBasicBlock::fromBasicBlock (Insert);
8076
8066
VPBasicBlock *OldEntry = Plan.getEntry ();
8077
8067
VPBlockUtils::reassociateBlocks (OldEntry, NewEntry);
8078
8068
Plan.setEntry (NewEntry);
8079
8069
delete OldEntry;
8080
8070
8081
- connectScalarPreheaderAsBypassInVPlan (Plan);
8071
+ introduceCheckBlockInVPlan (Plan, nullptr );
8082
8072
return Insert;
8083
8073
}
8084
8074
0 commit comments