Skip to content

Commit a524f31

Browse files
committed
Address comments
1 parent 4bd4bf3 commit a524f31

File tree

5 files changed

+29
-26
lines changed

5 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
@@ -7344,8 +7344,8 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73447344
// Regions are dissolved after optimizing for VF and UF, which completely
73457345
// removes unneeded loop regions first.
73467346
VPlanTransforms::dissolveLoopRegions(BestVPlan);
7347-
// Enable variable-length stepping for EVL loops after regions are dissolved
7348-
VPlanTransforms::simplifyEVLIVs(BestVPlan);
7347+
// Canonicalize EVL loops after regions are dissolved.
7348+
VPlanTransforms::canonicalizeEVLLoops(BestVPlan);
73497349
// Perform the actual loop transformation.
73507350
VPTransformState State(&TTI, BestVF, LI, DT, ILV.AC, ILV.Builder, &BestVPlan,
73517351
OrigLoop->getParentLoop(),

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,10 +2357,10 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
23572357
return true;
23582358
}
23592359

2360-
void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2360+
void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) {
23612361
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.
23642364
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr;
23652365

23662366
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
@@ -2371,11 +2371,11 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
23712371
EVLPhi = PhiR;
23722372
}
23732373

2374-
// Early return if no EVL PHI is found
2374+
// Early return if no EVL PHI is found.
23752375
if (!EVLPhi)
23762376
return;
23772377

2378-
VPBasicBlock *Entry = EVLPhi->getParent();
2378+
VPBasicBlock *HeaderVPBB = EVLPhi->getParent();
23792379
VPValue *EVLIncrement = EVLPhi->getBackedgeValue();
23802380

23812381
// Convert EVLPhi to concrete recipe.
@@ -2385,32 +2385,29 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
23852385
EVLPhi->replaceAllUsesWith(ScalarR);
23862386
EVLPhi->eraseFromParent();
23872387

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");
23912396
VPValue *Backedge = CanonicalIV->getOperand(1);
23922397
Backedge->replaceAllUsesWith(EVLIncrement);
23932398

2394-
// Remove unused phi
2399+
// Remove unused phi and increment.
23952400
VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe();
23962401
CanonicalIVIncrement->eraseFromParent();
23972402
CanonicalIV->eraseFromParent();
23982403

2399-
// Find the latch-exiting block and replace use of VectorTripCount
2404+
// Replace the use of VectorTripCount in the latch-exiting block.
24002405
// Before: (branch-on-count EVLIVInc, VectorTripCount)
24012406
// 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;
24112407

2408+
VPBasicBlock *LatchExiting =
2409+
HeaderVPBB->getPredecessors()[1]->getEntryBasicBlock();
24122410
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator());
2413-
24142411
// Skip single-iteration loop region
24152412
if (match(LatchExitingBr, m_BranchOnCond(m_True())))
24162413
return;

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,12 @@ struct VPlanTransforms {
198198
///
199199
/// Once loop regions are replaced with explicit CFG, EVL loops can step with
200200
/// variable vector lengths instead of fixed lengths. This transformation:
201-
/// * EVL-Phi concretization (makes them concrete)
201+
/// * Make EVL-Phi concrete.
202+
// * Remove CanonicalIV and increment.
202203
/// * Replaces fixed-length stepping (branch-on-cond CanonicalIVInc,
203204
/// VectorTripCount) with variable-length stepping (branch-on-cond
204205
/// EVLIVInc, TripCount).
205-
static void simplifyEVLIVs(VPlan &Plan);
206+
static void canonicalizeEVLLoops(VPlan &Plan);
206207

207208
/// Lower abstract recipes to concrete ones, that can be codegen'd. Use \p
208209
/// 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

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

0 commit comments

Comments
 (0)