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