Skip to content

Commit 3a3e455

Browse files
committed
Address comments
1 parent d72b07f commit 3a3e455

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7315,8 +7315,8 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73157315
// Regions are dissolved after optimizing for VF and UF, which completely
73167316
// removes unneeded loop regions first.
73177317
VPlanTransforms::dissolveLoopRegions(BestVPlan);
7318-
// Enable variable-length stepping for EVL loops after regions are dissolved
7319-
VPlanTransforms::simplifyEVLIVs(BestVPlan);
7318+
// Canonicalize EVL loops after regions are dissolved.
7319+
VPlanTransforms::canonicalizeEVLLoops(BestVPlan);
73207320
// Perform the actual loop transformation.
73217321
VPTransformState State(&TTI, BestVF, LI, DT, ILV.AC, ILV.Builder, &BestVPlan,
73227322
OrigLoop->getParentLoop(),

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,10 +2390,10 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
23902390
return true;
23912391
}
23922392

2393-
void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2393+
void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) {
23942394
using namespace llvm::VPlanPatternMatch;
2395-
// Find EVL loop entries by locating VPEVLBasedIVPHIRecipe
2396-
// There should be only one EVL PHI in the entire plan
2395+
// Find EVL loop entries by locating VPEVLBasedIVPHIRecipe.
2396+
// There should be only one EVL PHI in the entire plan.
23972397
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr;
23982398

23992399
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
@@ -2404,11 +2404,11 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
24042404
EVLPhi = PhiR;
24052405
}
24062406

2407-
// Early return if no EVL PHI is found
2407+
// Early return if no EVL PHI is found.
24082408
if (!EVLPhi)
24092409
return;
24102410

2411-
VPBasicBlock *Entry = EVLPhi->getParent();
2411+
VPBasicBlock *HeaderVPBB = EVLPhi->getParent();
24122412
VPValue *EVLIncrement = EVLPhi->getBackedgeValue();
24132413

24142414
// Convert EVLPhi to concrete recipe.
@@ -2418,32 +2418,29 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
24182418
EVLPhi->replaceAllUsesWith(ScalarR);
24192419
EVLPhi->eraseFromParent();
24202420

2421-
// Replace CanonicalIVInc with EVL-PHI increment
2422-
VPRecipeBase *CanonicalIV = &*Entry->begin();
2423-
assert(dyn_cast<VPPhi>(CanonicalIV) && "Unexpected canoincal iv");
2421+
// Replace CanonicalIVInc with EVL-PHI increment.
2422+
VPRecipeBase *CanonicalIV = &*HeaderVPBB->begin();
2423+
assert(
2424+
isa<VPPhi>(CanonicalIV) &&
2425+
match(CanonicalIV->getOperand(1),
2426+
m_c_Binary<Instruction::Add>(m_Specific(cast<VPPhi>(CanonicalIV)),
2427+
m_Specific(&Plan.getVFxUF()))) &&
2428+
"Unexpected canoincal iv");
24242429
VPValue *Backedge = CanonicalIV->getOperand(1);
24252430
Backedge->replaceAllUsesWith(EVLIncrement);
24262431

2427-
// Remove unused phi
2432+
// Remove unused phi and increment.
24282433
VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe();
24292434
CanonicalIVIncrement->eraseFromParent();
24302435
CanonicalIV->eraseFromParent();
24312436

2432-
// Find the latch-exiting block and replace use of VectorTripCount
2437+
// Replace the use of VectorTripCount in the latch-exiting block.
24332438
// Before: (branch-on-count EVLIVInc, VectorTripCount)
24342439
// After: (branch-on-count EVLIVInc, TripCount)
2435-
auto Range =
2436-
VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow(Entry));
2437-
auto It = find_if(Range, [&Entry](VPBasicBlock *VPBB) {
2438-
return any_of(VPBB->successors(),
2439-
[&Entry](VPBlockBase *Succ) { return Succ == Entry; });
2440-
});
2441-
assert((It != Range.end()) && "LatchExiting is not found");
2442-
2443-
VPBasicBlock *LatchExiting = *It;
24442440

2441+
VPBasicBlock *LatchExiting =
2442+
HeaderVPBB->getPredecessors()[1]->getEntryBasicBlock();
24452443
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator());
2446-
24472444
// Skip single-iteration loop region
24482445
if (match(LatchExitingBr, m_BranchOnCond(m_True())))
24492446
return;

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ struct VPlanTransforms {
214214
///
215215
/// Once loop regions are replaced with explicit CFG, EVL loops can step with
216216
/// variable vector lengths instead of fixed lengths. This transformation:
217-
/// * EVL-Phi concretization (makes them concrete)
217+
/// * Make EVL-Phi concrete.
218+
// * Remove CanonicalIV and increment.
218219
/// * Replaces fixed-length stepping (branch-on-cond CanonicalIVInc,
219220
/// VectorTripCount) with variable-length stepping (branch-on-cond
220221
/// EVLIVInc, TripCount).
221-
static void simplifyEVLIVs(VPlan &Plan);
222+
static void canonicalizeEVLLoops(VPlan &Plan);
222223

223224
/// Lower abstract recipes to concrete ones, that can be codegen'd. Use \p
224225
/// CanonicalIVTy as type for all un-typed live-ins in VPTypeAnalysis.

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "VPlanCFG.h"
1818
#include "VPlanDominatorTree.h"
1919
#include "VPlanHelpers.h"
20+
#include "VPlanPatternMatch.h"
2021
#include "llvm/ADT/SmallPtrSet.h"
2122
#include "llvm/ADT/TypeSwitch.h"
2223

@@ -194,8 +195,12 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
194195
return false;
195196
}
196197
// EVLIVIncrement is only used by EVLIV & BranchOnCount.
197-
// More than two is unexpected.
198-
if (I->getNumUsers() > 2) {
198+
// Having more than two users is unexpected.
199+
if ((I->getNumUsers() != 1) &&
200+
(I->getNumUsers() != 2 || !any_of(I->users(), [&I](VPUser *U) {
201+
using namespace llvm::VPlanPatternMatch;
202+
return match(U, m_BranchOnCount(m_Specific(I), m_VPValue()));
203+
}))) {
199204
errs() << "EVL is used in VPInstruction with multiple users\n";
200205
return false;
201206
}

0 commit comments

Comments
 (0)