@@ -2369,10 +2369,10 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
2369
2369
return true ;
2370
2370
}
2371
2371
2372
- void VPlanTransforms::simplifyEVLIVs (VPlan &Plan) {
2372
+ void VPlanTransforms::canonicalizeEVLLoops (VPlan &Plan) {
2373
2373
using namespace llvm ::VPlanPatternMatch;
2374
- // Find EVL loop entries by locating VPEVLBasedIVPHIRecipe
2375
- // There should be only one EVL PHI in the entire plan
2374
+ // Find EVL loop entries by locating VPEVLBasedIVPHIRecipe.
2375
+ // There should be only one EVL PHI in the entire plan.
2376
2376
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr ;
2377
2377
2378
2378
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
@@ -2383,11 +2383,11 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2383
2383
EVLPhi = PhiR;
2384
2384
}
2385
2385
2386
- // Early return if no EVL PHI is found
2386
+ // Early return if no EVL PHI is found.
2387
2387
if (!EVLPhi)
2388
2388
return ;
2389
2389
2390
- VPBasicBlock *Entry = EVLPhi->getParent ();
2390
+ VPBasicBlock *HeaderVPBB = EVLPhi->getParent ();
2391
2391
VPValue *EVLIncrement = EVLPhi->getBackedgeValue ();
2392
2392
2393
2393
// Convert EVLPhi to concrete recipe.
@@ -2397,32 +2397,29 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2397
2397
EVLPhi->replaceAllUsesWith (ScalarR);
2398
2398
EVLPhi->eraseFromParent ();
2399
2399
2400
- // Replace CanonicalIVInc with EVL-PHI increment
2401
- VPRecipeBase *CanonicalIV = &*Entry->begin ();
2402
- assert (dyn_cast<VPPhi>(CanonicalIV) && " Unexpected canoincal iv" );
2400
+ // Replace CanonicalIVInc with EVL-PHI increment.
2401
+ VPRecipeBase *CanonicalIV = &*HeaderVPBB->begin ();
2402
+ assert (
2403
+ isa<VPPhi>(CanonicalIV) &&
2404
+ match (CanonicalIV->getOperand (1 ),
2405
+ m_c_Binary<Instruction::Add>(m_Specific (cast<VPPhi>(CanonicalIV)),
2406
+ m_Specific (&Plan.getVFxUF ()))) &&
2407
+ " Unexpected canoincal iv" );
2403
2408
VPValue *Backedge = CanonicalIV->getOperand (1 );
2404
2409
Backedge->replaceAllUsesWith (EVLIncrement);
2405
2410
2406
- // Remove unused phi
2411
+ // Remove unused phi and increment.
2407
2412
VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe ();
2408
2413
CanonicalIVIncrement->eraseFromParent ();
2409
2414
CanonicalIV->eraseFromParent ();
2410
2415
2411
- // Find the latch-exiting block and replace use of VectorTripCount
2416
+ // Replace the use of VectorTripCount in the latch-exiting block.
2412
2417
// Before: (branch-on-count EVLIVInc, VectorTripCount)
2413
2418
// After: (branch-on-count EVLIVInc, TripCount)
2414
- auto Range =
2415
- VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow (Entry));
2416
- auto It = find_if (Range, [&Entry](VPBasicBlock *VPBB) {
2417
- return any_of (VPBB->successors (),
2418
- [&Entry](VPBlockBase *Succ) { return Succ == Entry; });
2419
- });
2420
- assert ((It != Range.end ()) && " LatchExiting is not found" );
2421
-
2422
- VPBasicBlock *LatchExiting = *It;
2423
2419
2420
+ VPBasicBlock *LatchExiting =
2421
+ HeaderVPBB->getPredecessors ()[1 ]->getEntryBasicBlock ();
2424
2422
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator ());
2425
-
2426
2423
// Skip single-iteration loop region
2427
2424
if (match (LatchExitingBr, m_BranchOnCond (m_True ())))
2428
2425
return ;
0 commit comments