[llvm] [CostModel] Move default expand cost for partial reductions to BasicTTIImpl (PR #189905)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 01:14:53 PDT 2026
================
@@ -3435,6 +3435,47 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
return RedCost + MulCost + 2 * ExtCost;
}
+ InstructionCost getPartialReductionCost(
+ unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
+ ElementCount VF, TTI::PartialReductionExtendKind OpAExtend,
+ TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
+ TTI::TargetCostKind CostKind,
+ std::optional<FastMathFlags> FMF) const override {
+ unsigned Ratio =
+ AccumType->getScalarSizeInBits() / InputTypeA->getScalarSizeInBits();
+ if (VF.getKnownMinValue() <= Ratio)
+ return InstructionCost::getInvalid();
+
+ Type *InputVectorType = VectorType::get(InputTypeA, VF);
+ Type *ExtInputVectorType = VectorType::get(AccumType, VF);
+ Type *AccumVectorType =
+ VectorType::get(AccumType, VF.divideCoefficientBy(Ratio));
----------------
sdesmalen-arm wrote:
On your comment: "(1) if `AccumType` is narrower than `InputTypeA`, integer division yields `Ratio == 0`, which will later be used in `VF.divideCoeffcientBy(Ratio) (division by zero)"
This should be caught by `if (VF.getKnownMinValue() <= Ratio)`, because if Ratio is `0` there is no value for `VF.getKnownMinValue()` (which is an unsigned value) for which this function does not return `InstructionCost::getInvalid()`.
https://github.com/llvm/llvm-project/pull/189905
More information about the llvm-commits
mailing list