[llvm] [RISCV] Combine `(setcc (riscv_selectcc A, B, ...), Y)` to just `(setcc A, B)` when possible (PR #90538)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 10:55:53 PDT 2024


================
@@ -13678,9 +13679,69 @@ static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG,
                                    const RISCVSubtarget &Subtarget) {
   SDValue N0 = N->getOperand(0);
   SDValue N1 = N->getOperand(1);
+  ISD::CondCode Cond = cast<CondCodeSDNode>(N->getOperand(2))->get();
   EVT VT = N->getValueType(0);
   EVT OpVT = N0.getValueType();
+  SDLoc DL(N);
+
+  // Both rules are looking for an equality compare.
+  if (!isIntEqualitySetCC(Cond))
+    return SDValue();
+
+  // Rule 1
+  using namespace SDPatternMatch;
+  auto getSelectCCPattern = [](SDValue Candidate, bool Inverse,
+                               SDValue &Select) -> auto {
+    if (Inverse)
+      return m_AllOf(
+          m_OneUse(m_Node(RISCVISD::SELECT_CC, m_Value(), m_Value(), m_Value(),
+                          /*TrueVal=*/m_Value(),
+                          /*FalseVal=*/m_Specific(Candidate))),
+          m_Value(Select));
+    else
+      return m_AllOf(
+          m_OneUse(m_Node(RISCVISD::SELECT_CC, m_Value(), m_Value(), m_Value(),
+                          /*TrueVal=*/m_Specific(Candidate),
+                          /*FalseVal=*/m_Value())),
+          m_Value(Select));
+  };
+
+  auto buildSetCC = [&](SDValue Select, bool Inverse) -> SDValue {
+    ISD::CondCode NewCC = cast<CondCodeSDNode>(Select->getOperand(2))->get();
+    if (Inverse)
+      NewCC = ISD::getSetCCInverse(NewCC, OpVT);
+    return DAG.getNode(
----------------
mshockwave wrote:

Fixed.

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


More information about the llvm-commits mailing list