Skip to content

Commit d72b07f

Browse files
committed
Fix for single-iteration EVL loop
1 parent b109174 commit d72b07f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,8 +2418,19 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
24182418
EVLPhi->replaceAllUsesWith(ScalarR);
24192419
EVLPhi->eraseFromParent();
24202420

2421-
// Find the latch-exiting block and convert to variable-length stepping.
2422-
// Before: (branch-on-count CanonicalIVInc, VectorTripCount)
2421+
// Replace CanonicalIVInc with EVL-PHI increment
2422+
VPRecipeBase *CanonicalIV = &*Entry->begin();
2423+
assert(dyn_cast<VPPhi>(CanonicalIV) && "Unexpected canoincal iv");
2424+
VPValue *Backedge = CanonicalIV->getOperand(1);
2425+
Backedge->replaceAllUsesWith(EVLIncrement);
2426+
2427+
// Remove unused phi
2428+
VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe();
2429+
CanonicalIVIncrement->eraseFromParent();
2430+
CanonicalIV->eraseFromParent();
2431+
2432+
// Find the latch-exiting block and replace use of VectorTripCount
2433+
// Before: (branch-on-count EVLIVInc, VectorTripCount)
24232434
// After: (branch-on-count EVLIVInc, TripCount)
24242435
auto Range =
24252436
VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow(Entry));
@@ -2428,20 +2439,20 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
24282439
[&Entry](VPBlockBase *Succ) { return Succ == Entry; });
24292440
});
24302441
assert((It != Range.end()) && "LatchExiting is not found");
2442+
24312443
VPBasicBlock *LatchExiting = *It;
2444+
24322445
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator());
2433-
VPValue *ScalarIVInc;
2446+
2447+
// Skip single-iteration loop region
2448+
if (match(LatchExitingBr, m_BranchOnCond(m_True())))
2449+
return;
24342450
assert(LatchExitingBr &&
24352451
match(LatchExitingBr,
2436-
m_BranchOnCount(m_VPValue(ScalarIVInc),
2452+
m_BranchOnCount(m_VPValue(EVLIncrement),
24372453
m_Specific(&Plan.getVectorTripCount()))) &&
24382454
"Unexpected terminator in EVL loop");
24392455
LatchExitingBr->setOperand(1, Plan.getTripCount());
2440-
ScalarIVInc->replaceAllUsesWith(EVLIncrement);
2441-
VPRecipeBase *IVIncR = ScalarIVInc->getDefiningRecipe();
2442-
VPRecipeBase *ScalarIV = IVIncR->getOperand(0)->getDefiningRecipe();
2443-
IVIncR->eraseFromParent();
2444-
ScalarIV->eraseFromParent();
24452456
}
24462457

24472458
void VPlanTransforms::dropPoisonGeneratingRecipes(

0 commit comments

Comments
 (0)