2121
2222using namespace llvm ;
2323
24- // / Create and return a new VPRegionBlock for loop starting at \p HeaderVPBB, if
25- // / it is a header of a loop.
26- static VPRegionBlock *introduceRegion (VPlan &Plan, VPBlockBase *HeaderVPBB,
27- VPDominatorTree &VPDT) {
28- if (HeaderVPBB->getNumPredecessors () != 2 )
29- return nullptr ;
24+ // / Create and return a new VPRegionBlock for loop starting at \p HeaderVPBB and
25+ // / return it.
26+ static VPRegionBlock *introduceRegion (VPlan &Plan, VPBlockBase *HeaderVPBB) {
3027 VPBlockBase *PreheaderVPBB = HeaderVPBB->getPredecessors ()[0 ];
3128 VPBlockBase *LatchVPBB = HeaderVPBB->getPredecessors ()[1 ];
32- if (!VPDT.dominates (HeaderVPBB, LatchVPBB))
33- return nullptr ;
34- assert (VPDT.dominates (PreheaderVPBB, HeaderVPBB) &&
35- " preheader must dominate header" );
3629 VPBlockUtils::disconnectBlocks (PreheaderVPBB, HeaderVPBB);
3730 VPBlockUtils::disconnectBlocks (LatchVPBB, HeaderVPBB);
3831 VPBlockBase *Succ = LatchVPBB->getSingleSuccessor ();
32+ assert (LatchVPBB->getNumSuccessors () <= 1 &&
33+ " Latch has more than one successor" );
3934 if (Succ)
4035 VPBlockUtils::disconnectBlocks (LatchVPBB, Succ);
4136
4237 auto *R = Plan.createVPRegionBlock (HeaderVPBB, LatchVPBB, " " ,
4338 false /* isReplicator*/ );
39+ R->setParent (HeaderVPBB->getParent ());
4440 // All VPBB's reachable shallowly from HeaderVPBB belong to top level loop,
45- // because VPlan is expected to end at top level latch.
41+ // because VPlan is expected to end at top level latch disconnected above .
4642 for (VPBlockBase *VPBB : vp_depth_first_shallow (HeaderVPBB))
4743 VPBB->setParent (R);
4844
@@ -57,9 +53,14 @@ void VPlanTransforms::introduceTopLevelVectorLoopRegion(
5753 bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop) {
5854 VPDominatorTree VPDT;
5955 VPDT.recalculate (Plan);
56+ for (VPBasicBlock *HeaderVPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
57+ vp_depth_first_shallow (Plan.getEntry ()))) {
58+ if (!HeaderVPBB->isHeader (VPDT))
59+ continue ;
60+ introduceRegion (Plan, HeaderVPBB);
61+ }
6062
61- auto *HeaderVPBB = cast<VPBasicBlock>(Plan.getEntry ()->getSingleSuccessor ());
62- VPRegionBlock *TopRegion = introduceRegion (Plan, HeaderVPBB, VPDT);
63+ VPRegionBlock *TopRegion = Plan.getVectorLoopRegion ();
6364 auto *OrigExiting = TopRegion->getExiting ();
6465 VPBasicBlock *LatchVPBB = Plan.createVPBasicBlock (" vector.latch" );
6566 VPBlockUtils::insertBlockAfter (LatchVPBB, OrigExiting);
@@ -120,9 +121,4 @@ void VPlanTransforms::introduceTopLevelVectorLoopRegion(
120121 ScalarLatchTerm->getDebugLoc (), " cmp.n" );
121122 Builder.createNaryOp (VPInstruction::BranchOnCond, {Cmp},
122123 ScalarLatchTerm->getDebugLoc ());
123-
124- for (VPBlockBase *HeaderVPBB :
125- vp_depth_first_shallow (Plan.getVectorLoopRegion ()->getEntry ())) {
126- introduceRegion (Plan, HeaderVPBB, VPDT);
127- }
128124}
0 commit comments