[llvm] [LV] Handle partial reductions with predication (PR #194859)

Jacob Crawley via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 03:42:26 PDT 2026


================
@@ -6906,6 +7011,36 @@ void VPlanTransforms::createPartialReductions(VPlan &Plan,
       auto UseIsValid = [&, RedPhiR = RedPhiR](VPUser *U) {
         if (auto *PhiR = dyn_cast<VPReductionPHIRecipe>(U))
           return PhiR == RedPhiR;
+
+        // Predicated reductions introduced by an 'if' inside the loop
+        // will be represented by a VPBlendRecipe with two incoming values,
+        // the reduction PHI and the reduction Bin Op.
+        if (auto *Blend = dyn_cast<VPBlendRecipe>(U)) {
+          if (Blend->getNumIncomingValues() != 2)
+            return false;
+
+          VPValue *V0 = Blend->getIncomingValue(0);
+          VPValue *V1 = Blend->getIncomingValue(1);
+          if (!((V0 == Chain.ReductionBinOp && V1 == RedPhiR) ||
+                (V1 == Chain.ReductionBinOp && V0 == RedPhiR)))
+            return false;
----------------
jacob-crawley wrote:

Done, I added the extra test case `@reduction_before_pred`

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


More information about the llvm-commits mailing list