@@ -2133,62 +2133,6 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
21332133 }
21342134};
21352135
2136- // / A recipe for forming partial reductions. In the loop, an accumulator and
2137- // / vector operand are added together and passed to the next iteration as the
2138- // / next accumulator. After the loop body, the accumulator is reduced to a
2139- // / scalar value.
2140- class VPPartialReductionRecipe : public VPSingleDefRecipe {
2141- unsigned Opcode;
2142- // / The divisor by which the VF of this recipe's output should be divided
2143- // / during execution.
2144- unsigned VFScaleFactor;
2145-
2146- public:
2147- VPPartialReductionRecipe (Instruction *ReductionInst, VPValue *Op0,
2148- VPValue *Op1, unsigned VFScaleFactor)
2149- : VPPartialReductionRecipe(ReductionInst->getOpcode (), Op0, Op1,
2150- VFScaleFactor, ReductionInst) {}
2151- VPPartialReductionRecipe (unsigned Opcode, VPValue *Op0, VPValue *Op1,
2152- unsigned VFScaleFactor,
2153- Instruction *ReductionInst = nullptr )
2154- : VPSingleDefRecipe(VPDef::VPPartialReductionSC,
2155- ArrayRef<VPValue *>({Op0, Op1}), ReductionInst),
2156- Opcode(Opcode), VFScaleFactor(VFScaleFactor) {
2157- [[maybe_unused]] auto *AccumulatorRecipe =
2158- getOperand (1 )->getDefiningRecipe ();
2159- assert ((isa<VPReductionPHIRecipe>(AccumulatorRecipe) ||
2160- isa<VPPartialReductionRecipe>(AccumulatorRecipe)) &&
2161- " Unexpected operand order for partial reduction recipe" );
2162- }
2163- ~VPPartialReductionRecipe () override = default ;
2164-
2165- VPPartialReductionRecipe *clone () override {
2166- return new VPPartialReductionRecipe (Opcode, getOperand (0 ), getOperand (1 ),
2167- VFScaleFactor, getUnderlyingInstr ());
2168- }
2169-
2170- VP_CLASSOF_IMPL (VPDef::VPPartialReductionSC)
2171-
2172- // / Generate the reduction in the loop.
2173- void execute(VPTransformState &State) override ;
2174-
2175- // / Return the cost of this VPPartialReductionRecipe.
2176- InstructionCost computeCost (ElementCount VF,
2177- VPCostContext &Ctx) const override ;
2178-
2179- // / Get the binary op's opcode.
2180- unsigned getOpcode () const { return Opcode; }
2181-
2182- // / Get the factor that the VF of this recipe's output should be scaled by.
2183- unsigned getVFScaleFactor () const { return VFScaleFactor; }
2184-
2185- #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2186- // / Print the recipe.
2187- void print (raw_ostream &O, const Twine &Indent,
2188- VPSlotTracker &SlotTracker) const override ;
2189- #endif
2190- };
2191-
21922136// / A recipe for vectorizing a phi-node as a sequence of mask-based select
21932137// / instructions.
21942138class VPBlendRecipe : public VPSingleDefRecipe {
@@ -2431,6 +2375,65 @@ class VPReductionRecipe : public VPRecipeWithIRFlags {
24312375 }
24322376};
24332377
2378+ // / A recipe for forming partial reductions. In the loop, an accumulator and
2379+ // / vector operand are added together and passed to the next iteration as the
2380+ // / next accumulator. After the loop body, the accumulator is reduced to a
2381+ // / scalar value.
2382+ class VPPartialReductionRecipe : public VPReductionRecipe {
2383+ unsigned Opcode;
2384+
2385+ // / The divisor by which the VF of this recipe's output should be divided
2386+ // / during execution.
2387+ unsigned VFScaleFactor;
2388+
2389+ public:
2390+ VPPartialReductionRecipe (Instruction *ReductionInst, VPValue *Op0,
2391+ VPValue *Op1, VPValue *Cond, unsigned VFScaleFactor)
2392+ : VPPartialReductionRecipe(ReductionInst->getOpcode (), Op0, Op1, Cond,
2393+ VFScaleFactor, ReductionInst) {}
2394+ VPPartialReductionRecipe (unsigned Opcode, VPValue *Op0, VPValue *Op1,
2395+ VPValue *Cond, unsigned ScaleFactor,
2396+ Instruction *ReductionInst = nullptr )
2397+ : VPReductionRecipe(VPDef::VPPartialReductionSC, RecurKind::Add,
2398+ FastMathFlags (), ReductionInst,
2399+ ArrayRef<VPValue *>({Op0, Op1}), Cond, false, {}),
2400+ Opcode(Opcode), VFScaleFactor(ScaleFactor) {
2401+ [[maybe_unused]] auto *AccumulatorRecipe =
2402+ getChainOp ()->getDefiningRecipe ();
2403+ assert ((isa<VPReductionPHIRecipe>(AccumulatorRecipe) ||
2404+ isa<VPPartialReductionRecipe>(AccumulatorRecipe)) &&
2405+ " Unexpected operand order for partial reduction recipe" );
2406+ }
2407+ ~VPPartialReductionRecipe () override = default ;
2408+
2409+ VPPartialReductionRecipe *clone () override {
2410+ return new VPPartialReductionRecipe (Opcode, getOperand (0 ), getOperand (1 ),
2411+ getCondOp (), VFScaleFactor,
2412+ getUnderlyingInstr ());
2413+ }
2414+
2415+ VP_CLASSOF_IMPL (VPDef::VPPartialReductionSC)
2416+
2417+ // / Generate the reduction in the loop.
2418+ void execute(VPTransformState &State) override ;
2419+
2420+ // / Return the cost of this VPPartialReductionRecipe.
2421+ InstructionCost computeCost (ElementCount VF,
2422+ VPCostContext &Ctx) const override ;
2423+
2424+ // / Get the binary op's opcode.
2425+ unsigned getOpcode () const { return Opcode; }
2426+
2427+ // / Get the factor that the VF of this recipe's output should be scaled by.
2428+ unsigned getVFScaleFactor () const { return VFScaleFactor; }
2429+
2430+ #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2431+ // / Print the recipe.
2432+ void print (raw_ostream &O, const Twine &Indent,
2433+ VPSlotTracker &SlotTracker) const override ;
2434+ #endif
2435+ };
2436+
24342437// / A recipe to represent inloop reduction operations with vector-predication
24352438// / intrinsics, performing a reduction on a vector operand with the explicit
24362439// / vector length (EVL) into a scalar value, and adding the result to a chain.
0 commit comments