Skip to content

Commit daf3236

Browse files
committed
[VPlan] Move scalarizeInstruction out of ILV (NFC).
15bb1db removed the last dependency on ILV, move the code out of ILV in preparation of consolidating in VPlanRecipes.cpp.
1 parent 9e9c9c4 commit daf3236

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,6 @@ class InnerLoopVectorizer {
508508
// Return true if any runtime check is added.
509509
bool areSafetyChecksAdded() { return AddedSafetyChecks; }
510510

511-
/// A helper function to scalarize a single Instruction in the innermost loop.
512-
/// Generates a sequence of scalar instances for each lane between \p MinLane
513-
/// and \p MaxLane, times each part between \p MinPart and \p MaxPart,
514-
/// inclusive. Uses the VPValue operands from \p RepRecipe instead of \p
515-
/// Instr's operands.
516-
void scalarizeInstruction(const Instruction *Instr,
517-
VPReplicateRecipe *RepRecipe, const VPLane &Lane,
518-
VPTransformState &State);
519-
520511
/// Fix the non-induction PHIs in \p Plan.
521512
void fixNonInductionPHIs(VPTransformState &State);
522513

@@ -2321,10 +2312,12 @@ static bool useMaskedInterleavedAccesses(const TargetTransformInfo &TTI) {
23212312
return TTI.enableMaskedInterleavedAccessVectorization();
23222313
}
23232314

2324-
void InnerLoopVectorizer::scalarizeInstruction(const Instruction *Instr,
2325-
VPReplicateRecipe *RepRecipe,
2326-
const VPLane &Lane,
2327-
VPTransformState &State) {
2315+
/// A helper function to scalarize a single Instruction in the innermost loop.
2316+
/// Generates a sequence of scalar instances for lane \p Lane. Uses the VPValue
2317+
/// operands from \p RepRecipe instead of \p Instr's operands.
2318+
static void scalarizeInstruction(const Instruction *Instr,
2319+
VPReplicateRecipe *RepRecipe,
2320+
const VPLane &Lane, VPTransformState &State) {
23282321
assert((!Instr->getType()->isAggregateType() ||
23292322
canVectorizeTy(Instr->getType())) &&
23302323
"Expected vectorizable or non-aggregate type.");
@@ -2366,7 +2359,7 @@ void InnerLoopVectorizer::scalarizeInstruction(const Instruction *Instr,
23662359

23672360
// If we just cloned a new assumption, add it the assumption cache.
23682361
if (auto *II = dyn_cast<AssumeInst>(Cloned))
2369-
AC->registerAssumption(II);
2362+
State.AC->registerAssumption(II);
23702363

23712364
assert(
23722365
(RepRecipe->getParent()->getParent() ||
@@ -7863,7 +7856,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
78637856
*Legal->getWidestInductionType());
78647857

78657858
// Perform the actual loop transformation.
7866-
VPTransformState State(&TTI, BestVF, LI, DT, ILV.Builder, &ILV, &BestVPlan,
7859+
VPTransformState State(&TTI, BestVF, LI, DT, ILV.AC, ILV.Builder, &BestVPlan,
78677860
OrigLoop->getParentLoop(),
78687861
Legal->getWidestInductionType());
78697862

@@ -10094,7 +10087,7 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
1009410087
assert((State.VF.isScalar() || !isUniform()) &&
1009510088
"uniform recipe shouldn't be predicated");
1009610089
assert(!State.VF.isScalable() && "Can't scalarize a scalable vector");
10097-
State.ILV->scalarizeInstruction(UI, this, *State.Lane, State);
10090+
scalarizeInstruction(UI, this, *State.Lane, State);
1009810091
// Insert scalar instance packing it into a vector.
1009910092
if (State.VF.isVector() && shouldPack()) {
1010010093
// If we're constructing lane 0, initialize to start from poison.
@@ -10111,7 +10104,7 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
1011110104

1011210105
if (IsUniform) {
1011310106
// Uniform within VL means we need to generate lane 0.
10114-
State.ILV->scalarizeInstruction(UI, this, VPLane(0), State);
10107+
scalarizeInstruction(UI, this, VPLane(0), State);
1011510108
return;
1011610109
}
1011710110

@@ -10120,15 +10113,15 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
1012010113
if (isa<StoreInst>(UI) &&
1012110114
vputils::isUniformAfterVectorization(getOperand(1))) {
1012210115
auto Lane = VPLane::getLastLaneForVF(State.VF);
10123-
State.ILV->scalarizeInstruction(UI, this, VPLane(Lane), State);
10116+
scalarizeInstruction(UI, this, VPLane(Lane), State);
1012410117
return;
1012510118
}
1012610119

1012710120
// Generate scalar instances for all VF lanes.
1012810121
assert(!State.VF.isScalable() && "Can't scalarize a scalable vector");
1012910122
const unsigned EndLane = State.VF.getKnownMinValue();
1013010123
for (unsigned Lane = 0; Lane < EndLane; ++Lane)
10131-
State.ILV->scalarizeInstruction(UI, this, VPLane(Lane), State);
10124+
scalarizeInstruction(UI, this, VPLane(Lane), State);
1013210125
}
1013310126

1013410127
// Determine how to lower the scalar epilogue, which depends on 1) optimising

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ VPBasicBlock::iterator VPBasicBlock::getFirstNonPhi() {
216216

217217
VPTransformState::VPTransformState(const TargetTransformInfo *TTI,
218218
ElementCount VF, LoopInfo *LI,
219-
DominatorTree *DT, IRBuilderBase &Builder,
220-
InnerLoopVectorizer *ILV, VPlan *Plan,
219+
DominatorTree *DT, AssumptionCache *AC,
220+
IRBuilderBase &Builder, VPlan *Plan,
221221
Loop *CurrentParentLoop, Type *CanonicalIVTy)
222-
: TTI(TTI), VF(VF), CFG(DT), LI(LI), Builder(Builder), ILV(ILV), Plan(Plan),
222+
: TTI(TTI), VF(VF), CFG(DT), LI(LI), AC(AC), Builder(Builder), Plan(Plan),
223223
CurrentParentLoop(CurrentParentLoop), LVer(nullptr),
224224
TypeAnalysis(CanonicalIVTy), VPDT(*Plan) {}
225225

llvm/lib/Transforms/Vectorize/VPlanHelpers.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
namespace llvm {
2929

30+
class AssumptionCache;
3031
class BasicBlock;
3132
class DominatorTree;
3233
class InnerLoopVectorizer;
@@ -203,9 +204,9 @@ class VPLane {
203204
/// needed for generating the output IR.
204205
struct VPTransformState {
205206
VPTransformState(const TargetTransformInfo *TTI, ElementCount VF,
206-
LoopInfo *LI, DominatorTree *DT, IRBuilderBase &Builder,
207-
InnerLoopVectorizer *ILV, VPlan *Plan,
208-
Loop *CurrentParentLoop, Type *CanonicalIVTy);
207+
LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC,
208+
IRBuilderBase &Builder, VPlan *Plan, Loop *CurrentParentLoop,
209+
Type *CanonicalIVTy);
209210
/// Target Transform Info.
210211
const TargetTransformInfo *TTI;
211212

@@ -329,12 +330,13 @@ struct VPTransformState {
329330
/// Hold a pointer to LoopInfo to register new basic blocks in the loop.
330331
LoopInfo *LI;
331332

333+
/// Hold a pointer to AssumptionCache to register new assumptions after
334+
/// replicating assume calls.
335+
AssumptionCache *AC;
336+
332337
/// Hold a reference to the IRBuilder used to generate output IR code.
333338
IRBuilderBase &Builder;
334339

335-
/// Hold a pointer to InnerLoopVectorizer to reuse its IR generation methods.
336-
InnerLoopVectorizer *ILV;
337-
338340
/// Pointer to the VPlan code is generated for.
339341
VPlan *Plan;
340342

0 commit comments

Comments
 (0)