Skip to content

Commit ce66b56

Browse files
authored
[LV][VPlan] Remove any-of reduction from precomputeCost. NFC (#117109)
The any-of reduction contains phi and select instructions. The select instruction might be optimized and removed in the vplan which may cause VF difference between legacy and VPlan-based model. But if the select instruction be removed, `planContainsAdditionalSimplifications()` will catch it and disable the assertion. Therefore, we can just remove the ayn-of reduction calculation in the precomputeCost().
1 parent 6b22e39 commit ce66b56

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7303,34 +7303,14 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
73037303

73047304
// The legacy cost model has special logic to compute the cost of in-loop
73057305
// reductions, which may be smaller than the sum of all instructions involved
7306-
// in the reduction. For AnyOf reductions, VPlan codegen may remove the select
7307-
// which the legacy cost model uses to assign cost. Pre-compute their costs
7308-
// for now.
7306+
// in the reduction.
73097307
// TODO: Switch to costing based on VPlan once the logic has been ported.
73107308
for (const auto &[RedPhi, RdxDesc] : Legal->getReductionVars()) {
73117309
if (ForceTargetInstructionCost.getNumOccurrences())
73127310
continue;
73137311

7314-
if (!CM.isInLoopReduction(RedPhi) &&
7315-
!RecurrenceDescriptor::isAnyOfRecurrenceKind(
7316-
RdxDesc.getRecurrenceKind()))
7317-
continue;
7318-
7319-
// AnyOf reduction codegen may remove the select. To match the legacy cost
7320-
// model, pre-compute the cost for AnyOf reductions here.
7321-
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
7322-
RdxDesc.getRecurrenceKind())) {
7323-
auto *Select = cast<SelectInst>(*find_if(
7324-
RedPhi->users(), [](User *U) { return isa<SelectInst>(U); }));
7325-
assert(!CostCtx.SkipCostComputation.contains(Select) &&
7326-
"reduction op visited multiple times");
7327-
CostCtx.SkipCostComputation.insert(Select);
7328-
auto ReductionCost = CostCtx.getLegacyCost(Select, VF);
7329-
LLVM_DEBUG(dbgs() << "Cost of " << ReductionCost << " for VF " << VF
7330-
<< ":\n any-of reduction " << *Select << "\n");
7331-
Cost += ReductionCost;
7312+
if (!CM.isInLoopReduction(RedPhi))
73327313
continue;
7333-
}
73347314

73357315
const auto &ChainOps = RdxDesc.getReductionOpChain(RedPhi, OrigLoop);
73367316
SetVector<Instruction *> ChainOpsAndOperands(ChainOps.begin(),

0 commit comments

Comments
 (0)