[llvm] Add LoopVectorizer support for `llvm.vector.partial.reduce.fadd` (PR #163975)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 07:34:34 PST 2025


================
@@ -3958,6 +3940,22 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
     Mul->setOperand(1, ExtB);
   };
 
+  // Try to match reduce.add(fmul(...)).
+  if (match(VecOp, m_FMul(m_VPValue(A), m_VPValue(B)))) {
+    auto *RecipeA = dyn_cast_if_present<VPWidenCastRecipe>(A);
+    auto *RecipeB = dyn_cast_if_present<VPWidenCastRecipe>(B);
+    auto *FMul = dyn_cast<VPWidenRecipe>(VecOp);
+
+    // Match reduce.fadd(fmul(ext, ext)).
+    if (FMul && RecipeA && RecipeB && match(RecipeA, m_FPExt(m_VPValue())) &&
+        match(RecipeB, m_FPExt(m_VPValue())) &&
+        IsMulAccValidAndClampRange(FMul, RecipeA, RecipeB, nullptr)) {
+      return new VPExpressionRecipe(RecipeA, RecipeB, FMul, Red);
+    }
+  }
+  if (Opcode == Instruction::FAdd)
----------------
sdesmalen-arm wrote:

Even though the code would already have discarded this, it is possible to have `fsub` reductions (RecurKind::FSub), so maybe just return `nullptr` if the type is not integer type just to be safe.

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


More information about the llvm-commits mailing list