[llvm] [LoopVectorizer] Add support for partial reductions (PR #92418)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 18 12:40:26 PST 2024
================
@@ -2440,6 +2446,50 @@ 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 {
+ unsigned Opcode;
+
+public:
+ VPPartialReductionRecipe(Instruction *ReductionInst, VPValue *Op0,
+ VPValue *Op1)
+ : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1,
+ ReductionInst) {}
+ VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1,
+ Instruction *ReductionInst = nullptr)
+ : VPSingleDefRecipe(VPDef::VPPartialReductionSC,
+ ArrayRef<VPValue *>({Op0, Op1}), ReductionInst),
+ Opcode(Opcode) {
+ assert(isa<VPReductionPHIRecipe>(getOperand(1)->getDefiningRecipe()) &&
+ "Unexpected operand order for partial reduction recipe");
+ }
+ ~VPPartialReductionRecipe() override = default;
+ VPPartialReductionRecipe *clone() override {
----------------
fhahn wrote:
```suggestion
~VPPartialReductionRecipe() override = default;
VPPartialReductionRecipe *clone() override {
```
https://github.com/llvm/llvm-project/pull/92418
More information about the llvm-commits
mailing list