[ARITH] Bugfix: int bound analysis for mod (#3288)
authorSergei Grechanik <grechanik.sergey@huawei.com>
Tue, 4 Jun 2019 15:42:27 +0000 (18:42 +0300)
committerTianqi Chen <tqchen@users.noreply.github.com>
Tue, 4 Jun 2019 15:42:27 +0000 (08:42 -0700)
src/arithmetic/const_int_bound.cc
tests/python/unittest/test_arith_rewrite_simplify.py

index 72b8508..ed8faba 100644 (file)
@@ -190,7 +190,7 @@ class ConstIntBoundAnalyzer::Impl :
                          std::min(a.max_value, b_max_cap));
       } else {
         return MakeBound(std::max(a.min_value, -b_max_cap),
-                         std::min(a.max_value, b_max_cap));
+                         std::min(std::max(a.max_value, (int64_t)0), b_max_cap));
       }
     } else {
       CHECK(!b.is_const(0)) << "mod by zero";
index ee113e1..596e54d 100644 (file)
@@ -564,6 +564,7 @@ def test_cmp_simplify():
     ck.verify((x + 1)*(y - 1) < 0, tvm.const(1, "bool"))
     ck.verify(y*y >= 0, tvm.const(1, "bool"))
     ck.verify(x*6 <= -3, tvm.const(0, "bool"))
+    ck.verify((y - 1) % 3 == 0, (y + (-1)) % 3 == 0)
 
 
 def test_logical_simplify():