[llvm] [RISCV] Remove redundant czero in multi-word comparisons (PR #180485)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 9 19:04:27 PST 2026


================
@@ -21460,6 +21460,23 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
         return DAG.getNode(CCVal == ISD::SETNE ? Opc : InvOpc, SDLoc(N),
                            N->getValueType(0), Val, Cond.getOperand(0));
     }
+
+    // czero_nez (setcc X, Y, CC), (setcc X, Y, eq) -> (setcc X, Y, CC)
+    // if CC is a strict inequality (lt, gt, ult, ugt), because when X == Y
+    // the setcc result is already 0. The eq operands can be in either order.
+    if (Opc == RISCVISD::CZERO_NEZ && Val.getOpcode() == ISD::SETCC &&
+        Cond.getOpcode() == ISD::SETCC &&
+        cast<CondCodeSDNode>(Cond.getOperand(2))->get() == ISD::SETEQ) {
----------------
wangpc-pp wrote:

`cast<CondCodeSDNode>` may fail?

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


More information about the llvm-commits mailing list