Skip to content

Commit 1bc6c5d

Browse files
committed
Fix for single-iteration EVL loop
1 parent 3e106be commit 1bc6c5d

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
@@ -2401,8 +2401,19 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
24012401
EVLPhi->replaceAllUsesWith(ScalarR);
24022402
EVLPhi->eraseFromParent();
24032403

2404-
// Find the latch-exiting block and convert to variable-length stepping.
2405-
// Before: (branch-on-count CanonicalIVInc, VectorTripCount)
2404+
// Replace CanonicalIVInc with EVL-PHI increment
2405+
VPRecipeBase *CanonicalIV = &*Entry->begin();
2406+
assert(dyn_cast<VPPhi>(CanonicalIV) && "Unexpected canoincal iv");
2407+
VPValue *Backedge = CanonicalIV->getOperand(1);
2408+
Backedge->replaceAllUsesWith(EVLIncrement);
2409+
2410+
// Remove unused phi
2411+
VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe();
2412+
CanonicalIVIncrement->eraseFromParent();
2413+
CanonicalIV->eraseFromParent();
2414+
2415+
// Find the latch-exiting block and replace use of VectorTripCount
2416+
// Before: (branch-on-count EVLIVInc, VectorTripCount)
24062417
// After: (branch-on-count EVLIVInc, TripCount)
24072418
auto Range =
24082419
VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow(Entry));
@@ -2411,20 +2422,20 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
24112422
[&Entry](VPBlockBase *Succ) { return Succ == Entry; });
24122423
});
24132424
assert((It != Range.end()) && "LatchExiting is not found");
2425+
24142426
VPBasicBlock *LatchExiting = *It;
2427+
24152428
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator());
2416-
VPValue *ScalarIVInc;
2429+
2430+
// Skip single-iteration loop region
2431+
if (match(LatchExitingBr, m_BranchOnCond(m_True())))
2432+
return;
24172433
assert(LatchExitingBr &&
24182434
match(LatchExitingBr,
2419-
m_BranchOnCount(m_VPValue(ScalarIVInc),
2435+
m_BranchOnCount(m_VPValue(EVLIncrement),
24202436
m_Specific(&Plan.getVectorTripCount()))) &&
24212437
"Unexpected terminator in EVL loop");
24222438
LatchExitingBr->setOperand(1, Plan.getTripCount());
2423-
ScalarIVInc->replaceAllUsesWith(EVLIncrement);
2424-
VPRecipeBase *IVIncR = ScalarIVInc->getDefiningRecipe();
2425-
VPRecipeBase *ScalarIV = IVIncR->getOperand(0)->getDefiningRecipe();
2426-
IVIncR->eraseFromParent();
2427-
ScalarIV->eraseFromParent();
24282439
}
24292440

24302441
void VPlanTransforms::dropPoisonGeneratingRecipes(

0 commit comments

Comments
 (0)