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

Nicholas Guy via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 19 09:26:52 PST 2024


================
@@ -2374,6 +2380,43 @@ 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 VPRecipeWithIRFlags {
+  unsigned Opcode;
+
+public:
+  template <typename IterT>
+  VPPartialReductionRecipe(unsigned ReductionOpcode,
+                           iterator_range<IterT> Operands)
+      : VPRecipeWithIRFlags(VPDef::VPPartialReductionSC, Operands),
+        Opcode(ReductionOpcode) {
----------------
NickGuy-Arm wrote:

Could we use one of the `VPRecipeWithIRFlags` constructors that set `UnderlyingVal`?

```suggestion
    VPPartialReductionRecipe(Instruction &ReductionInst, iterator_range<IterT> Operands)
      : VPRecipeWithIRFlags(VPDef::VPPartialReductionSC, Operands, ReductionInst), Opcode(ReductionInst.getOpcode())
```

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


More information about the llvm-commits mailing list