Skip to content

Commit 9ea5be6

Browse files
authored
Recommit "[LV][VPlan] Remove any-of reduction from precomputeCost. NFC (#117109)" (#117289)
Update the test cases contains `any-of` printings from the precomputeCost(). Origin message: 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(). Recommit "[LV][VPlan] Remove any-of reduction from precomputeCost. NFC (#117109)"
1 parent d36a4c0 commit 9ea5be6

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
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(),

llvm/test/Transforms/LoopVectorize/AArch64/select-costs.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ for.cond.cleanup: ; preds = %for.cond.cleanup.lo
5050

5151
define i32 @multi_user_cmp(ptr readonly %a, i64 noundef %n) {
5252
; CHECK: LV: Checking a loop in 'multi_user_cmp'
53-
; CHECK: Cost of 1 for VF 16:
54-
; CHECK: any-of reduction %all.off = select i1 %cmp1, i1 %all.off.next, i1 false
55-
; CHECK: Cost of 1 for VF 16:
56-
; CHECK: any-of reduction %.any.0.off0 = select i1 %cmp1, i1 true, i1 %any.0.off09
5753
; CHECK: Cost of 4 for VF 16: WIDEN ir<%cmp1> = fcmp olt ir<%load1>, ir<0.000000e+00>
5854
; CHECK: LV: Selecting VF: 16.
5955
entry:

0 commit comments

Comments
 (0)