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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 05:56:23 PDT 2024


================
@@ -6871,6 +6974,18 @@ void LoopVectorizationCostModel::collectValuesToIgnore() {
     const SmallVectorImpl<Instruction *> &Casts = IndDes.getCastInsts();
     VecValuesToIgnore.insert(Casts.begin(), Casts.end());
   }
+
+  // Ignore any values that we know will be flattened
+  for (auto It : getPartialReductionChains()) {
+    PartialReductionChain Chain = It.second;
+    SmallVector<Value *> PartialReductionValues{Chain.Reduction, Chain.BinOp,
+                                                Chain.ExtendA, Chain.ExtendB,
+                                                Chain.Accumulator};
+    ValuesToIgnore.insert(PartialReductionValues.begin(),
+                          PartialReductionValues.end());
+    VecValuesToIgnore.insert(PartialReductionValues.begin(),
----------------
fhahn wrote:

Would it be possible to shift the detection of partial reductions to after the initial VPlans have been constructed and work based on VPlan? The pattern matching done in `addPartialReductionIfSupported(` should be possible to do on VPlan and then introducing the partial reductions could be done as VPlan transformation. That would allow the cost to be computed directly on the VPlan (given ::computeCost is implemented for the recipe) and more accurately (VPlan DCE will take care of removing unneeded recipes)

If possible this would be preferable instead of adding additional logic and mappings to the legacy cost model.

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


More information about the llvm-commits mailing list