Skip to content

Commit 22528ca

Browse files
committed
Update to pass assertion comparing two cost models
1 parent d7a1335 commit 22528ca

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
@@ -5592,14 +5592,28 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
55925592
InstructionCost LoopVectorizationCostModel::expectedCost(ElementCount VF) {
55935593
InstructionCost Cost;
55945594

5595+
// If with the given VF loop gets fully unrolled, ignore the costs of
5596+
// comparison and induction instructions, as they'll get simplified away
5597+
SmallPtrSet<const Value *, 16> ValuesToIgnoreForVF;
5598+
auto TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
5599+
auto *Cmp = TheLoop->getLatchCmpInst();
5600+
if (Cmp && TC == VF.getKnownMinValue()) {
5601+
ValuesToIgnoreForVF.insert(Cmp);
5602+
for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {
5603+
Instruction *IVInc = cast<Instruction>(
5604+
IV->getIncomingValueForBlock(TheLoop->getLoopLatch()));
5605+
ValuesToIgnoreForVF.insert(IVInc);
5606+
}
5607+
}
5608+
55955609
// For each block.
55965610
for (BasicBlock *BB : TheLoop->blocks()) {
55975611
InstructionCost BlockCost;
55985612

55995613
// For each instruction in the old loop.
56005614
for (Instruction &I : BB->instructionsWithoutDebug()) {
56015615
// Skip ignored values.
5602-
if (ValuesToIgnore.count(&I) ||
5616+
if (ValuesToIgnore.count(&I) || ValuesToIgnoreForVF.count(&I) ||
56035617
(VF.isVector() && VecValuesToIgnore.count(&I)))
56045618
continue;
56055619

@@ -7282,22 +7296,16 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
72827296
IVInsts.push_back(CI);
72837297
}
72847298

7285-
// If the given VF loop gets fully unrolled, ignore the costs of comparison
7286-
// and increment instruction, as they'll get simplified away
7299+
// If with the given VF loop gets fully unrolled, ignore the costs of
7300+
// comparison and induction instructions, as they'll get simplified away
72877301
auto TC = CM.PSE.getSE()->getSmallConstantTripCount(OrigLoop);
72887302
auto *Cmp = OrigLoop->getLatchCmpInst();
7289-
if (Cmp && VF.isFixed() && VF.getFixedValue() == TC) {
7303+
if (Cmp && TC == VF.getKnownMinValue()) {
72907304
CostCtx.SkipCostComputation.insert(Cmp);
7291-
for (Instruction *IVInst : IVInsts) {
7292-
bool IsSimplifiedAway = true;
7293-
for (auto *UIV : IVInst->users()) {
7294-
if (!Legal->isInductionVariable(UIV) && UIV != Cmp) {
7295-
IsSimplifiedAway = false;
7296-
break;
7297-
}
7298-
}
7299-
if (IsSimplifiedAway)
7300-
CostCtx.SkipCostComputation.insert(IVInst);
7305+
for (const auto &[IV, IndDesc] : Legal->getInductionVars()) {
7306+
Instruction *IVInc = cast<Instruction>(
7307+
IV->getIncomingValueForBlock(OrigLoop->getLoopLatch()));
7308+
CostCtx.SkipCostComputation.insert(IVInc);
73017309
}
73027310
}
73037311

0 commit comments

Comments
 (0)