[llvm] [RISCV] Fold vmnot.m of an integer compare into the compare (PR #222553)

Marton Moro via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 05:11:59 PDT 2026


================
@@ -19253,6 +19253,28 @@ static SDValue performORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
   return combineSelectAndUseCommutative(N, DAG, /*AllOnes*/ false, Subtarget);
 }
 
+// Fold (vmxor_vl (setcc_vl a, b, cc), vmset_vl) -> (setcc_vl a, b, !cc) for
+// integer compares.
+static SDValue combineVMNOTOfSetCC(SDNode *N, SelectionDAG &DAG) {
+  SDValue Cmp = N->getOperand(0);
+  if (Cmp.getOpcode() == RISCVISD::VMSET_VL)
+    Cmp = N->getOperand(1);
+  else if (N->getOperand(1).getOpcode() != RISCVISD::VMSET_VL)
+    return SDValue();
+
+  if (Cmp.getOpcode() != RISCVISD::SETCC_VL || !Cmp.hasOneUse() ||
+      !Cmp.getOperand(0).getValueType().isInteger() ||
+      !Cmp.getOperand(3).isUndef() ||
----------------
martonmoro wrote:

Right, I was being too conservative I think since the case from the issue had an all-ones mask and I wasn't sure. IIUC only one of the two is needed, since masked-off lanes take the passthru, which the NOT flips but the inverted compare doesn't. So it's correct if the mask is all-ones or the passthru is undef? 

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


More information about the llvm-commits mailing list