[llvm] [SDPatternMatch] Simplify MaxMin_match. NFC (PR #227947)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 21:02:24 PDT 2026


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/227947

Remove EffectiveOperands and m_SpecificOpc since we no longer need to match VP nodes.

Use . instead of -> for calling getOperand, getOpcode, and getNumOperands.

>From 3010c5d1cbc1488234d43a8522b5d7c0cb46ed36 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 30 Sep 2026 20:50:06 -0700
Subject: [PATCH] [SDPatternMatch] Simplify MaxMin_match. NFC

Remove EffectiveOperands and m_SpecificOpc since we no longer need
to match VP nodes.

Use . instead of -> for calling getOperand, getOpcode, and
getNumOperands.
---
 llvm/include/llvm/CodeGen/SDPatternMatch.h | 48 ++++++++++------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index 78766f89bce16..ad29772ce7063 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -692,7 +692,7 @@ struct m_SpecificMask {
 };
 
 template <typename LHS_P, typename RHS_P, typename Pred_t,
-          bool Commutable = false, bool ExcludeChain = false>
+          bool Commutable = false>
 struct MaxMin_match {
   using PredType = Pred_t;
   LHS_P LHS;
@@ -716,35 +716,29 @@ struct MaxMin_match {
              (Commutable && LHS.match(R) && RHS.match(L));
     };
 
-    if (sd_match(N, m_SpecificOpc(ISD::SELECT)) ||
-        sd_match(N, m_SpecificOpc(ISD::VSELECT))) {
-      EffectiveOperands<ExcludeChain> EO_SELECT(N);
-      assert(EO_SELECT.Size == 3);
-      SDValue Cond = N->getOperand(EO_SELECT.FirstIndex);
-      SDValue TrueValue = N->getOperand(EO_SELECT.FirstIndex + 1);
-      SDValue FalseValue = N->getOperand(EO_SELECT.FirstIndex + 2);
-
-      if (sd_match(Cond, m_SpecificOpc(ISD::SETCC))) {
-        EffectiveOperands<ExcludeChain> EO_SETCC(Cond);
-        assert(EO_SETCC.Size == 3);
-        SDValue L = Cond->getOperand(EO_SETCC.FirstIndex);
-        SDValue R = Cond->getOperand(EO_SETCC.FirstIndex + 1);
-        auto *CondNode =
-            cast<CondCodeSDNode>(Cond->getOperand(EO_SETCC.FirstIndex + 2));
-        return MatchMinMax(L, R, TrueValue, FalseValue, CondNode->get());
+    if (N.getOpcode() == ISD::SELECT || N.getOpcode() == ISD::VSELECT) {
+      assert(N.getNumOperands() == 3);
+      SDValue Cond = N.getOperand(0);
+      SDValue TrueValue = N.getOperand(1);
+      SDValue FalseValue = N.getOperand(2);
+
+      if (Cond.getOpcode() == ISD::SETCC) {
+        assert(Cond.getNumOperands() == 3);
+        SDValue L = Cond.getOperand(0);
+        SDValue R = Cond.getOperand(1);
+        ISD::CondCode CC = cast<CondCodeSDNode>(Cond.getOperand(2))->get();
+        return MatchMinMax(L, R, TrueValue, FalseValue, CC);
       }
     }
 
-    if (sd_match(N, m_SpecificOpc(ISD::SELECT_CC))) {
-      EffectiveOperands<ExcludeChain> EO_SELECT(N);
-      assert(EO_SELECT.Size == 5);
-      SDValue L = N->getOperand(EO_SELECT.FirstIndex);
-      SDValue R = N->getOperand(EO_SELECT.FirstIndex + 1);
-      SDValue TrueValue = N->getOperand(EO_SELECT.FirstIndex + 2);
-      SDValue FalseValue = N->getOperand(EO_SELECT.FirstIndex + 3);
-      auto *CondNode =
-          cast<CondCodeSDNode>(N->getOperand(EO_SELECT.FirstIndex + 4));
-      return MatchMinMax(L, R, TrueValue, FalseValue, CondNode->get());
+    if (N.getOpcode() == ISD::SELECT_CC) {
+      assert(N.getNumOperands() == 5);
+      SDValue L = N.getOperand(0);
+      SDValue R = N.getOperand(1);
+      SDValue TrueValue = N.getOperand(2);
+      SDValue FalseValue = N.getOperand(3);
+      ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get();
+      return MatchMinMax(L, R, TrueValue, FalseValue, CC);
     }
 
     return false;



More information about the llvm-commits mailing list