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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 17 11:24:30 PST 2024


================
@@ -291,6 +291,53 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
   llvm_unreachable("subclasses should implement computeCost");
 }
 
+InstructionCost
+VPPartialReductionRecipe::computeCost(ElementCount VF,
+                                      VPCostContext &Ctx) const {
+  auto *BinOp = cast<BinaryOperator>(getOperand(0)->getUnderlyingValue());
+  auto *PhiR = cast<VPReductionPHIRecipe>(getOperand(1)->getDefiningRecipe());
+  auto *Phi = cast<PHINode>(PhiR->getUnderlyingValue());
+  auto *ExtA = cast<Instruction>(BinOp->getOperand(0));
+  auto *ExtB = cast<Instruction>(BinOp->getOperand(1));
+  Value *A = ExtA->getOperand(0);
+  return Ctx.TTI.getPartialReductionCost(
----------------
fhahn wrote:

Can the cost be computed by avoiding to rely in the underlying IR instructions, e.g. types should be determined by VPTypeAnalysis, extend kinds from the extend recipes. VPlan simplifications may change the recipe's operands, meaning the underlying IR isn't accurate any more.

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


More information about the llvm-commits mailing list