[llvm] [VPlan] Introduce m_SelectLike and use to support 2-operand blends. (PR #194729)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 05:52:03 PDT 2026


================
@@ -761,13 +761,44 @@ inline auto m_GetElementPtr(const Op0_t &Op0, const Op1_t &Op1) {
       VPInstruction_match<VPInstruction::WidePtrAdd, Op0_t, Op1_t>(Op0, Op1));
 }
 
+/// Match a  VPBlendRecipe with 2 incoming values ([M0, I0, M1, I1]) as
+/// select(M1, I1, I0). Also matches the normalized form, where M0 is dropped.
+template <typename Op0_t, typename Op1_t, typename Op2_t> struct Blend2_match {
+  Op0_t MaskOp;
+  Op1_t TrueOp;
+  Op2_t FalseOp;
+
+  Blend2_match(const Op0_t &MaskOp, const Op1_t &TrueOp, const Op2_t &FalseOp)
+      : MaskOp(MaskOp), TrueOp(TrueOp), FalseOp(FalseOp) {}
+
+  template <typename T> bool match(const T *Val) const {
+    auto *Blend = dyn_cast<VPBlendRecipe>(Val);
+    if (!Blend || Blend->getNumIncomingValues() != 2)
+      return false;
+    unsigned TrueIdx = Blend->isNormalized() ? 1 : 0;
+    unsigned FalseIdx = 1 - TrueIdx;
+    return MaskOp.match(Blend->getMask(TrueIdx)) &&
+           TrueOp.match(Blend->getIncomingValue(TrueIdx)) &&
+           FalseOp.match(Blend->getIncomingValue(FalseIdx));
----------------
sdesmalen-arm wrote:

```suggestion
    return MaskOp.match(Blend->getMask(1)) &&
           TrueOp.match(Blend->getIncomingValue(1)) &&
           FalseOp.match(Blend->getIncomingValue(0));
```
This way, they're equivalent for the normalized/non-normalized case.

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


More information about the llvm-commits mailing list