[Mlir-commits] [mlir] Improving MinUI and MaxUI implementation in valuebounds (PR #207701)
Matthias Springer
llvmlistbot at llvm.org
Mon Jul 6 05:14:45 PDT 2026
================
@@ -354,20 +354,25 @@ struct MinUIOpInterface
assert(value == minOp.getResult() && "invalid value");
// ValueBoundsConstraintSet models values as signed integers (e.g. an i8
- // 0xff is treated as -1, not 255).So, we can only derive bounds for minui
- // if both operands are provably non-negative.
+ // 0xff is treated as -1, not 255). For an unsigned minimum it is enough
+ // that a single operand is provably non-negative: minui(x, y) is in
+ // [0, y] whenever y >= 0 (and symmetrically for x).
bool lhsNonNegative =
ValueBoundsConstraintSet::isProvablyNonNegative(minOp.getLhs(), cstr);
bool rhsNonNegative =
ValueBoundsConstraintSet::isProvablyNonNegative(minOp.getRhs(), cstr);
- if (!lhsNonNegative || !rhsNonNegative)
+ if (!lhsNonNegative && !rhsNonNegative)
return;
cstr.bound(value) >= 0;
----------------
matthias-springer wrote:
Can you add more details about the `>= 0` bound? Something along the lines of:
```
A negative signed integer bit pattern reinterpreted as an
unsigned integer is greater than SIGNED_INT_MAX. If
one of the operands is signed non-negative, it is smaller than
or equal to SIGNED_INT_MAX in unsigned interpretation,
and `minui` will choose that operand over a negative signed
integer operand.
```
(Please double-check if what I wrote is correct.)
https://github.com/llvm/llvm-project/pull/207701
More information about the Mlir-commits
mailing list