wrongtest-intellif commented on code in PR #13936:
URL: https://github.com/apache/tvm/pull/13936#discussion_r1119892258
##########
src/arith/rewrite_simplify.cc:
##########
@@ -454,6 +460,14 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const
SubNode* op) {
TVM_TRY_REWRITE_IF(floordiv(x - y, c1) * c1 - x, 0 - floormod(x - y, c1) -
y,
c1.Eval()->value != 0);
+ TVM_TRY_RECURSIVE_REWRITE(
+ floordiv(x + c1, 2) - floordiv(x + c2, 2),
+ floormod(x, 2) * (floormod(c1, 2) - floormod(c2, 2)) + floordiv(c1, 2)
- floordiv(c2, 2));
Review Comment:
Could we add bracket to fast fold out `(floordiv(c1, 2) - floordiv(c2, 2))`
##########
src/arith/rewrite_simplify.cc:
##########
@@ -473,6 +487,9 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const SubNode*
op) {
floordiv(x - y, c1) * c3 - x * c2, (0 - floormod(x - y, c1) - y) * c2,
c1.Eval()->value != 0 && c3.Eval()->value == c1.Eval()->value *
c2.Eval()->value);
+ TVM_TRY_RECURSIVE_REWRITE(floordiv(x + 1, 2) - floormod(x, 2), floordiv(x,
2));
+ TVM_TRY_RECURSIVE_REWRITE(floordiv(x, 2) - floormod(x - 1, 2), floordiv(x
- 1, 2));
Review Comment:
Like above, `floormod(x - 1, 2)` -> `1 - x % 2`, then it seems apply `x // 2
+ x % 2` rule could achieve `(x + 1) // 2 - 1`
##########
src/arith/rewrite_simplify.cc:
##########
@@ -278,10 +278,16 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const
AddNode* op) {
TVM_TRY_REWRITE_IF(floordiv(floormod(x, c2) + c1, c2) + floordiv(x, c2),
floordiv(x + c1, c2),
c2.Eval()->value > 0);
+ TVM_TRY_REWRITE(floormod(x + 1, 2) + floormod(x, 2), OneWithTypeLike(x));
Review Comment:
`TVM_TRY_RECURSIVE_REWRITE_IF(floormod(x + c1, 2), floormod(x, 2) * (-1) +
1, floormod(c1.Eval()->value, 2) == 1);` would lead to `(x + 1) % 2` -> `1 - x
% 2`
Then it seems that rule 281 is already covered, if we rewrite recursively?
##########
src/arith/iter_affine_map.cc:
##########
@@ -898,6 +898,11 @@ class IterMapRewriter : public ExprMutator {
PrimExpr SplitFloorModConst(IterSplitExpr lhs, PrimExpr base, PrimExpr rhs);
static void AddToLhs(IterSumExprNode* lhs, IterSplitExpr rhs, int sign) {
+ if (sign < 0 && is_const_int(rhs->extent, 2)) {
Review Comment:
Could we add a cover case for the codepath?
--
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]