@@ -461,19 +461,23 @@ static void createLoopRegion(VPlan &Plan, VPBlockBase *HeaderVPB) {
461
461
VPBlockUtils::connectBlocks (R, Succ);
462
462
}
463
463
464
- void VPlanTransforms::createLoopRegions (VPlan &Plan, Type *InductionTy,
465
- PredicatedScalarEvolution &PSE,
466
- bool RequiresScalarEpilogueCheck,
467
- bool TailFolded, Loop *TheLoop) {
464
+ void VPlanTransforms::prepareForVectorization (VPlan &Plan, Type *InductionTy,
465
+ PredicatedScalarEvolution &PSE,
466
+ bool RequiresScalarEpilogueCheck,
467
+ bool TailFolded, Loop *TheLoop) {
468
468
VPDominatorTree VPDT;
469
469
VPDT.recalculate (Plan);
470
- for (VPBlockBase *HeaderVPB : vp_depth_first_shallow (Plan.getEntry ()))
471
- if (canonicalHeaderAndLatch (HeaderVPB, VPDT))
472
- createLoopRegion (Plan, HeaderVPB);
473
470
474
- VPRegionBlock *TopRegion = Plan.getVectorLoopRegion ();
475
- TopRegion->setName (" vector loop" );
476
- TopRegion->getEntryBasicBlock ()->setName (" vector.body" );
471
+ VPBlockBase *HeaderVPB = Plan.getEntry ()->getSingleSuccessor ();
472
+ canonicalHeaderAndLatch (HeaderVPB, VPDT);
473
+ VPBlockBase *LatchVPB = HeaderVPB->getPredecessors ()[1 ];
474
+
475
+ VPBasicBlock *VecPreheader = Plan.createVPBasicBlock (" vector.ph" );
476
+ VPBlockUtils::insertBlockAfter (VecPreheader, Plan.getEntry ());
477
+
478
+ VPBasicBlock *MiddleVPBB = Plan.createVPBasicBlock (" middle.block" );
479
+ VPBlockUtils::connectBlocks (LatchVPB, MiddleVPBB);
480
+ LatchVPB->swapSuccessors ();
477
481
478
482
// Create SCEV and VPValue for the trip count.
479
483
// We use the symbolic max backedge-taken-count, which works also when
@@ -487,11 +491,6 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy,
487
491
Plan.setTripCount (
488
492
vputils::getOrCreateVPValueForSCEVExpr (Plan, TripCount, SE));
489
493
490
- VPBasicBlock *VecPreheader = Plan.createVPBasicBlock (" vector.ph" );
491
- VPBlockUtils::insertBlockAfter (VecPreheader, Plan.getEntry ());
492
- VPBasicBlock *MiddleVPBB = Plan.createVPBasicBlock (" middle.block" );
493
- VPBlockUtils::insertBlockAfter (MiddleVPBB, TopRegion);
494
-
495
494
VPBasicBlock *ScalarPH = Plan.createVPBasicBlock (" scalar.ph" );
496
495
VPBlockUtils::connectBlocks (ScalarPH, Plan.getScalarHeader ());
497
496
@@ -516,10 +515,10 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy,
516
515
return ;
517
516
}
518
517
518
+ // The connection order corresponds to the operands of the conditional branch.
519
519
BasicBlock *IRExitBlock = TheLoop->getUniqueLatchExitBlock ();
520
520
auto *VPExitBlock = Plan.getExitBlock (IRExitBlock);
521
- // The connection order corresponds to the operands of the conditional branch.
522
- VPBlockUtils::insertBlockAfter (VPExitBlock, MiddleVPBB);
521
+ VPBlockUtils::connectBlocks (MiddleVPBB, VPExitBlock);
523
522
VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
524
523
525
524
auto *ScalarLatchTerm = TheLoop->getLoopLatch ()->getTerminator ();
@@ -538,3 +537,15 @@ void VPlanTransforms::createLoopRegions(VPlan &Plan, Type *InductionTy,
538
537
Builder.createNaryOp (VPInstruction::BranchOnCond, {Cmp},
539
538
ScalarLatchTerm->getDebugLoc ());
540
539
}
540
+
541
+ void VPlanTransforms::createLoopRegions (VPlan &Plan) {
542
+ VPDominatorTree VPDT;
543
+ VPDT.recalculate (Plan);
544
+ for (VPBlockBase *HeaderVPB : vp_depth_first_shallow (Plan.getEntry ()))
545
+ if (canonicalHeaderAndLatch (HeaderVPB, VPDT))
546
+ createLoopRegion (Plan, HeaderVPB);
547
+
548
+ VPRegionBlock *TopRegion = Plan.getVectorLoopRegion ();
549
+ TopRegion->setName (" vector loop" );
550
+ TopRegion->getEntryBasicBlock ()->setName (" vector.body" );
551
+ }
0 commit comments