@@ -2418,8 +2418,19 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2418
2418
EVLPhi->replaceAllUsesWith (ScalarR);
2419
2419
EVLPhi->eraseFromParent ();
2420
2420
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)
2423
2434
// After: (branch-on-count EVLIVInc, TripCount)
2424
2435
auto Range =
2425
2436
VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow (Entry));
@@ -2428,20 +2439,20 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2428
2439
[&Entry](VPBlockBase *Succ) { return Succ == Entry; });
2429
2440
});
2430
2441
assert ((It != Range.end ()) && " LatchExiting is not found" );
2442
+
2431
2443
VPBasicBlock *LatchExiting = *It;
2444
+
2432
2445
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 ;
2434
2450
assert (LatchExitingBr &&
2435
2451
match (LatchExitingBr,
2436
- m_BranchOnCount (m_VPValue (ScalarIVInc ),
2452
+ m_BranchOnCount (m_VPValue (EVLIncrement ),
2437
2453
m_Specific (&Plan.getVectorTripCount ()))) &&
2438
2454
" Unexpected terminator in EVL loop" );
2439
2455
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 ();
2445
2456
}
2446
2457
2447
2458
void VPlanTransforms::dropPoisonGeneratingRecipes (
0 commit comments