@@ -2374,61 +2374,57 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
2374
2374
}
2375
2375
2376
2376
void VPlanTransforms::simplifyEVLIVs (VPlan &Plan) {
2377
- auto ConvertEVLPhi = [](VPlan &Plan, VPBasicBlock *Entry,
2378
- VPEVLBasedIVPHIRecipe *EVLPhi) {
2379
- using namespace llvm ::VPlanPatternMatch;
2380
- VPValue *EVLIncrement = EVLPhi->getBackedgeValue ();
2381
-
2382
- // Convert EVLPhi to concrete recipe.
2383
- auto *ScalarR = VPBuilder (EVLPhi).createScalarPhi (
2384
- {EVLPhi->getStartValue (), EVLIncrement}, EVLPhi->getDebugLoc (),
2385
- " evl.based.iv" );
2386
- EVLPhi->replaceAllUsesWith (ScalarR);
2387
- EVLPhi->eraseFromParent ();
2388
-
2389
- // Find the latch-exiting block and convert to variable-length stepping.
2390
- // Before: (branch-on-count CanonicalIVInc, VectorTripCount)
2391
- // After: (branch-on-count EVLIVInc, TripCount)
2392
- auto Range =
2393
- VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow (Entry));
2394
- auto It = find_if (Range, [&](VPBasicBlock *VPBB) {
2395
- return any_of (VPBB->successors (),
2396
- [&](VPBlockBase *Succ) { return Succ == Entry; });
2397
- });
2398
- assert ((It != Range.end ()) && " LatchExiting is not found" );
2399
- VPBasicBlock *LatchExiting = *It;
2400
- auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator ());
2401
- VPValue *ScalarIVInc;
2402
- assert (LatchExitingBr &&
2403
- match (LatchExitingBr,
2404
- m_BranchOnCount (m_VPValue (ScalarIVInc),
2405
- m_Specific (&Plan.getVectorTripCount ()))) &&
2406
- " Unexpected terminator in EVL loop" );
2407
- LatchExitingBr->setOperand (1 , Plan.getTripCount ());
2408
- ScalarIVInc->replaceAllUsesWith (EVLIncrement);
2409
- VPRecipeBase *IVIncR = ScalarIVInc->getDefiningRecipe ();
2410
- VPRecipeBase *ScalarIV = IVIncR->getOperand (0 )->getDefiningRecipe ();
2411
- IVIncR->eraseFromParent ();
2412
- ScalarIV->eraseFromParent ();
2413
- };
2414
-
2377
+ using namespace llvm ::VPlanPatternMatch;
2415
2378
// Find EVL loop entries by locating VPEVLBasedIVPHIRecipe
2416
2379
// There should be only one EVL PHI in the entire plan
2417
2380
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr ;
2418
- VPBasicBlock *EVLPhiBlock = nullptr ;
2419
2381
2420
2382
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2421
2383
vp_depth_first_shallow (Plan.getEntry ())))
2422
2384
for (VPRecipeBase &R : VPBB->phis ())
2423
2385
if (auto *PhiR = dyn_cast<VPEVLBasedIVPHIRecipe>(&R)) {
2424
- assert (!EVLPhi && " Found multiple EVL PHIs - only one expected" );
2386
+ assert (!EVLPhi && " Found multiple EVL PHIs. Only one expected" );
2425
2387
EVLPhi = PhiR;
2426
- EVLPhiBlock = VPBB;
2427
2388
}
2428
2389
2429
- // Process the single EVL PHI if found
2430
- if (EVLPhi)
2431
- ConvertEVLPhi (Plan, EVLPhiBlock, EVLPhi);
2390
+ // Early return if no EVL PHI is found
2391
+ if (!EVLPhi)
2392
+ return ;
2393
+
2394
+ VPBasicBlock *Entry = EVLPhi->getParent ();
2395
+ VPValue *EVLIncrement = EVLPhi->getBackedgeValue ();
2396
+
2397
+ // Convert EVLPhi to concrete recipe.
2398
+ auto *ScalarR =
2399
+ VPBuilder (EVLPhi).createScalarPhi ({EVLPhi->getStartValue (), EVLIncrement},
2400
+ EVLPhi->getDebugLoc (), " evl.based.iv" );
2401
+ EVLPhi->replaceAllUsesWith (ScalarR);
2402
+ EVLPhi->eraseFromParent ();
2403
+
2404
+ // Find the latch-exiting block and convert to variable-length stepping.
2405
+ // Before: (branch-on-count CanonicalIVInc, VectorTripCount)
2406
+ // After: (branch-on-count EVLIVInc, TripCount)
2407
+ auto Range =
2408
+ VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow (Entry));
2409
+ auto It = find_if (Range, [&Entry](VPBasicBlock *VPBB) {
2410
+ return any_of (VPBB->successors (),
2411
+ [&Entry](VPBlockBase *Succ) { return Succ == Entry; });
2412
+ });
2413
+ assert ((It != Range.end ()) && " LatchExiting is not found" );
2414
+ VPBasicBlock *LatchExiting = *It;
2415
+ auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator ());
2416
+ VPValue *ScalarIVInc;
2417
+ assert (LatchExitingBr &&
2418
+ match (LatchExitingBr,
2419
+ m_BranchOnCount (m_VPValue (ScalarIVInc),
2420
+ m_Specific (&Plan.getVectorTripCount ()))) &&
2421
+ " Unexpected terminator in EVL loop" );
2422
+ LatchExitingBr->setOperand (1 , Plan.getTripCount ());
2423
+ ScalarIVInc->replaceAllUsesWith (EVLIncrement);
2424
+ VPRecipeBase *IVIncR = ScalarIVInc->getDefiningRecipe ();
2425
+ VPRecipeBase *ScalarIV = IVIncR->getOperand (0 )->getDefiningRecipe ();
2426
+ IVIncR->eraseFromParent ();
2427
+ ScalarIV->eraseFromParent ();
2432
2428
}
2433
2429
2434
2430
void VPlanTransforms::dropPoisonGeneratingRecipes (
0 commit comments