Skip to content

Commit

Permalink
[PASS] More improvement of canonical (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored Aug 12, 2017
1 parent 3c2569a commit afa2086
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/arithmetic/canonical.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class Canonical::Internal : public IRMutator {
ret_entry_.max_level = stack_.back().max_level;
stack_.pop_back();
CHECK(expr.defined());
if (const IntImm* op = expr.as<IntImm>()) {
return Mutate_(op, expr);
}
return expr;
}
// call produce to get a cache entry.
Expand Down
10 changes: 10 additions & 0 deletions tests/python/unittest/test_pass_simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def test_basic():
assert str(ret.value) == "(m - 1)"


def test_canonical():
x = tvm.var("x")
z = tvm.const(3)
ret = tvm.ir_pass.CanonicalSimplify(x / (z*z) - x / (z*z))
assert(tvm.ir_pass.Equal(ret, 0))

ret = tvm.ir_pass.CanonicalSimplify(x / (z+z) - x / (z+z))
assert(tvm.ir_pass.Equal(ret, 0))

if __name__ == "__main__":
test_basic()
test_simplify()
test_canonical()

0 comments on commit afa2086

Please sign in to comment.