Skip to content

Commit e47d220

Browse files
committed
[LV] Use getVectorLoopRegion to retrieve header. (NFC)
Update all places that currently assume the entry block to the plan is also the vector loop header to use getVectorLoopRegion instead. getVectorLoopRegion will keep doing the right thing when the pre-header is modeled explicitly (and becomes the new entry block in the plan).
1 parent 8f7db76 commit e47d220

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,7 +3758,8 @@ void InnerLoopVectorizer::fixCrossIterationPHIs(VPTransformState &State) {
37583758
// the currently empty PHI nodes. At this point every instruction in the
37593759
// original loop is widened to a vector form so we can use them to construct
37603760
// the incoming edges.
3761-
VPBasicBlock *Header = State.Plan->getEntry()->getEntryBasicBlock();
3761+
VPBasicBlock *Header =
3762+
State.Plan->getVectorLoopRegion()->getEntryBasicBlock();
37623763
for (VPRecipeBase &R : Header->phis()) {
37633764
if (auto *ReductionPhi = dyn_cast<VPReductionPHIRecipe>(&R))
37643765
fixReduction(ReductionPhi, State);
@@ -8092,7 +8093,8 @@ VPValue *VPRecipeBuilder::createBlockInMask(BasicBlock *BB, VPlanPtr &Plan) {
80928093
// constructing the desired canonical IV in the header block as its first
80938094
// non-phi instructions.
80948095
assert(CM.foldTailByMasking() && "must fold the tail");
8095-
VPBasicBlock *HeaderVPBB = Plan->getEntry()->getEntryBasicBlock();
8096+
VPBasicBlock *HeaderVPBB =
8097+
Plan->getVectorLoopRegion()->getEntryBasicBlock();
80968098
auto NewInsertionPoint = HeaderVPBB->getFirstNonPhi();
80978099
auto *IV = new VPWidenCanonicalIVRecipe(Plan->getCanonicalIV());
80988100
HeaderVPBB->insert(IV, HeaderVPBB->getFirstNonPhi());
@@ -8860,8 +8862,8 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
88608862
// After here, VPBB should not be used.
88618863
VPBB = nullptr;
88628864

8863-
assert(isa<VPRegionBlock>(Plan->getEntry()) &&
8864-
!Plan->getEntry()->getEntryBasicBlock()->empty() &&
8865+
assert(isa<VPRegionBlock>(Plan->getVectorLoopRegion()) &&
8866+
!Plan->getVectorLoopRegion()->getEntryBasicBlock()->empty() &&
88658867
"entry block must be set to a VPRegionBlock having a non-empty entry "
88668868
"VPBasicBlock");
88678869
RecipeBuilder.fixHeaderPhis();
@@ -8946,7 +8948,8 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
89468948

89478949
// Introduce a recipe to combine the incoming and previous values of a
89488950
// first-order recurrence.
8949-
for (VPRecipeBase &R : Plan->getEntry()->getEntryBasicBlock()->phis()) {
8951+
for (VPRecipeBase &R :
8952+
Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
89508953
auto *RecurPhi = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(&R);
89518954
if (!RecurPhi)
89528955
continue;
@@ -9162,7 +9165,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91629165
// dedicated latch block.
91639166
if (CM.foldTailByMasking()) {
91649167
Builder.setInsertPoint(LatchVPBB, LatchVPBB->begin());
9165-
for (VPRecipeBase &R : Plan->getEntry()->getEntryBasicBlock()->phis()) {
9168+
for (VPRecipeBase &R :
9169+
Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
91669170
VPReductionPHIRecipe *PhiR = dyn_cast<VPReductionPHIRecipe>(&R);
91679171
if (!PhiR || PhiR->isInLoop())
91689172
continue;
@@ -10574,7 +10578,8 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1057410578

1057510579
// Ensure that the start values for any VPReductionPHIRecipes are
1057610580
// updated before vectorising the epilogue loop.
10577-
VPBasicBlock *Header = BestEpiPlan.getEntry()->getEntryBasicBlock();
10581+
VPBasicBlock *Header =
10582+
BestEpiPlan.getVectorLoopRegion()->getEntryBasicBlock();
1057810583
for (VPRecipeBase &R : Header->phis()) {
1057910584
if (auto *ReductionPhi = dyn_cast<VPReductionPHIRecipe>(&R)) {
1058010585
if (auto *Resume = MainILV.getReductionResumeValue(

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ void VPlan::execute(VPTransformState *State) {
974974

975975
// Fix the latch value of canonical, reduction and first-order recurrences
976976
// phis in the vector loop.
977-
VPBasicBlock *Header = Entry->getEntryBasicBlock();
977+
VPBasicBlock *Header = getVectorLoopRegion()->getEntryBasicBlock();
978978
if (Header->empty()) {
979979
assert(EnableVPlanNativePath);
980980
Header = cast<VPBasicBlock>(Header->getSingleSuccessor());

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,9 @@ class VPlan {
26462646
VPRegionBlock *getVectorLoopRegion() {
26472647
return cast<VPRegionBlock>(getEntry());
26482648
}
2649+
const VPRegionBlock *getVectorLoopRegion() const {
2650+
return cast<VPRegionBlock>(getEntry());
2651+
}
26492652

26502653
/// Returns the canonical induction recipe of the vector loop.
26512654
VPCanonicalIVPHIRecipe *getCanonicalIV() {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ bool VPlanTransforms::mergeReplicateRegions(VPlan &Plan) {
297297
}
298298

299299
void VPlanTransforms::removeRedundantInductionCasts(VPlan &Plan) {
300-
for (auto &Phi : Plan.getEntry()->getEntryBasicBlock()->phis()) {
300+
for (auto &Phi : Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
301301
auto *IV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
302302
if (!IV || IV->getTruncInst())
303303
continue;

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ bool VPlanVerifier::verifyPlanIsValid(const VPlan &Plan) {
157157
}
158158
}
159159

160-
const VPRegionBlock *TopRegion = cast<VPRegionBlock>(Plan.getEntry());
160+
const VPRegionBlock *TopRegion = Plan.getVectorLoopRegion();
161161
const VPBasicBlock *Entry = dyn_cast<VPBasicBlock>(TopRegion->getEntry());
162162
if (!Entry) {
163163
errs() << "VPlan entry block is not a VPBasicBlock\n";

0 commit comments

Comments
 (0)