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

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 07:59:44 PST 2025


================
@@ -3898,6 +3904,24 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
   VPRecipeBase *Sub = nullptr;
   VPValue *A, *B;
   VPValue *Tmp = nullptr;
+
+  // Try to match reduce.fadd(fmul(...)).
+  if (match(VecOp, m_FMul(m_VPValue(A), m_VPValue(B)))) {
+    assert(Opcode == Instruction::FAdd);
+    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 (Ctx.Types.inferScalarType(VecOp)->isFloatingPointTy())
----------------
MacDue wrote:

very nit: Can this be?
```suggestion
  if (RedTy->isFloatingPointTy())
```

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


More information about the llvm-commits mailing list