@@ -2390,10 +2390,10 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
2390
2390
return true ;
2391
2391
}
2392
2392
2393
- void VPlanTransforms::simplifyEVLIVs (VPlan &Plan) {
2393
+ void VPlanTransforms::canonicalizeEVLLoops (VPlan &Plan) {
2394
2394
using namespace llvm ::VPlanPatternMatch;
2395
- // Find EVL loop entries by locating VPEVLBasedIVPHIRecipe
2396
- // There should be only one EVL PHI in the entire plan
2395
+ // Find EVL loop entries by locating VPEVLBasedIVPHIRecipe.
2396
+ // There should be only one EVL PHI in the entire plan.
2397
2397
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr ;
2398
2398
2399
2399
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
@@ -2404,11 +2404,11 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2404
2404
EVLPhi = PhiR;
2405
2405
}
2406
2406
2407
- // Early return if no EVL PHI is found
2407
+ // Early return if no EVL PHI is found.
2408
2408
if (!EVLPhi)
2409
2409
return ;
2410
2410
2411
- VPBasicBlock *Entry = EVLPhi->getParent ();
2411
+ VPBasicBlock *HeaderVPBB = EVLPhi->getParent ();
2412
2412
VPValue *EVLIncrement = EVLPhi->getBackedgeValue ();
2413
2413
2414
2414
// Convert EVLPhi to concrete recipe.
@@ -2418,32 +2418,29 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2418
2418
EVLPhi->replaceAllUsesWith (ScalarR);
2419
2419
EVLPhi->eraseFromParent ();
2420
2420
2421
- // Replace CanonicalIVInc with EVL-PHI increment
2422
- VPRecipeBase *CanonicalIV = &*Entry->begin ();
2423
- assert (dyn_cast<VPPhi>(CanonicalIV) && " Unexpected canoincal iv" );
2421
+ // Replace CanonicalIVInc with EVL-PHI increment.
2422
+ VPRecipeBase *CanonicalIV = &*HeaderVPBB->begin ();
2423
+ assert (
2424
+ isa<VPPhi>(CanonicalIV) &&
2425
+ match (CanonicalIV->getOperand (1 ),
2426
+ m_c_Binary<Instruction::Add>(m_Specific (cast<VPPhi>(CanonicalIV)),
2427
+ m_Specific (&Plan.getVFxUF ()))) &&
2428
+ " Unexpected canoincal iv" );
2424
2429
VPValue *Backedge = CanonicalIV->getOperand (1 );
2425
2430
Backedge->replaceAllUsesWith (EVLIncrement);
2426
2431
2427
- // Remove unused phi
2432
+ // Remove unused phi and increment.
2428
2433
VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe ();
2429
2434
CanonicalIVIncrement->eraseFromParent ();
2430
2435
CanonicalIV->eraseFromParent ();
2431
2436
2432
- // Find the latch-exiting block and replace use of VectorTripCount
2437
+ // Replace the use of VectorTripCount in the latch-exiting block.
2433
2438
// Before: (branch-on-count EVLIVInc, VectorTripCount)
2434
2439
// After: (branch-on-count EVLIVInc, TripCount)
2435
- auto Range =
2436
- VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow (Entry));
2437
- auto It = find_if (Range, [&Entry](VPBasicBlock *VPBB) {
2438
- return any_of (VPBB->successors (),
2439
- [&Entry](VPBlockBase *Succ) { return Succ == Entry; });
2440
- });
2441
- assert ((It != Range.end ()) && " LatchExiting is not found" );
2442
-
2443
- VPBasicBlock *LatchExiting = *It;
2444
2440
2441
+ VPBasicBlock *LatchExiting =
2442
+ HeaderVPBB->getPredecessors ()[1 ]->getEntryBasicBlock ();
2445
2443
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator ());
2446
-
2447
2444
// Skip single-iteration loop region
2448
2445
if (match (LatchExitingBr, m_BranchOnCond (m_True ())))
2449
2446
return ;
0 commit comments