[llvm] [LoopVectorizer] Add support for partial reductions (PR #92418)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 6 06:25:03 PST 2024


================
@@ -2374,6 +2380,42 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
   bool isInLoop() const { return IsInLoop; }
 };
 
+/// A recipe for forming partial reductions. In the loop, an accumulator and
+/// vector operand are added together and passed to the next iteration as the
+/// next accumulator. After the loop body, the accumulator is reduced to a
+/// scalar value.
+class VPPartialReductionRecipe : public VPSingleDefRecipe {
+
+public:
+  template <typename IterT>
+  VPPartialReductionRecipe(Instruction *ReductionInst,
+                           iterator_range<IterT> Operands)
+      : VPSingleDefRecipe(VPDef::VPPartialReductionSC, Operands,
----------------
fhahn wrote:

```suggestion
-  template <typename IterT>
   VPPartialReductionRecipe(Instruction *ReductionInst,
-                           iterator_range<IterT> Operands)
-      : VPSingleDefRecipe(VPDef::VPPartialReductionSC, Operands,
+                           VPValue *Op0, VPValue *Op1)
+      : VPSingleDefRecipe(VPDef::VPPartialReductionSC, ArrayRef<VPValue *>({Op0, Op1}),
```

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


More information about the llvm-commits mailing list