Skip to content

Commit 9a5cbbc

Browse files
committed
[WIP][LV] Ignore some costs when loop gets fully unrolled
When fixed-width 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 eaf87d3 commit 9a5cbbc

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
@@ -7112,6 +7112,26 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
71127112
continue;
71137113
IVInsts.push_back(CI);
71147114
}
7115+
7116+
// If the given VF loop gets fully unrolled, ignore the costs of comparison
7117+
// and increment instruction, as they'll get simplified away
7118+
auto TC = CM.PSE.getSE()->getSmallConstantTripCount(OrigLoop);
7119+
auto *Cmp = OrigLoop->getLatchCmpInst();
7120+
if (Cmp && VF.isFixed() && VF.getFixedValue() == TC) {
7121+
CostCtx.SkipCostComputation.insert(Cmp);
7122+
for (Instruction *IVInst : IVInsts) {
7123+
bool IsSimplifiedAway = true;
7124+
for (auto *UIV : IVInst->users()) {
7125+
if (!Legal->isInductionVariable(UIV) && UIV != Cmp) {
7126+
IsSimplifiedAway = false;
7127+
break;
7128+
}
7129+
}
7130+
if (IsSimplifiedAway)
7131+
CostCtx.SkipCostComputation.insert(IVInst);
7132+
}
7133+
}
7134+
71157135
for (Instruction *IVInst : IVInsts) {
71167136
if (CostCtx.skipCostComputation(IVInst, VF.isVector()))
71177137
continue;

0 commit comments

Comments
 (0)