[llvm] [RISCV] DAGCombine canonicalizes the true operand of vselect to have one use (PR #206449)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 05:38:26 PDT 2026


================
@@ -20406,6 +20355,40 @@ static SDValue useInversedSetcc(SDNode *N, SelectionDAG &DAG,
   return SDValue();
 }
 
+static SDValue
+canonicalizeVSelectTrueToOneUse(SDNode *N, SelectionDAG &DAG,
+                                const RISCVSubtarget &Subtarget) {
+  SDValue CC = N->getOperand(0);
+  SDValue TrueVal = N->getOperand(1);
+  SDValue FalseVal = N->getOperand(2);
+
+  if (CC.getOpcode() != ISD::SETCC || !CC.hasOneUse() || TrueVal.hasOneUse() ||
+      !FalseVal.hasOneUse())
+    return SDValue();
+
+  ISD::CondCode CCVal = cast<CondCodeSDNode>(CC.getOperand(2))->get();
+  if (CCVal != ISD::SETEQ && CCVal != ISD::SETNE)
+    return SDValue();
+
+  EVT VT = TrueVal.getValueType();
+  if (!VT.isSimple())
+    return SDValue();
----------------
lukel97 wrote:

Any particular reason to restrict this to simple VTs? Just quickly looking at the code below, it looks like it would also work for EVTs pre-type legalization

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


More information about the llvm-commits mailing list