[llvm] [DAG] SimplifyDemandedBits - ICMP_SLT(X, 0) - only sign mask of X is required (PR #164946)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 8 01:48:59 PST 2025


================
@@ -1753,23 +1753,38 @@ bool TargetLowering::SimplifyDemandedBits(
     SDValue Op0 = Op.getOperand(0);
     SDValue Op1 = Op.getOperand(1);
     ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
-    // If (1) we only need the sign-bit, (2) the setcc operands are the same
-    // width as the setcc result, and (3) the result of a setcc conforms to 0 or
-    // -1, we may be able to bypass the setcc.
-    if (DemandedBits.isSignMask() &&
-        Op0.getScalarValueSizeInBits() == BitWidth &&
-        getBooleanContents(Op0.getValueType()) ==
-            BooleanContent::ZeroOrNegativeOneBooleanContent) {
-      // If we're testing X < 0, then this compare isn't needed - just use X!
-      // FIXME: We're limiting to integer types here, but this should also work
-      // if we don't care about FP signed-zero. The use of SETLT with FP means
-      // that we don't care about NaNs.
-      if (CC == ISD::SETLT && Op1.getValueType().isInteger() &&
-          (isNullConstant(Op1) || ISD::isBuildVectorAllZeros(Op1.getNode())))
-        return TLO.CombineTo(Op, Op0);
-
-      // TODO: Should we check for other forms of sign-bit comparisons?
-      // Examples: X <= -1, X >= 0
+    // If we're testing X < 0, X >= 0, X <= -1 (X is of integer type) or X > -1
+    // (X is of integer type) then we only need the sign mask of the previous
+    // result
+    if (((CC == ISD::SETLT || CC == ISD::SETGE) &&
+         Op1.getValueType().isInteger() && isNullOrNullSplat(Op1)) ||
+        ((CC == ISD::SETLE || CC == ISD::SETGT) &&
+         Op1.getValueType().isInteger() && isAllOnesOrAllOnesSplat(Op1))) {
----------------
jayfoad wrote:

Just check `Op1.getValueType().isInteger()` once

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


More information about the llvm-commits mailing list