You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/10/28 01:14:52 UTC

[GitHub] [incubator-tvm] hzfan commented on a change in pull request #6771: [ARITH] Tight bound for floormod

hzfan commented on a change in pull request #6771:
URL: https://github.com/apache/incubator-tvm/pull/6771#discussion_r513122313



##########
File path: src/arith/const_int_bound.cc
##########
@@ -259,9 +259,28 @@ class ConstIntBoundAnalyzer::Impl
       }
     } else {
       ICHECK(!b.is_const(0)) << "floormod by zero";
-      // mod by negative value is rare,
-      // and we just use the simpliest rule.
-      return Everything(op->dtype);
+      /* let a / b = x + y, where x is integer, y \in [0, 1)
+       * floormod(a, b) = a - floordiv(a, b) * b
+       * floordiv(a, b) = x
+       * floormod(a, b) = a - floordiv(a, b) * b
+       *                = a - x * b
+       *                = a - (a / b - y) * b
+       *                = a - a + y * b
+       *                = y * b
+       * note that 0 <= y < 1
+       * when b > 0, 0 <= b * y < b
+       *             0 <= b * y <= b - 1
+       * when b < 0, b < b * y <= 0
+       *             b + 1 <= b * y <= 0
+       * In all cases, min(0, b + 1) <= b * y <= max(0, b - 1)
+       *               min(0, b_min + 1) <= b * y <= max(0, b_max - 1)
+       * That is, min(0, b_min + 1) <= floormod(a, b) <= max(0, b_max - 1)
+       */
+      int64_t b_min_cap = InfAwareAdd(b.min_value, 1);

Review comment:
       Sure. Thanks for the suggestion.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org