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

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 09:33:32 PDT 2026


================
@@ -6786,6 +6852,44 @@ getScaledReductions(VPReductionPHIRecipe *RedPhiR, VPCostContext &CostCtx,
   // Work backwards from the ExitValue examining each reduction operation.
   VPValue *CurrentValue = ExitValue;
   while (CurrentValue != RedPhiR) {
+    VPValue *LinkMask = nullptr;
+    bool LinkNegateMask = false;
+    if (auto *Blend = dyn_cast<VPBlendRecipe>(CurrentValue)) {
----------------
MacDue wrote:

I think we can simplify this a bit. Given when `VPlanTransforms::createPartialReductions` runs, I think we can assume the blend is not normalized (the code paths added for normalized blends don't seem to be hit). 

Also, if we're limiting the conditional reduction support to:
```
%prev.val = previous_reduce(...)
if (cond)
      cond_reduce(%prev.val, ...);
```

I think we can limit this to looking for: `VPBlend(cond_reduce(PrevValue, Op), PrevValue)`. I'm fairly sure that we'd always expect the first incoming value to be the conditional reduction and the second incoming value to be the previous reduction in the chain.

So, if there's a blend. I think we can set the "CurrentValue" to the first incoming value, and then match like normal. We'd then later want to check that "PrevValue" matches the second incoming value of the blend. We may also want to make sure that the conditional reduction is only used by the blend. 




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


More information about the llvm-commits mailing list