Skip to content

Commit a88f03e

Browse files
committed
!fixup address comments, thanks!
1 parent 9854453 commit a88f03e

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,17 @@ bool VPBasicBlock::isExiting() const {
648648
return getParent() && getParent()->getExitingBasicBlock() == this;
649649
}
650650

651+
bool VPBasicBlock::isHeader(const VPDominatorTree &VPDT) const {
652+
if (getNumPredecessors() != 2)
653+
return false;
654+
VPBlockBase *LatchVPBB = getPredecessors()[1];
655+
if (!VPDT.dominates(this, LatchVPBB))
656+
return false;
657+
assert(VPDT.dominates(getPredecessors()[0], this) &&
658+
"preheader must dominate header");
659+
return true;
660+
}
661+
651662
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
652663
void VPBlockBase::print(raw_ostream &O) const {
653664
VPSlotTracker SlotTracker(getPlan());

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class SCEV;
5757
class Type;
5858
class VPBasicBlock;
5959
class VPBuilder;
60+
class VPDominatorTree;
6061
class VPRegionBlock;
6162
class VPlan;
6263
class VPLane;
@@ -3251,6 +3252,11 @@ class VPBasicBlock : public VPBlockBase {
32513252
/// Returns true if the block is exiting it's parent region.
32523253
bool isExiting() const;
32533254

3255+
/// Returns true if the block is a loop header block in the plain CFG; that
3256+
/// is, it has exactly 2 predecessors (preheader and latch), where the block
3257+
/// dominates the latch and the preheader dominates the block.
3258+
bool isHeader(const VPDominatorTree &VPDT) const;
3259+
32543260
/// Clone the current block and it's recipes, without updating the operands of
32553261
/// the cloned recipes.
32563262
VPBasicBlock *clone() override;

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,24 @@
2121

2222
using 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

Comments
 (0)