Skip to content

Commit 2eab83f

Browse files
authored
[VPlan] Remove CanonicalIV when dissolving loop regions (NFC). (#142372)
Directly replace the canonical IV when we dissolve the containing region. That ensures that it won't get removed before the region gets removed, which would result in an invalid region. This removes the current ordering constraint between convertToConcreteRecipes and dissolving regions. PR: #142372
1 parent 9a15e3e commit 2eab83f

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,16 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
883883

884884
void VPRegionBlock::dissolveToCFGLoop() {
885885
auto *Header = cast<VPBasicBlock>(getEntry());
886+
if (auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(&Header->front())) {
887+
assert(this == getPlan()->getVectorLoopRegion() &&
888+
"Canonical IV must be in the entry of the top-level loop region");
889+
auto *ScalarR = VPBuilder(CanIV).createScalarPhi(
890+
{CanIV->getStartValue(), CanIV->getBackedgeValue()},
891+
CanIV->getDebugLoc(), "index");
892+
CanIV->replaceAllUsesWith(ScalarR);
893+
CanIV->eraseFromParent();
894+
}
895+
886896
VPBlockBase *Preheader = getSinglePredecessor();
887897
auto *ExitingLatch = cast<VPBasicBlock>(getExiting());
888898
VPBlockBase *Middle = getSingleSuccessor();

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,14 +2599,10 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
25992599
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
26002600
vp_depth_first_deep(Plan.getEntry()))) {
26012601
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
2602-
if (isa<VPCanonicalIVPHIRecipe, VPEVLBasedIVPHIRecipe>(&R)) {
2603-
auto *PhiR = cast<VPHeaderPHIRecipe>(&R);
2604-
StringRef Name =
2605-
isa<VPCanonicalIVPHIRecipe>(PhiR) ? "index" : "evl.based.iv";
2606-
VPBuilder Builder(PhiR);
2607-
auto *ScalarR = Builder.createScalarPhi(
2602+
if (auto *PhiR = dyn_cast<VPEVLBasedIVPHIRecipe>(&R)) {
2603+
auto *ScalarR = VPBuilder(PhiR).createScalarPhi(
26082604
{PhiR->getStartValue(), PhiR->getBackedgeValue()},
2609-
PhiR->getDebugLoc(), Name);
2605+
PhiR->getDebugLoc(), "evl.based.iv");
26102606
PhiR->replaceAllUsesWith(ScalarR);
26112607
ToRemove.push_back(PhiR);
26122608
continue;

0 commit comments

Comments
 (0)