Skip to content

Commit 0698c76

Browse files
committed
[LV] Ignore some costs when loop gets fully unrolled
When VF equals the number of iterations, comparison instruction and induction operation will be DCEed later. Ignoring the costs of these instructions improves the cost model.
1 parent a33ae1b commit 0698c76

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7224,6 +7224,26 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
72247224
continue;
72257225
IVInsts.push_back(CI);
72267226
}
7227+
7228+
// If the given VF loop gets fully unrolled, ignore the costs of comparison
7229+
// and increment instruction, as they'll get simplified away
7230+
auto TC = CM.PSE.getSE()->getSmallConstantTripCount(OrigLoop);
7231+
auto *Cmp = OrigLoop->getLatchCmpInst();
7232+
if (Cmp && VF.isFixed() && VF.getFixedValue() == TC) {
7233+
CostCtx.SkipCostComputation.insert(Cmp);
7234+
for (Instruction *IVInst : IVInsts) {
7235+
bool IsSimplifiedAway = true;
7236+
for (auto *UIV : IVInst->users()) {
7237+
if (!Legal->isInductionVariable(UIV) && UIV != Cmp) {
7238+
IsSimplifiedAway = false;
7239+
break;
7240+
}
7241+
}
7242+
if (IsSimplifiedAway)
7243+
CostCtx.SkipCostComputation.insert(IVInst);
7244+
}
7245+
}
7246+
72277247
for (Instruction *IVInst : IVInsts) {
72287248
if (CostCtx.skipCostComputation(IVInst, VF.isVector()))
72297249
continue;

0 commit comments

Comments
 (0)