Skip to content

Commit 777c320

Browse files
committed
[VPlan] Address comments missed in #142309.
Address additional comments from #142309.
1 parent 9b7b382 commit 777c320

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10321,8 +10321,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1032110321

1032210322
// TODO: Move to general VPlan pipeline once epilogue loops are also
1032310323
// supported.
10324-
VPlanTransforms::runPass(VPlanTransforms::materializeVectorTripCount,
10325-
BestPlan, VF.Width, IC, PSE);
10324+
VPlanTransforms::runPass(
10325+
VPlanTransforms::materializeConstantVectorTripCount, BestPlan,
10326+
VF.Width, IC, PSE);
1032610327

1032710328
LVP.executePlan(VF.Width, IC, BestPlan, Unroller, DT, false);
1032810329

@@ -10393,8 +10394,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1039310394
Checks, BestPlan);
1039410395
// TODO: Move to general VPlan pipeline once epilogue loops are also
1039510396
// supported.
10396-
VPlanTransforms::runPass(VPlanTransforms::materializeVectorTripCount,
10397-
BestPlan, VF.Width, IC, PSE);
10397+
VPlanTransforms::runPass(
10398+
VPlanTransforms::materializeConstantVectorTripCount, BestPlan,
10399+
VF.Width, IC, PSE);
1039810400

1039910401
LVP.executePlan(VF.Width, IC, BestPlan, LB, DT, false);
1040010402
++LoopsVectorized;

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,27 +3222,34 @@ void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
32223222
}
32233223
}
32243224

3225-
void VPlanTransforms::materializeVectorTripCount(
3225+
void VPlanTransforms::materializeConstantVectorTripCount(
32263226
VPlan &Plan, ElementCount BestVF, unsigned BestUF,
32273227
PredicatedScalarEvolution &PSE) {
32283228
assert(Plan.hasVF(BestVF) && "BestVF is not available in Plan");
32293229
assert(Plan.hasUF(BestUF) && "BestUF is not available in Plan");
32303230

32313231
VPValue *TC = Plan.getTripCount();
32323232
// Skip cases for which the trip count may be non-trivial to materialize.
3233+
// I.e., when a scalar tail is absent - due to tail folding, or when a scalar
3234+
// tail is required.
32333235
if (!Plan.hasScalarTail() ||
32343236
Plan.getMiddleBlock()->getSingleSuccessor() ==
32353237
Plan.getScalarPreheader() ||
32363238
!TC->isLiveIn())
32373239
return;
3240+
32383241
// Materialize vector trip counts for constants early if it can simply
32393242
// be computed as (Original TC / VF * UF) * VF * UF.
3243+
// TODO: Compute vector trip counts for loops requiring a scalar epilogue and
3244+
// tail-folded loops.
32403245
ScalarEvolution &SE = *PSE.getSE();
32413246
auto *TCScev = SE.getSCEV(TC->getLiveInIRValue());
3247+
if (!isa<SCEVConstant>(TCScev))
3248+
return;
32423249
const SCEV *VFxUF = SE.getElementCount(TCScev->getType(), BestVF * BestUF);
32433250
auto VecTCScev = SE.getMulExpr(SE.getUDivExpr(TCScev, VFxUF), VFxUF);
3244-
if (auto *NewC = dyn_cast<SCEVConstant>(VecTCScev))
3245-
Plan.getVectorTripCount().setUnderlyingValue(NewC->getValue());
3251+
if (auto *ConstVecTC = dyn_cast<SCEVConstant>(VecTCScev))
3252+
Plan.getVectorTripCount().setUnderlyingValue(ConstVecTC->getValue());
32463253
}
32473254

32483255
void VPlanTransforms::materializeBackedgeTakenCount(VPlan &Plan,

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ struct VPlanTransforms {
252252

253253
// Materialize vector trip counts for constants early if it can simply be
254254
// computed as (Original TC / VF * UF) * VF * UF.
255-
static void materializeVectorTripCount(VPlan &Plan, ElementCount BestVF,
256-
unsigned BestUF,
257-
PredicatedScalarEvolution &PSE);
255+
static void
256+
materializeConstantVectorTripCount(VPlan &Plan, ElementCount BestVF,
257+
unsigned BestUF,
258+
PredicatedScalarEvolution &PSE);
258259

259260
/// Materialize the backedge-taken count to be computed explicitly using
260261
/// VPInstructions.

0 commit comments

Comments
 (0)