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

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 06:35:14 PDT 2026


================
@@ -6786,6 +6809,19 @@ getScaledReductions(VPReductionPHIRecipe *RedPhiR, VPCostContext &CostCtx,
   // Work backwards from the ExitValue examining each reduction operation.
   VPValue *CurrentValue = ExitValue;
   while (CurrentValue != RedPhiR) {
+    VPBlendRecipe *Blend = nullptr;
+    if (auto *B = dyn_cast<VPBlendRecipe>(CurrentValue)) {
+      if (B->getNumIncomingValues() != 2)
+        return std::nullopt;
+      assert(!B->isNormalized() && "Expect Blend not to be normalized.");
+
+      Blend = B;
+      CurrentValue = B->getIncomingValue(0);
+
+      if (!CurrentValue->hasOneUse())
+        return std::nullopt;
+    }
----------------
sdesmalen-arm wrote:

nit: you can assign to `Blend` directly, and can be tidied up further to:
```suggestion
    VPBlendRecipe *Blend = dyn_cast<VPBlendRecipe>(CurrentValue);
    if (Blend) {
      assert(!Blend->isNormalized() && "Expect Blend not to be normalized.");
      CurrentValue = Blend->getIncomingValue(0);
      if (Blend->getNumIncomingValues() != 2 || !CurrentValue->hasOneUse())
        return std::nullopt;
    }
```
(a `VPBlendRecipe` is expected to have _at least_ 2 incoming values, hence why `getIncomingValue(0)` is safe).

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


More information about the llvm-commits mailing list