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

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 08:08:51 PST 2025


================
@@ -8184,11 +8185,21 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
              Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader()));
 
       // If the PHI is used by a partial reduction, set the scale factor.
+      bool UseInLoopReduction = CM.isInLoopReduction(Phi);
+      bool UseOrderedReductions = CM.useOrderedReductions(RdxDesc);
       unsigned ScaleFactor =
           getScalingForReduction(RdxDesc.getLoopExitInstr()).value_or(1);
-      PhiRecipe = new VPReductionPHIRecipe(
-          Phi, RdxDesc.getRecurrenceKind(), *StartV, CM.isInLoopReduction(Phi),
-          CM.useOrderedReductions(RdxDesc), ScaleFactor);
+      RdxStyle Style(RdxNormal{});
+      if (UseInLoopReduction) {
+        if (UseOrderedReductions)
+          Style = RdxOrderedInLoop{};
+        else
+          Style = RdxInLoop{};
+      } else if (ScaleFactor > 1) {
+        Style = RdxPartial{/*VFScaleFactor=*/ScaleFactor};
+      }
----------------
SamTebbs33 wrote:

Done. I'd like to have namespaced it in `ReductionStyle` but that's just an alias for the `std::variant`.

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


More information about the llvm-commits mailing list