Skip to content

Commit 4eb13cc

Browse files
committed
Update to pass assertion comparing two cost models
1 parent def2ca7 commit 4eb13cc

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5559,14 +5559,28 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
55595559
InstructionCost LoopVectorizationCostModel::expectedCost(ElementCount VF) {
55605560
InstructionCost Cost;
55615561

5562+
// If with the given VF loop gets fully unrolled, ignore the costs of
5563+
// comparison and induction instructions, as they'll get simplified away
5564+
SmallPtrSet<const Value *, 16> ValuesToIgnoreForVF;
5565+
auto TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
5566+
auto *Cmp = TheLoop->getLatchCmpInst();
5567+
if (Cmp && TC == VF.getKnownMinValue()) {
5568+
ValuesToIgnoreForVF.insert(Cmp);
5569+
for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {
5570+
Instruction *IVInc = cast<Instruction>(
5571+
IV->getIncomingValueForBlock(TheLoop->getLoopLatch()));
5572+
ValuesToIgnoreForVF.insert(IVInc);
5573+
}
5574+
}
5575+
55625576
// For each block.
55635577
for (BasicBlock *BB : TheLoop->blocks()) {
55645578
InstructionCost BlockCost;
55655579

55665580
// For each instruction in the old loop.
55675581
for (Instruction &I : BB->instructionsWithoutDebug()) {
55685582
// Skip ignored values.
5569-
if (ValuesToIgnore.count(&I) ||
5583+
if (ValuesToIgnore.count(&I) || ValuesToIgnoreForVF.count(&I) ||
55705584
(VF.isVector() && VecValuesToIgnore.count(&I)))
55715585
continue;
55725586

@@ -7249,22 +7263,16 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
72497263
IVInsts.push_back(CI);
72507264
}
72517265

7252-
// If the given VF loop gets fully unrolled, ignore the costs of comparison
7253-
// and increment instruction, as they'll get simplified away
7266+
// If with the given VF loop gets fully unrolled, ignore the costs of
7267+
// comparison and induction instructions, as they'll get simplified away
72547268
auto TC = CM.PSE.getSE()->getSmallConstantTripCount(OrigLoop);
72557269
auto *Cmp = OrigLoop->getLatchCmpInst();
7256-
if (Cmp && VF.isFixed() && VF.getFixedValue() == TC) {
7270+
if (Cmp && TC == VF.getKnownMinValue()) {
72577271
CostCtx.SkipCostComputation.insert(Cmp);
7258-
for (Instruction *IVInst : IVInsts) {
7259-
bool IsSimplifiedAway = true;
7260-
for (auto *UIV : IVInst->users()) {
7261-
if (!Legal->isInductionVariable(UIV) && UIV != Cmp) {
7262-
IsSimplifiedAway = false;
7263-
break;
7264-
}
7265-
}
7266-
if (IsSimplifiedAway)
7267-
CostCtx.SkipCostComputation.insert(IVInst);
7272+
for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {
7273+
Instruction *IVInc = cast<Instruction>(
7274+
IV->getIncomingValueForBlock(OrigLoop->getLoopLatch()));
7275+
CostCtx.SkipCostComputation.insert(IVInc);
72687276
}
72697277
}
72707278

0 commit comments

Comments
 (0)