gemini-code-assist[bot] commented on code in PR #19832:
URL: https://github.com/apache/tvm/pull/19832#discussion_r3438428596


##########
src/arith/rewrite_simplify.cc:
##########
@@ -1249,15 +1249,15 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const 
FloorModNode* op) {
                            CanProveEqual(floordiv(y.Eval(), c1.Eval()), 0));
 
     TVM_TRY_REWRITE_IF(floormod(x * c1 + y, c2), floormod(x * floormod(c1, c2) 
+ y, c2),
-                       c2.Eval()->value > 0);
+                       c2.Eval()->value > 0 && c1.Eval()->value % 
c2.Eval()->value == 0);

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Since the rewrite is now restricted to cases where `c1 % c2 == 0`, 
`floormod(c1, c2)` will always evaluate to `0`. Therefore, `floormod(x * 
floormod(c1, c2) + y, c2)` simplifies directly to `floormod(y, c2)`. We can 
simplify the target expression directly to `floormod(y, c2)` to avoid 
unnecessary recursive simplification steps (such as multiplying by zero and 
adding zero).
   
   ```c
       TVM_TRY_REWRITE_IF(floormod(x * c1 + y, c2), floormod(y, c2),
                          c2.Eval()->value > 0 && c1.Eval()->value % 
c2.Eval()->value == 0);
   ```



##########
src/arith/rewrite_simplify.cc:
##########
@@ -1249,15 +1249,15 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const 
FloorModNode* op) {
                            CanProveEqual(floordiv(y.Eval(), c1.Eval()), 0));
 
     TVM_TRY_REWRITE_IF(floormod(x * c1 + y, c2), floormod(x * floormod(c1, c2) 
+ y, c2),
-                       c2.Eval()->value > 0);
+                       c2.Eval()->value > 0 && c1.Eval()->value % 
c2.Eval()->value == 0);
 
     // (x + 5) % 2 -> (x + 1) %2,  (x + 3) % 3 => x
     TVM_TRY_REWRITE_IF(
         floormod(x + c1, c2), floormod(x + floormod(c1, c2), c2),
         c2.Eval()->value > 0 && (c1.Eval()->value >= c2.Eval()->value || 
c1.Eval()->value < 0));
 
     TVM_TRY_REWRITE_IF(floormod(x + y * c1, c2), floormod(x + y * floormod(c1, 
c2), c2),
-                       c2.Eval()->value > 0);
+                       c2.Eval()->value > 0 && c1.Eval()->value % 
c2.Eval()->value == 0);

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Similarly, since `c1 % c2 == 0` implies `floormod(c1, c2) == 0`, the 
expression `floormod(x + y * floormod(c1, c2), c2)` simplifies directly to 
`floormod(x, c2)`. Rewriting directly to `floormod(x, c2)` avoids intermediate 
simplification overhead.
   
   ```c
       TVM_TRY_REWRITE_IF(floormod(x + y * c1, c2), floormod(x, c2),
                          c2.Eval()->value > 0 && c1.Eval()->value % 
c2.Eval()->value == 0);
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to