@@ -4007,8 +4007,6 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
4007
4007
4008
4008
// For SMAX, if CstLow is non-negative we know the result will be
4009
4009
// non-negative and thus all sign bits are 0.
4010
- // TODO: There's an equivalent of this for smin with negative constant for
4011
- // known ones.
4012
4010
if (IsMax && CstLow) {
4013
4011
const APInt &ValueLow = CstLow->getAPIntValue ();
4014
4012
if (ValueLow.isNonNegative ()) {
@@ -4017,6 +4015,16 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
4017
4015
}
4018
4016
}
4019
4017
4018
+ // For SMIN, if CstHigh is negative we know the result will be
4019
+ // negative and thus all sign bits are 1.
4020
+ if (!IsMax && CstHigh) {
4021
+ const APInt &ValueHigh = CstHigh->getAPIntValue ();
4022
+ if (ValueHigh.isNegative ()) {
4023
+ unsigned SignBits = ComputeNumSignBits (Op.getOperand (0 ), Depth + 1 );
4024
+ Known.One .setHighBits (std::min (SignBits, ValueHigh.getNumSignBits ()));
4025
+ }
4026
+ }
4027
+
4020
4028
break ;
4021
4029
}
4022
4030
case ISD::UINT_TO_FP: {
@@ -5360,10 +5368,20 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
5360
5368
return isKnownNeverZero (Op.getOperand (1 ), Depth + 1 ) ||
5361
5369
isKnownNeverZero (Op.getOperand (0 ), Depth + 1 );
5362
5370
5363
- // TODO for smin/smax: If either operand is known negative/positive
5371
+ // For smin/smax: If either operand is known negative/positive
5364
5372
// respectively we don't need the other to be known at all.
5365
5373
case ISD::SMAX:
5374
+ if (computeKnownBits (Op.getOperand (1 ), Depth + 1 ).isStrictlyPositive () ||
5375
+ computeKnownBits (Op.getOperand (0 ), Depth + 1 ).isStrictlyPositive ())
5376
+ return true ;
5377
+ return isKnownNeverZero (Op.getOperand (1 ), Depth + 1 ) &&
5378
+ isKnownNeverZero (Op.getOperand (0 ), Depth + 1 );
5366
5379
case ISD::SMIN:
5380
+ if (computeKnownBits (Op.getOperand (1 ), Depth + 1 ).isNegative () ||
5381
+ computeKnownBits (Op.getOperand (0 ), Depth + 1 ).isNegative ())
5382
+ return true ;
5383
+ return isKnownNeverZero (Op.getOperand (1 ), Depth + 1 ) &&
5384
+ isKnownNeverZero (Op.getOperand (0 ), Depth + 1 );
5367
5385
case ISD::UMIN:
5368
5386
return isKnownNeverZero (Op.getOperand (1 ), Depth + 1 ) &&
5369
5387
isKnownNeverZero (Op.getOperand (0 ), Depth + 1 );
0 commit comments