[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;
- AffineExpr lhs = cstr.getExpr(minOp.getLhs());
- AffineExpr rhs = cstr.getExpr(minOp.getRhs());
- cstr.bound(value) <= lhs;
- cstr.bound(value) <= rhs;
+ if (lhsNonNegative) {
+ AffineExpr lhs = cstr.getExpr(minOp.getLhs());
+ cstr.bound(value) <= lhs;
----------------
matthias-springer wrote:
This one here is much simpler than the `>= 0` bound: if the signed interpretation and the unsigned interpretation match, then `minsi` and `minui` have the same bound. I would still add a comment about this.
https://github.com/llvm/llvm-project/pull/207701
More information about the Mlir-commits
mailing list