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



##########
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:
       Just a suggestion: why don't you move this (very well done) explanation 
at the beginning of the function? It seems to cover more than just the `else` 
branch




----------------------------------------------------------------
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:
[email protected]


Reply via email to