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