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

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 03:25:49 PDT 2024


================
@@ -308,6 +308,53 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
   return UI ? Ctx.getLegacyCost(UI, VF) : 0;
 }
 
+void VPPartialReductionRecipe::execute(VPTransformState &State) {
+  State.setDebugLocFrom(getDebugLoc());
+  auto &Builder = State.Builder;
+
+  assert(Opcode == Instruction::Add && "Unhandled partial reduction opcode");
+
+  for (unsigned Part = 0; Part < State.UF; ++Part) {
+    Value *Mul = nullptr;
----------------
huntergr-arm wrote:

I still think the operand order needs to be fixed at recipe creation time instead of being (re)discovered here... especially since FullTy is calculated based on the first operand regardless of whether it's assigned to Phi or Mul.

You don't need to store Scale in the recipe at all, if your types can already be determined from those of your inputs -- Phi must have the same type as the return, since the partial reduction is an input to the Phi.


We might also want a different name than `Mul`, since we intend to represent operations besides dot product with this intrinsic.

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


More information about the llvm-commits mailing list