[llvm] [SelectionDAG]: Deduce known bits from SMIN and SMAX (PR #85722)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 10:44:31 PDT 2024
================
@@ -5360,10 +5368,20 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
return isKnownNeverZero(Op.getOperand(1), Depth + 1) ||
isKnownNeverZero(Op.getOperand(0), Depth + 1);
- // TODO for smin/smax: If either operand is known negative/positive
+ // For smin/smax: If either operand is known negative/positive
// respectively we don't need the other to be known at all.
case ISD::SMAX:
+ if (computeKnownBits(Op.getOperand(1), Depth + 1).isStrictlyPositive() ||
+ computeKnownBits(Op.getOperand(0), Depth + 1).isStrictlyPositive())
+ return true;
+ return isKnownNeverZero(Op.getOperand(1), Depth + 1) &&
+ isKnownNeverZero(Op.getOperand(0), Depth + 1);
case ISD::SMIN:
+ if (computeKnownBits(Op.getOperand(1), Depth + 1).isNegative() ||
+ computeKnownBits(Op.getOperand(0), Depth + 1).isNegative())
----------------
RKSimon wrote:
Maybe pull out the computeKnownBits calls so we can also test:
```cpp
if (computeKnownBits(Op.getOperand(1), Depth + 1).isNonZero() &&
computeKnownBits(Op.getOperand(0), Depth + 1).isNonZero())
```
https://github.com/llvm/llvm-project/pull/85722
More information about the llvm-commits
mailing list