[llvm] [LV] Use VPReductionRecipe for partial reductions (PR #144908)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 20 08:39:02 PDT 2025


================
@@ -2563,6 +2495,30 @@ InstructionCost VPReductionRecipe::computeCost(ElementCount VF,
   std::optional<FastMathFlags> OptionalFMF =
       ElementTy->isFloatingPointTy() ? std::make_optional(FMFs) : std::nullopt;
 
+  if (isPartialReduction()) {
+    using namespace llvm::VPlanPatternMatch;
+    VPValue *Mul = getVecOp();
+    // Some chained partial reductions used for complex numbers will have a
+    // negation between the mul and reduction. This extracts the mul from that
+    // pattern to use it for further checking.
+    match(Mul, m_Binary<Instruction::Sub>(m_SpecificInt(0), m_VPValue(Mul)));
+    if (match(Mul,
+              m_Mul(m_ZExtOrSExt(m_VPValue()), m_ZExtOrSExt(m_VPValue())))) {
----------------
sdesmalen-arm wrote:

The case you're trying to match is the case already implemented by the `VPMulAccumulateReductionRecipe`, so there's no need to try and match this again. For this default case, the call to `getPartialReductionCost` should assume no extends and no opcode.

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


More information about the llvm-commits mailing list