Skip to content

Commit 3e106be

Browse files
committed
early return and remove lambda
1 parent 545228b commit 3e106be

File tree

1 file changed

+40
-44
lines changed

1 file changed

+40
-44
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,61 +2374,57 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
23742374
}
23752375

23762376
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;
24152378
// Find EVL loop entries by locating VPEVLBasedIVPHIRecipe
24162379
// There should be only one EVL PHI in the entire plan
24172380
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr;
2418-
VPBasicBlock *EVLPhiBlock = nullptr;
24192381

24202382
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
24212383
vp_depth_first_shallow(Plan.getEntry())))
24222384
for (VPRecipeBase &R : VPBB->phis())
24232385
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");
24252387
EVLPhi = PhiR;
2426-
EVLPhiBlock = VPBB;
24272388
}
24282389

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();
24322428
}
24332429

24342430
void VPlanTransforms::dropPoisonGeneratingRecipes(

0 commit comments

Comments
 (0)