[llvm] [VPlan] Impl VPlan-based pattern match for ExtendedRed and MulAccRed (NFCI) (PR #113903)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 24 10:58:02 PST 2024


================
@@ -2702,6 +2785,212 @@ class VPReductionEVLRecipe : public VPReductionRecipe {
   }
 };
 
+/// A recipe to represent inloop extended reduction operations, performing a
+/// reduction on a extended vector operand into a scalar value, and adding the
+/// result to a chain. This recipe is abstract and needs to be lowered to
+/// concrete recipes before codegen. The Operands are {ChainOp, VecOp,
+/// [Condition]}.
+class VPExtendedReductionRecipe : public VPReductionRecipe {
+  /// Opcode of the extend recipe will be lowered to.
+  Instruction::CastOps ExtOp;
+  /// Debug location of reduction recipe will be lowered to.
+  DebugLoc RedDL;
+
+public:
+  VPExtendedReductionRecipe(const RecurrenceDescriptor &R, Instruction *RedI,
+                            VPValue *ChainOp, VPWidenCastRecipe *Ext,
+                            VPValue *CondOp, bool IsOrdered)
+      : VPReductionRecipe(VPDef::VPExtendedReductionSC, R,
+                          ArrayRef<VPValue *>({ChainOp, Ext->getOperand(0)}),
+                          CondOp, IsOrdered, Ext->isNonNeg(),
+                          Ext->getDebugLoc()),
+        ExtOp(Ext->getOpcode()), RedDL(RedI->getDebugLoc()) {}
+
+  /// Contructor for cloning VPExtendedReductionRecipe.
+  VPExtendedReductionRecipe(VPExtendedReductionRecipe *ExtRed)
+      : VPReductionRecipe(
+            VPDef::VPExtendedReductionSC, ExtRed->getRecurrenceDescriptor(),
+            ArrayRef<VPValue *>({ExtRed->getChainOp(), ExtRed->getVecOp()}),
+            ExtRed->getCondOp(), ExtRed->isOrdered(), ExtRed->isNonNeg(),
+            ExtRed->getExtDebugLoc()),
+        ExtOp(ExtRed->getExtOpcode()), RedDL(ExtRed->getRedDebugLoc()) {}
+
+  ~VPExtendedReductionRecipe() override = default;
+
+  VPExtendedReductionRecipe *clone() override {
+    return new VPExtendedReductionRecipe(this);
+  }
+
+  VP_CLASSOF_IMPL(VPDef::VPExtendedReductionSC);
+
+  void execute(VPTransformState &State) override {
+    llvm_unreachable("VPExtendedReductionRecipe should be transform to "
+                     "VPExtendedRecipe + VPReductionRecipe before execution.");
+  };
+
+  /// Return the cost of VPExtendedReductionRecipe.
+  InstructionCost computeCost(ElementCount VF,
+                              VPCostContext &Ctx) const override;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  /// Print the recipe.
+  void print(raw_ostream &O, const Twine &Indent,
+             VPSlotTracker &SlotTracker) const override;
+#endif
+
+  /// The scalar type after extended.
+  Type *getResultType() const {
+    return getRecurrenceDescriptor().getRecurrenceType();
+  }
+
+  bool isZExt() const { return getExtOpcode() == Instruction::ZExt; }
+
+  /// The Opcode of extend instruction.
+  Instruction::CastOps getExtOpcode() const { return ExtOp; }
+
+  /// Return the debug location of the extend instruction.
+  DebugLoc getExtDebugLoc() const { return getDebugLoc(); }
+
+  /// Return the debug location of the reduction instruction.
+  DebugLoc getRedDebugLoc() const { return RedDL; }
+};
+
+/// A recipe to represent inloop MulAccumulateReduction operations, performing a
+/// reduction.add on the result of vector operands (might be extended)
+/// multiplication into a scalar value, and adding the result to a chain. This
+/// recipe is abstract and needs to be lowered to concrete recipes before
+/// codegen. The Operands are {ChainOp, VecOp1, VecOp2, [Condition]}.
+class VPMulAccumulateReductionRecipe : public VPReductionRecipe {
+  /// Opcode of the extend recipe.
+  Instruction::CastOps ExtOp;
+
+  /// Non-neg flag of the extend recipe.
+  bool IsNonNeg;
----------------
alexey-bataev wrote:

```suggestion
  bool IsNonNeg = false;
```


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


More information about the llvm-commits mailing list