[llvm] [LV] Bundle partial reductions inside VPExpressionRecipe (PR #147302)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 06:39:56 PDT 2025


================
@@ -300,11 +301,11 @@ InstructionCost
 VPPartialReductionRecipe::computeCost(ElementCount VF,
----------------
sdesmalen-arm wrote:

Looking at the change you made to this function, it made me realise that this entirely function can be simplified to:

```
auto *PhiType = Ctx.Types.inferScalarType(getChainOp());
auto *InputType = Ctx.Types.inferScalarType(getVecOp());
return Ctx.TTI.getPartialReductionCost(getOpcode(), InputType, InputType,
                                       PhiType, VF, TTI::PR_None, TTI::PR_None,
                                       {}, Ctx.CostKind);
```

Because there is no need to re-analyse all the expressions again, all this information should have already been expressed by a VPExpression's and its corresponding cost model. (Note that the cost-model for AArch64 will return `Invalid` cost for all the costs if there is no BinOp and no extend, but that's fine, because we wouldn't want to select a partial reduction anyway if there wasn't any type-extension going on)

That being said, using VPExpressions for partial reductions doesn't currently support predicated vector loops, because that introduces another `select` in the loop, which isn't recognised by any of the VPExpressions as of today, so you can put the above suggested code under a `if (!match(Op, m_Select(m_VPValue(), m_VPValue(Op), m_VPValue()))) {}` condition.

It would also be good to add a FIXME to say that that complicated cost-model code here should be removed after fully migrating to VPExpressions.

https://github.com/llvm/llvm-project/pull/147302


More information about the llvm-commits mailing list