@@ -2429,28 +2429,29 @@ InnerLoopVectorizer::getOrCreateVectorTripCount(BasicBlock *InsertBlock) {
2429
2429
return VectorTripCount;
2430
2430
}
2431
2431
2432
- // / Helper to connect both the vector and scalar preheaders to the vector
2433
- // / preheader's predecessor . This is used when adjusting \p Plan during skeleton
2432
+ // / Helper to connect both the vector and scalar preheaders to the Plan's
2433
+ // / entry . This is used when adjusting \p Plan during skeleton
2434
2434
// / creation, i.e. adjusting the plan after introducing an initial runtime
2435
2435
// / check.
2436
2436
static void connectScalarPreheaderInVPlan (VPlan &Plan) {
2437
2437
VPBlockBase *VectorPH = Plan.getVectorPreheader ();
2438
2438
VPBlockBase *ScalarPH = Plan.getScalarPreheader ();
2439
- VPBlockBase *PredVPB = VectorPH->getSinglePredecessor ();
2440
- VPBlockUtils::disconnectBlocks (Plan.getEntry (), VectorPH);
2441
- VPBlockUtils::connectBlocks (PredVPB, ScalarPH);
2442
- VPBlockUtils::connectBlocks (PredVPB, VectorPH);
2439
+ VPBlockBase *PredVPB = Plan.getEntry ();
2440
+ VPBlockUtils::connectBlocks (PredVPB, ScalarPH, -1 , 0 );
2441
+ VPBlockUtils::connectBlocks (PredVPB, VectorPH, 0 , -1 );
2443
2442
}
2444
2443
2445
- static void connectCheckBlockInVPlan (VPlan &Plan, BasicBlock *CheckIRBB) {
2444
+ // / 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.
2447
+ static void introduceCheckBlockInVPlan (VPlan &Plan, BasicBlock *CheckIRBB) {
2446
2448
VPBlockBase *ScalarPH = Plan.getScalarPreheader ();
2447
2449
VPBlockBase *VectorPH = Plan.getVectorPreheader ();
2448
- VPBlockBase *PredVPB = VectorPH->getSinglePredecessor ();
2449
- VPBlockUtils::disconnectBlocks (PredVPB, VectorPH);
2450
+ VPBlockBase *PreVectorPH = VectorPH->getSinglePredecessor ();
2450
2451
VPIRBasicBlock *CheckVPIRBB = VPIRBasicBlock::fromBasicBlock (CheckIRBB);
2451
- VPBlockUtils::connectBlocks (PredVPB , CheckVPIRBB);
2452
+ VPBlockUtils::connectBlocks (PreVectorPH , CheckVPIRBB, - 1 , 1 );
2452
2453
VPBlockUtils::connectBlocks (CheckVPIRBB, ScalarPH);
2453
- VPBlockUtils::connectBlocks (CheckVPIRBB, VectorPH);
2454
+ VPBlockUtils::connectBlocks (CheckVPIRBB, VectorPH, 0 , - 1 );
2454
2455
}
2455
2456
2456
2457
void InnerLoopVectorizer::emitIterationCountCheck (BasicBlock *Bypass) {
@@ -2537,14 +2538,14 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
2537
2538
DT->getNode (Bypass)->getIDom ()) &&
2538
2539
" TC check is expected to dominate Bypass" );
2539
2540
2540
- // Update dominator for Bypass & LoopExit (if needed).
2541
2541
BranchInst &BI =
2542
2542
*BranchInst::Create (Bypass, LoopVectorPreHeader, CheckMinIters);
2543
2543
if (hasBranchWeightMD (*OrigLoop->getLoopLatch ()->getTerminator ()))
2544
2544
setBranchWeights (BI, MinItersBypassWeights, /* IsExpected=*/ false );
2545
2545
ReplaceInstWithInst (TCCheckBlock->getTerminator (), &BI);
2546
2546
LoopBypassBlocks.push_back (TCCheckBlock);
2547
2547
2548
+ // TODO: Wrap LoopVectorPreHeader in VPIRBasicBlock here.
2548
2549
connectScalarPreheaderInVPlan (Plan);
2549
2550
}
2550
2551
@@ -2563,7 +2564,7 @@ BasicBlock *InnerLoopVectorizer::emitSCEVChecks(BasicBlock *Bypass) {
2563
2564
LoopBypassBlocks.push_back (SCEVCheckBlock);
2564
2565
AddedSafetyChecks = true ;
2565
2566
2566
- connectCheckBlockInVPlan (Plan, SCEVCheckBlock);
2567
+ introduceCheckBlockInVPlan (Plan, SCEVCheckBlock);
2567
2568
return SCEVCheckBlock;
2568
2569
}
2569
2570
@@ -2600,7 +2601,7 @@ BasicBlock *InnerLoopVectorizer::emitMemRuntimeChecks(BasicBlock *Bypass) {
2600
2601
2601
2602
AddedSafetyChecks = true ;
2602
2603
2603
- connectCheckBlockInVPlan (Plan, MemCheckBlock);
2604
+ introduceCheckBlockInVPlan (Plan, MemCheckBlock);
2604
2605
return MemCheckBlock;
2605
2606
}
2606
2607
@@ -7909,7 +7910,7 @@ EpilogueVectorizerMainLoop::emitIterationCountCheck(BasicBlock *Bypass,
7909
7910
if (PredVPB->getNumSuccessors () == 1 )
7910
7911
connectScalarPreheaderInVPlan (Plan);
7911
7912
else
7912
- connectCheckBlockInVPlan (Plan, TCCheckBlock);
7913
+ introduceCheckBlockInVPlan (Plan, TCCheckBlock);
7913
7914
return TCCheckBlock;
7914
7915
}
7915
7916
@@ -7946,10 +7947,9 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton(
7946
7947
if (EPI.SCEVSafetyCheck )
7947
7948
EPI.SCEVSafetyCheck ->getTerminator ()->replaceUsesOfWith (
7948
7949
VecEpilogueIterationCountCheck, LoopScalarPreHeader);
7949
- if (EPI.MemSafetyCheck ) {
7950
+ if (EPI.MemSafetyCheck )
7950
7951
EPI.MemSafetyCheck ->getTerminator ()->replaceUsesOfWith (
7951
7952
VecEpilogueIterationCountCheck, LoopScalarPreHeader);
7952
- }
7953
7953
7954
7954
DT->changeImmediateDominator (LoopScalarPreHeader,
7955
7955
EPI.EpilogueIterationCountCheck );
0 commit comments