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