This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git


The following commit(s) were added to refs/heads/main by this push:
     new 4a76fe3f9 [FIX] Respect unsigned subtraction underflow in constant 
bounds (#142)
4a76fe3f9 is described below

commit 4a76fe3f96dd717766b292449d447c5ba05a6b45
Author: Tianqi Chen <[email protected]>
AuthorDate: Sat Oct 31 10:51:00 2026 -0400

    [FIX] Respect unsigned subtraction underflow in constant bounds (#142)
    
    Return the full unsigned range when subtraction may underflow and
    AllowUIntAsIndex is disabled. Preserve ordinary interval arithmetic
    under the caller's no-underflow assumption when the flag is enabled.
---
 src/sym/const_int_bound.cc               |  6 ++++++
 tests/python/sym/test_const_int_bound.py | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/src/sym/const_int_bound.cc b/src/sym/const_int_bound.cc
index 03ac9d566..13d19bae8 100644
--- a/src/sym/const_int_bound.cc
+++ b/src/sym/const_int_bound.cc
@@ -280,6 +280,12 @@ class ConstIntBoundAnalyzer::Impl final
     ret.min_value = InfAwareAdd(a.min_value, -b.max_value);
     ret.max_value = InfAwareAdd(a.max_value, -b.min_value);
 
+    PrimType dtype = op->ty.as_or_throw<PrimType>();
+    if (dtype.code() == DLDataTypeCode::kDLUInt && 
!AllowUIntAsIndex::Enabled() &&
+        ret.min_value < 0) {
+      return Everything(dtype);
+    }
+
     return ret;
   }
 
diff --git a/tests/python/sym/test_const_int_bound.py 
b/tests/python/sym/test_const_int_bound.py
index 8e7729f29..990c31bb1 100644
--- a/tests/python/sym/test_const_int_bound.py
+++ b/tests/python/sym/test_const_int_bound.py
@@ -135,6 +135,20 @@ class TestCastBound(BaseCompare):
         return request.param
 
 
+def test_unsigned_sub_underflow_requires_index_mode():
+    x = tvm_tirx.tirx.Var("x", "uint32")
+    expr = x % 7 - 6
+    analyzer = tvm_tirx.sym.Analyzer()
+
+    bound = analyzer.const_int_bound(expr)
+    assert (bound.min_value, bound.max_value) == (0, 2**32 - 1)
+    with tvm_tirx.sym.allow_uint_as_index():
+        bound = analyzer.const_int_bound(expr)
+        assert (bound.min_value, bound.max_value) == (-6, 0)
+    bound = analyzer.const_int_bound(expr)
+    assert (bound.min_value, bound.max_value) == (0, 2**32 - 1)
+
+
 class TestAddSubBound(BaseCompare):
     x = tvm_tirx.tirx.Var("x", "int64")
     y = tvm_tirx.tirx.Var("y", "int64")

Reply via email to