[llvm] Reland "[LoopVectorizer] Add support for partial reductions" with non-phi operand fix. (PR #121744)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 05:48:58 PST 2025


================
@@ -292,6 +292,70 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
   llvm_unreachable("subclasses should implement computeCost");
 }
 
+InstructionCost
+VPPartialReductionRecipe::computeCost(ElementCount VF,
+                                      VPCostContext &Ctx) const {
+  std::optional<unsigned> Opcode = std::nullopt;
+  VPRecipeBase *BinOpR = getOperand(0)->getDefiningRecipe();
+  if (auto *WidenR = dyn_cast<VPWidenRecipe>(BinOpR))
+    Opcode = std::make_optional(WidenR->getOpcode());
+
+  VPRecipeBase *ExtAR = BinOpR->getOperand(0)->getDefiningRecipe();
+  VPRecipeBase *ExtBR = BinOpR->getOperand(1)->getDefiningRecipe();
+
+  auto *PhiType = Ctx.Types.inferScalarType(getOperand(1));
+  auto *ExtTy = ExtAR ? Ctx.Types.inferScalarType(ExtAR->getOperand(0))
----------------
SamTebbs33 wrote:

Renaming it to `InputType` sounds like a good idea to me.

At the moment both A and B have to be extends from and to the same type but I can see the argument for passing both input types to the target and letting it decide.

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


More information about the llvm-commits mailing list