21
21
22
22
using namespace llvm ;
23
23
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) {
30
27
VPBlockBase *PreheaderVPBB = HeaderVPBB->getPredecessors ()[0 ];
31
28
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" );
36
29
VPBlockUtils::disconnectBlocks (PreheaderVPBB, HeaderVPBB);
37
30
VPBlockUtils::disconnectBlocks (LatchVPBB, HeaderVPBB);
38
31
VPBlockBase *Succ = LatchVPBB->getSingleSuccessor ();
32
+ assert (LatchVPBB->getNumSuccessors () <= 1 &&
33
+ " Latch has more than one successor" );
39
34
if (Succ)
40
35
VPBlockUtils::disconnectBlocks (LatchVPBB, Succ);
41
36
42
37
auto *R = Plan.createVPRegionBlock (HeaderVPBB, LatchVPBB, " " ,
43
38
false /* isReplicator*/ );
39
+ R->setParent (HeaderVPBB->getParent ());
44
40
// 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 .
46
42
for (VPBlockBase *VPBB : vp_depth_first_shallow (HeaderVPBB))
47
43
VPBB->setParent (R);
48
44
@@ -57,9 +53,14 @@ void VPlanTransforms::introduceTopLevelVectorLoopRegion(
57
53
bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop) {
58
54
VPDominatorTree VPDT;
59
55
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
+ }
60
62
61
- auto *HeaderVPBB = cast<VPBasicBlock>(Plan.getEntry ()->getSingleSuccessor ());
62
- VPRegionBlock *TopRegion = introduceRegion (Plan, HeaderVPBB, VPDT);
63
+ VPRegionBlock *TopRegion = Plan.getVectorLoopRegion ();
63
64
auto *OrigExiting = TopRegion->getExiting ();
64
65
VPBasicBlock *LatchVPBB = Plan.createVPBasicBlock (" vector.latch" );
65
66
VPBlockUtils::insertBlockAfter (LatchVPBB, OrigExiting);
@@ -120,9 +121,4 @@ void VPlanTransforms::introduceTopLevelVectorLoopRegion(
120
121
ScalarLatchTerm->getDebugLoc (), " cmp.n" );
121
122
Builder.createNaryOp (VPInstruction::BranchOnCond, {Cmp},
122
123
ScalarLatchTerm->getDebugLoc ());
123
-
124
- for (VPBlockBase *HeaderVPBB :
125
- vp_depth_first_shallow (Plan.getVectorLoopRegion ()->getEntry ())) {
126
- introduceRegion (Plan, HeaderVPBB, VPDT);
127
- }
128
124
}
0 commit comments