@@ -150,43 +150,26 @@ class BoundDeducer: public IRVisitor {
150150 // always use relax bound
151151 bool divided = analyzer_.CanProve (floormod (result_, operand) == 0 );
152152
153- // TODO(tvm-team): use floordiv, which could give better bound.
154- result_ = truncdiv (result_, operand);
153+ result_ = floordiv (result_, operand); // rounding down here
155154
156155 if (!divided) {
157- // Handle non-divisible case
158- // NOTE: this accounts for trunc div behavior.
159- bool target_is_non_neg = expr_map_[target_var].can_prove_non_negative ();
160-
161156 if (comp_op == kGreater ) {
157+ // System will round down in all the cases, so add one for result_ for kGreater
158+ // (x >= 3/2 --> x >= 2)
159+ // (x >= -3/2 --> x >= -1)
160+ // (x >= 3/-2 --> x >= -1)
161+ // (x >= -3/-2 --> x >= 2)
162162 result_ += 1 ;
163163 } else if (comp_op == kEqual ) {
164- // condition unsatisfiable as with trunc div, it will change the expression
164+ // condition unsatisfiable as with floor div, it will change the expression
165165 success_ = false ;
166166 return ;
167167 } else {
168- // NOTE: this is a bit sutble hack.
169- //
170- // condition:
171- // - x * operand <= result
172- // - operand > 0
173- // - x >= 0
174- //
175- // Then it is fine to deduce that x <= result / operand.
176- // - if result > 0, this division round down
177- // - if result < 0, (result / operand) rounds up and may violate the constraint
178- // however, given that x is always non-negative,
179- // it is fine to have this relaxed bound, given that the user of deduce bound
180- // will respect the bound of x
181- //
182- // TODO(tvm-team): think about a better API to incorporate constraint of x.
183- // e.g. specify an interval of x and return a bound
184- // that is in the interval and satisfies the condition.
185- if (target_is_non_neg && sign_operand == kPositive ) {
186- // do nothing
187- } else {
188- result_ -= 1 ;
189- }
168+ // System rounds down in all cases, do nothing for kLess.
169+ // ( x <= 3/2 --> x <= 1)
170+ // ( x <= -3/2 --> x <= -2)
171+ // ( x <= 3/-2 --> x <= -2)
172+ // ( x <= -3/-2 --> x <= 1)
190173 }
191174 }
192175 Visit (left ? op->a : op->b );
0 commit comments