[llvm] [AArch64] Refactor and refine cost-model for partial reductions (PR #158641)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 07:42:49 PDT 2025


================
@@ -5632,75 +5632,97 @@ InstructionCost AArch64TTIImpl::getPartialReductionCost(
     TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
     TTI::TargetCostKind CostKind) const {
   InstructionCost Invalid = InstructionCost::getInvalid();
-  InstructionCost Cost(TTI::TCC_Basic);
 
   if (CostKind != TTI::TCK_RecipThroughput)
     return Invalid;
 
-  // Sub opcodes currently only occur in chained cases.
-  // Independent partial reduction subtractions are still costed as an add
+  if (VF.isScalable() && !ST->isSVEorStreamingSVEAvailable())
+    return Invalid;
+
+  if (VF.isFixed() && !ST->isSVEorStreamingSVEAvailable() &&
+      (!ST->isNeonAvailable() || !ST->hasDotProd()))
+    return Invalid;
+
   if ((Opcode != Instruction::Add && Opcode != Instruction::Sub) ||
       OpAExtend == TTI::PR_None)
     return Invalid;
 
   // We only support multiply binary operations for now, and for muls we
   // require the types being extended to be the same.
-  // NOTE: For muls AArch64 supports lowering mixed extensions to a usdot but
-  // only if the i8mm or sve/streaming features are available.
-  if (BinOp && (*BinOp != Instruction::Mul || InputTypeA != InputTypeB ||
-                OpBExtend == TTI::PR_None ||
-                (OpAExtend != OpBExtend && !ST->hasMatMulInt8() &&
-                 !ST->isSVEorStreamingSVEAvailable())))
+  if (BinOp && (*BinOp != Instruction::Mul || InputTypeA != InputTypeB))
----------------
david-arm wrote:

Sorry, I didn't do a good job of explaining! The existing assert is for the case where there is no bin op and we want to make sure that there is no info for OpB (because there shouldn't be). What I was trying to say is that when there is a BinOp we must have some information for OpB because the code below relies upon it.

The old code explicitly bailed out if there was a bin op and `OpBExtend == TTI::PR_None`, whereas now the `IsUSDot` code below assumes the caller has set up the arguments sensibly for binary ops.

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


More information about the llvm-commits mailing list