Lunderberg commented on code in PR #13933:
URL: https://github.com/apache/tvm/pull/13933#discussion_r1109023351
##########
src/arith/rewrite_simplify.cc:
##########
@@ -1642,20 +1621,35 @@ PrimExpr RewriteSimplifier::Impl::ApplyRewriteRules(LT
ret) {
TVM_TRY_RECURSIVE_REWRITE(z < min(x, y), z < x && z < y);
TVM_TRY_RECURSIVE_REWRITE(z < max(x, y), z < x || z < y);
- TVM_TRY_RECURSIVE_REWRITE(x < c1 - y, x + y < c1);
- TVM_TRY_RECURSIVE_REWRITE(x < c1 + y, x - y < c1);
- TVM_TRY_RECURSIVE_REWRITE(c1 - y < x, c1 < x + y);
- TVM_TRY_RECURSIVE_REWRITE(c1 + y < x, c1 < x - y);
- TVM_TRY_RECURSIVE_REWRITE(x + c1 < c2, x < c2 - c1);
- TVM_TRY_RECURSIVE_REWRITE(x - c1 < c2, x < c2 + c1);
- TVM_TRY_REWRITE(x - c1 < 0, x < c1);
+ // TVM_TRY_REWRITE(c1 < x + c2, c1 - c2 < x);
+ // TVM_TRY_REWRITE(c1 < c2 - x, x < c2 - c1);
- TVM_TRY_RECURSIVE_REWRITE(x - 1 < y, x <= y);
- TVM_TRY_RECURSIVE_REWRITE(x < y + 1, x <= y);
- TVM_TRY_RECURSIVE_REWRITE(x + (-1) < y, x <= y);
- TVM_TRY_RECURSIVE_REWRITE(x < y - (-1), x <= y);
// clang-format on
+
+ TVM_TRY_RECURSIVE_REWRITE(matches_one_of(c1 < x + c2, c1 - x < c2), c1 -
c2 < x);
+ TVM_TRY_RECURSIVE_REWRITE(matches_one_of(c1 < c2 - x, x + c1 < c2), x < c2
- c1);
+ TVM_TRY_RECURSIVE_REWRITE(c1 < x - c2, c1 + c2 < x);
+ TVM_TRY_RECURSIVE_REWRITE(x - c2 < c1, x < c1 + c2);
+
+ TVM_TRY_RECURSIVE_REWRITE(x < c1 - y, x + y < c1);
Review Comment:
Huh, I guess so. Up until about 5 minutes ago, I thought that
`RewriteSimplifier` had a rule to rewrite `c1 + x` into `x + c1`, so this later
rule would never apply due to the constant on the LHS. However, it looks like
while multiplication does merge the constants to the right, addition does not
unless you use the canonical simplifier.
I've re-added the missing rules for `x < c1 + y` and `c1 + y < x`, and can
remove them if/when I make a PR to have the rewrite simplifier move additive
constants to the RHS.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]