[llvm] [DAG] SimplifyDemandedBits - ICMP_SLT(X, 0) - only sign mask of X is required (PR #164946)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 7 10:32:16 PST 2025
================
@@ -1753,23 +1753,41 @@ 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
+ // FIXME: We're limiting to integer types for X < 0 or X >= 0 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.
----------------
arsenm wrote:
I don't think it makes sense to mention the FP case. You can do simplify-demanded-fp-class optimizations, but it will be wholly different and separate from SimplifyDemandedBits
https://github.com/llvm/llvm-project/pull/164946
More information about the llvm-commits
mailing list