[llvm-branch-commits] [llvm] [LV] Only create partial reductions when profitable. (PR #181706)

Florian Hahn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 12 03:59:00 PDT 2026


================
@@ -4339,23 +4339,19 @@ tryToMatchAndCreateExtendedReduction(VPReductionRecipe *Red, VPCostContext &Ctx,
               cast<VPWidenCastRecipe>(VecOp)->computeCost(VF, Ctx);
           InstructionCost RedCost = Red->computeCost(VF, Ctx);
 
-          if (Red->isPartialReduction()) {
-            TargetTransformInfo::PartialReductionExtendKind ExtKind =
-                TargetTransformInfo::getPartialReductionExtendKind(ExtOpc);
-            // FIXME: Move partial reduction creation, costing and clamping
-            // here from LoopVectorize.cpp.
-            ExtRedCost = Ctx.TTI.getPartialReductionCost(
-                Opcode, SrcTy, nullptr, RedTy, VF, ExtKind,
-                llvm::TargetTransformInfo::PR_None, std::nullopt, Ctx.CostKind,
-                RedTy->isFloatingPointTy()
-                    ? std::optional{Red->getFastMathFlags()}
-                    : std::nullopt);
-          } else if (!RedTy->isFloatingPointTy()) {
-            // TTI::getExtendedReductionCost only supports integer types.
-            ExtRedCost = Ctx.TTI.getExtendedReductionCost(
-                Opcode, ExtOpc == Instruction::CastOps::ZExt, RedTy, SrcVecTy,
-                Red->getFastMathFlags(), CostKind);
-          }
+          // For partial reductions, the decision has already been
+          // made at the point of transforming reductions -> partial
+          // reductions for a given plan, based on the cost-model.
+          if (Red->isPartialReduction())
----------------
fhahn wrote:

It looks like this could be moved up before computing any costs, or maybe even outside of `IsExtendedRedValidAndClampRange`, as we don't really check if the extends are valid in that case?

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


More information about the llvm-branch-commits mailing list