Skip to content

Commit 151f339

Browse files
committed
Address comments
1 parent 1bc6c5d commit 151f339

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
@@ -7292,8 +7292,8 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
72927292
// Regions are dissolved after optimizing for VF and UF, which completely
72937293
// removes unneeded loop regions first.
72947294
VPlanTransforms::dissolveLoopRegions(BestVPlan);
7295-
// Enable variable-length stepping for EVL loops after regions are dissolved
7296-
VPlanTransforms::simplifyEVLIVs(BestVPlan);
7295+
// Canonicalize EVL loops after regions are dissolved.
7296+
VPlanTransforms::canonicalizeEVLLoops(BestVPlan);
72977297
// Perform the actual loop transformation.
72987298
VPTransformState State(&TTI, BestVF, LI, DT, ILV.AC, ILV.Builder, &BestVPlan,
72997299
OrigLoop->getParentLoop(),

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,10 +2373,10 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
23732373
return true;
23742374
}
23752375

2376-
void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
2376+
void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) {
23772377
using namespace llvm::VPlanPatternMatch;
2378-
// Find EVL loop entries by locating VPEVLBasedIVPHIRecipe
2379-
// There should be only one EVL PHI in the entire plan
2378+
// Find EVL loop entries by locating VPEVLBasedIVPHIRecipe.
2379+
// There should be only one EVL PHI in the entire plan.
23802380
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr;
23812381

23822382
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
@@ -2387,11 +2387,11 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
23872387
EVLPhi = PhiR;
23882388
}
23892389

2390-
// Early return if no EVL PHI is found
2390+
// Early return if no EVL PHI is found.
23912391
if (!EVLPhi)
23922392
return;
23932393

2394-
VPBasicBlock *Entry = EVLPhi->getParent();
2394+
VPBasicBlock *HeaderVPBB = EVLPhi->getParent();
23952395
VPValue *EVLIncrement = EVLPhi->getBackedgeValue();
23962396

23972397
// Convert EVLPhi to concrete recipe.
@@ -2401,32 +2401,29 @@ void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
24012401
EVLPhi->replaceAllUsesWith(ScalarR);
24022402
EVLPhi->eraseFromParent();
24032403

2404-
// Replace CanonicalIVInc with EVL-PHI increment
2405-
VPRecipeBase *CanonicalIV = &*Entry->begin();
2406-
assert(dyn_cast<VPPhi>(CanonicalIV) && "Unexpected canoincal iv");
2404+
// Replace CanonicalIVInc with EVL-PHI increment.
2405+
VPRecipeBase *CanonicalIV = &*HeaderVPBB->begin();
2406+
assert(
2407+
isa<VPPhi>(CanonicalIV) &&
2408+
match(CanonicalIV->getOperand(1),
2409+
m_c_Binary<Instruction::Add>(m_Specific(cast<VPPhi>(CanonicalIV)),
2410+
m_Specific(&Plan.getVFxUF()))) &&
2411+
"Unexpected canoincal iv");
24072412
VPValue *Backedge = CanonicalIV->getOperand(1);
24082413
Backedge->replaceAllUsesWith(EVLIncrement);
24092414

2410-
// Remove unused phi
2415+
// Remove unused phi and increment.
24112416
VPRecipeBase *CanonicalIVIncrement = Backedge->getDefiningRecipe();
24122417
CanonicalIVIncrement->eraseFromParent();
24132418
CanonicalIV->eraseFromParent();
24142419

2415-
// Find the latch-exiting block and replace use of VectorTripCount
2420+
// Replace the use of VectorTripCount in the latch-exiting block.
24162421
// Before: (branch-on-count EVLIVInc, VectorTripCount)
24172422
// After: (branch-on-count EVLIVInc, TripCount)
2418-
auto Range =
2419-
VPBlockUtils::blocksOnly<VPBasicBlock>(vp_depth_first_shallow(Entry));
2420-
auto It = find_if(Range, [&Entry](VPBasicBlock *VPBB) {
2421-
return any_of(VPBB->successors(),
2422-
[&Entry](VPBlockBase *Succ) { return Succ == Entry; });
2423-
});
2424-
assert((It != Range.end()) && "LatchExiting is not found");
2425-
2426-
VPBasicBlock *LatchExiting = *It;
24272423

2424+
VPBasicBlock *LatchExiting =
2425+
HeaderVPBB->getPredecessors()[1]->getEntryBasicBlock();
24282426
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator());
2429-
24302427
// Skip single-iteration loop region
24312428
if (match(LatchExitingBr, m_BranchOnCond(m_True())))
24322429
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

@@ -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)