[llvm] [VPlan] Peek through nested phi incoming values in computeBlendMasks (PR #203164)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 2 23:04:30 PDT 2026


================
@@ -275,6 +275,10 @@ VPPredicator::computeBlendEdges(VPPhi *Phi) {
   for (auto [InVal, InVPBB] : Phi->incoming_values_and_blocks())
     AddEdge(InVPBB, Phi->getParent(), InVal);
 
+  // Don't optimize any reduction chains for now.
----------------
lukel97 wrote:

We actually only need to bail out for phis that are inserted in reduction chains during tail folding, which should always be of the form:

```
latch:
  %phi = [%rdxphi, %entry], [%foo, %bbX]
```

The main thing this is trying to avoid breaking is this part in `VPlanTransforms::handleFindLastReductions`:

```c++
    // If there's a header mask, the backedge select will not be the find-last
    // select.
    if (HeaderMask &&
        !match(BackedgeSelect,
               m_SelectLike(m_Specific(HeaderMask), m_VPValue(CondSelect),
                            m_Specific(PhiR))))
      return false;
```

Partial reductions w/ tail folding also get affected by the optimisation, somewhere in `transformToPartialReduction` I think.

I've clarified this and relaxed the restriction to specifically check that the phi is in the latch in 17eb3204e9bb5a089e112e68e40ed830ffde3047

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


More information about the llvm-commits mailing list