@@ -2401,8 +2401,19 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2401
2401
EVLPhi->replaceAllUsesWith (ScalarR);
2402
2402
EVLPhi->eraseFromParent ();
2403
2403
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)
2406
2417
// After: (branch-on-count EVLIVInc, TripCount)
2407
2418
auto Range =
2408
2419
VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow (Entry));
@@ -2411,20 +2422,20 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2411
2422
[&Entry](VPBlockBase *Succ) { return Succ == Entry; });
2412
2423
});
2413
2424
assert ((It != Range.end ()) && " LatchExiting is not found" );
2425
+
2414
2426
VPBasicBlock *LatchExiting = *It;
2427
+
2415
2428
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 ;
2417
2433
assert (LatchExitingBr &&
2418
2434
match (LatchExitingBr,
2419
- m_BranchOnCount (m_VPValue (ScalarIVInc ),
2435
+ m_BranchOnCount (m_VPValue (EVLIncrement ),
2420
2436
m_Specific (&Plan.getVectorTripCount ()))) &&
2421
2437
" Unexpected terminator in EVL loop" );
2422
2438
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 ();
2428
2439
}
2429
2440
2430
2441
void VPlanTransforms::dropPoisonGeneratingRecipes (
0 commit comments