From 1d71097311af5be7368dbd043c44b06fc8d28ad3 Mon Sep 17 00:00:00 2001 From: Sergei Grechanik Date: Tue, 16 Apr 2019 19:37:45 +0300 Subject: [PATCH] [ARITH] Fix x||!x for comparisons in rewrite simplifier (#3029) --- src/arithmetic/rewrite_simplify.cc | 2 +- tests/python/unittest/test_arith_rewrite_simplify.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arithmetic/rewrite_simplify.cc b/src/arithmetic/rewrite_simplify.cc index 1ebb328925d0..6098faa44846 100644 --- a/src/arithmetic/rewrite_simplify.cc +++ b/src/arithmetic/rewrite_simplify.cc @@ -1169,7 +1169,7 @@ Mutate_(const Or* op, const Expr& self) { TVM_TRY_REWRITE(x != y || x == y, ctrue); TVM_TRY_REWRITE(x || !x, ctrue); TVM_TRY_REWRITE(x <= y || y < x, ctrue); - TVM_TRY_REWRITE(y < x || y <= x, ctrue); + TVM_TRY_REWRITE(y < x || x <= y, ctrue); TVM_TRY_REWRITE_IF(x < c1 || c2 < x, ctrue, c2.Eval()->value < c1.Eval()->value); diff --git a/tests/python/unittest/test_arith_rewrite_simplify.py b/tests/python/unittest/test_arith_rewrite_simplify.py index e752d7c632ab..be961a5c6543 100644 --- a/tests/python/unittest/test_arith_rewrite_simplify.py +++ b/tests/python/unittest/test_arith_rewrite_simplify.py @@ -508,10 +508,10 @@ def test_logical_simplify(): tvm.const(True, "bool")) ck.verify(tvm.expr.Or(tvm.expr.NE(x, y), tvm.expr.EQ(x, y)), tvm.const(True, "bool")) - ck.verify(tvm.expr.Or(x > y, tvm.expr.Not(x < y)), tvm.const(True, "bool")) + ck.verify(tvm.expr.Or(x > y, tvm.expr.Not(x > y)), tvm.const(True, "bool")) ck.verify(tvm.expr.Or(x <= y, y < x), tvm.const(True, "bool")) - ck.verify(tvm.expr.Or(y < x, y <= x), tvm.const(True, "bool")) + ck.verify(tvm.expr.Or(y < x, y >= x), tvm.const(True, "bool")) ck.verify(tvm.expr.Or(x < 1, 0 < x), tvm.const(True, "bool")) ck.verify(tvm.expr.Or(0 < x, x < 1), tvm.const(True, "bool"))