[llvm] [PowerPC] Add PPC cost model support for partial reductions (PR #214760)
Lei Huang via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 07:13:05 PDT 2026
================
@@ -1160,3 +1160,40 @@ PPCTTIImpl::getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA,
Cost += 1; // need shift for length
return Cost;
}
+
+InstructionCost PPCTTIImpl::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 {
+ InstructionCost Invalid = InstructionCost::getInvalid();
+
+ if (Opcode != Instruction::Add)
+ return Invalid;
+ if (BinOp && BinOp.value() != Instruction::Mul)
+ return Invalid;
+
+ EVT AccVT = TLI->getValueType(DL, AccumType, true);
+ if (AccVT != MVT::i32)
+ return Invalid;
+ if (InputTypeA != InputTypeB)
+ return Invalid;
+
+ Type *ATy = VectorType::get(InputTypeA, VF);
+ EVT AVT = TLI->getValueType(DL, ATy, true);
+ if (AVT != MVT::v16i8 && AVT != MVT::v8i16)
+ return Invalid;
+
+ // For v16i8 PPC has vmsumubm zext/zext and vmsummbm sext/zext
+ // For v8i16 PPC has vmsumuhm zext/zext and vmsumshm sext/sext
+ if (OpAExtend != TTI::PR_SignExtend && OpAExtend != TTI::PR_ZeroExtend)
+ return Invalid;
+ if (OpAExtend != OpBExtend) {
+ if (AVT != MVT::v16i8 || OpBExtend != TTI::PR_ZeroExtend)
+ return Invalid;
+ } else if (AVT == MVT::v16i8 && OpAExtend == TTI::PR_SignExtend) {
+ return Invalid;
+ }
----------------
lei137 wrote:
I found this a bit hard to parse initially. Maybe something a bit longer/verbose will make it easier to read?
```
// Ensure both operands are extended (zext or sext).
if ((OpAExtend != TTI::PR_SignExtend && OpAExtend != TTI::PR_ZeroExtend) ||
(OpBExtend != TTI::PR_SignExtend && OpBExtend != TTI::PR_ZeroExtend))
return Invalid;
// For v16i8, PPC supports vmsumubm (zext/zext) and vmsummbm (sext/zext).
// For v8i16, PPC supports vmsumuhm (zext/zext) and vmsumshm (sext/sext).
if (AVT == MVT::v16i8) {
if (OpBExtend != TTI::PR_ZeroExtend)
return Invalid;
} else if (AVT == MVT::v8i16) {
if (OpAExtend != OpBExtend)
return Invalid;
}
```
https://github.com/llvm/llvm-project/pull/214760
More information about the llvm-commits
mailing list