[llvm] [AArch64] Fold four and eight way partial reductions with [SU]ADDLP (PR #214636)

Adam Scott via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 07:25:17 PDT 2026


================
@@ -13984,6 +13984,51 @@ SDValue TargetLowering::expandPartialReduceMLA(SDNode *N,
     break;
   }
 
+  // A wide partial reduction is built from a ladder of narrower ones, a rung
+  // at a time, each halving the element count and doubling the width.
+  unsigned Opc = N->getOpcode();
+  ElementCount MulEC = MulOpVT.getVectorElementCount();
+  ElementCount AccEC = AccVT.getVectorElementCount();
+  unsigned CountRatio =
+      MulEC.hasKnownScalarFactor(AccEC) ? MulEC.getKnownScalarFactor(AccEC) : 0;
+  unsigned WidthRatio =
+      AccVT.getScalarSizeInBits() / MulOpVT.getScalarSizeInBits();
+  if (Opc != ISD::PARTIAL_REDUCE_FMLA && CountRatio > 2 &&
+      2 * WidthRatio >= CountRatio) {
----------------
as4230 wrote:

That makes sense. Your condition asks whether the next rung is valid and mine is trying to prove every rung up front, and since each rung re-enters and re-checks that isn't needed. I will replace it with your suggestion. 

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


More information about the llvm-commits mailing list