tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] tqchen commented on a change in pull request #5749: [Simplify]fix a min/max simplify bug
Date Tue, 09 Jun 2020 16:39:46 GMT

tqchen commented on a change in pull request #5749:
URL: https://github.com/apache/incubator-tvm/pull/5749#discussion_r437108677



##########
File path: src/arith/rewrite_simplify.cc
##########
@@ -1026,7 +1026,9 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const MinNode* op) {
       int64_t c1val = c1.Eval()->value;
       int64_t c2val = c2.Eval()->value;
       if (c2val % c1val == 0) {
-        if (c2val / c1val >= 0) {
+        if (c2val == 0) {
+          return c1val > 0 ? (min(x, 0) * c1val).Eval() : (max(x, 0) * c1val).Eval();
+        } else if (c2val / c1val > 0) {

Review comment:
       Thanks @xqdan this rule seems also should applies to other cases when c1val is smaller
than 0, 
   
   e.g. (  `min(x * (-2),  -4)`), please also fix that case

##########
File path: src/arith/rewrite_simplify.cc
##########
@@ -1026,7 +1026,9 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const MinNode* op) {
       int64_t c1val = c1.Eval()->value;
       int64_t c2val = c2.Eval()->value;
       if (c2val % c1val == 0) {
-        if (c2val / c1val >= 0) {
+        if (c2val == 0) {
+          return c1val > 0 ? (min(x, 0) * c1val).Eval() : (max(x, 0) * c1val).Eval();
+        } else if (c2val / c1val > 0) {

Review comment:
       We should also fix the case for max

##########
File path: src/arith/rewrite_simplify.cc
##########
@@ -1026,7 +1026,9 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const MinNode* op) {
       int64_t c1val = c1.Eval()->value;
       int64_t c2val = c2.Eval()->value;
       if (c2val % c1val == 0) {
-        if (c2val / c1val >= 0) {
+        if (c2val == 0) {
+          return c1val > 0 ? (min(x, 0) * c1val).Eval() : (max(x, 0) * c1val).Eval();
+        } else if (c2val / c1val > 0) {

Review comment:
       We can change original line from `c2val / c1val >= 0` to `c1val > 0`.
   
   

##########
File path: src/arith/rewrite_simplify.cc
##########
@@ -1026,7 +1026,9 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const MinNode* op) {
       int64_t c1val = c1.Eval()->value;
       int64_t c2val = c2.Eval()->value;
       if (c2val % c1val == 0) {
-        if (c2val / c1val >= 0) {
+        if (c2val == 0) {
+          return c1val > 0 ? (min(x, 0) * c1val).Eval() : (max(x, 0) * c1val).Eval();
+        } else if (c2val / c1val > 0) {

Review comment:
       Let us also fix the (rare) special case, `(c1val == 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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message