[llvm] [SelectionDAG] Improve ucmp/scmp codegen (PR #190787)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 14:00:34 PDT 2026


================
@@ -11638,6 +11638,23 @@ SDValue TargetLowering::expandCMP(SDNode *Node, SelectionDAG &DAG) const {
   EVT BoolVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
   SDLoc dl(Node);
 
+  // fold scmp(x, 0) -> or(sra(x, bw-1), zext(setne(x, 0)))
+  // only when VT is a non-native integer type.
+  if (Opcode == ISD::SCMP && isNullConstant(RHS) && VT.isScalarInteger() &&
+      getTypeAction(*DAG.getContext(), VT) == TypeExpandInteger) {
----------------
arsenm wrote:

```suggestion
  if (Opcode == ISD::SCMP && isNullConstant(RHS) && 
      !isTypeLegal(VT))
```
Doesn't need to limit to scalars. It's also unusual to check the exact legalization action in these sorts of expansion 


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


More information about the llvm-commits mailing list