[llvm-branch-commits] [llvm] [LV] Only create partial reductions when profitable. (PR #181706)
Sander de Smalen via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 12 06:51:00 PDT 2026
================
@@ -6273,6 +6259,28 @@ void VPlanTransforms::createPartialReductions(VPlan &Plan,
});
};
+ auto IsProfitablePartialReductionChainForVF =
+ [&](ArrayRef<VPPartialReductionChain> Chain, ElementCount VF) -> bool {
+ InstructionCost PartialCost = 0, RegularCost = 0;
+
+ // The chain is a profitable partial reduction chain if
+ // the cost of handling the entire chain is cheaper when
+ // using partial reductions than when handling the entire
+ // chain using regular reductions.
+ for (const VPPartialReductionChain &Link : Chain) {
+ ExtendedReductionOperand ExtendedOp = Link.ExtendedOp;
+ PartialCost += getPartialReductionLinkCost(CostCtx, Link, VF);
+ RegularCost += Link.ReductionBinOp->computeCost(VF, CostCtx);
+ if (ExtendedOp.BinOp && ExtendedOp.BinOp != Link.ReductionBinOp)
+ RegularCost += ExtendedOp.BinOp->computeCost(VF, CostCtx);
+ if (ExtendedOp.CastRecipes[0])
+ RegularCost += ExtendedOp.CastRecipes[0]->computeCost(VF, CostCtx);
+ if (ExtendedOp.CastRecipes[1])
+ RegularCost += ExtendedOp.CastRecipes[1]->computeCost(VF, CostCtx);
+ }
+ return PartialCost.isValid() && PartialCost <= RegularCost;
----------------
sdesmalen-arm wrote:
That was an intentional change, if the cost is equal then a partial reduction would be more profitable because it reduces register pressure.
https://github.com/llvm/llvm-project/pull/181706
More information about the llvm-branch-commits
mailing list