Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/arithmetic/canonical.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class Canonical::Internal : public IRMutator {
return Binary_(op, e, a.value, b.value);
}
if (is_const(a.value) && is_const(b.value)) {
return ComputeExpr<Mul>(a.value, b.value);
return ComputeExpr<Mod>(a.value, b.value);
} else if (is_const(b.value)) {
return SumModConst(a.AsSum(), b.value);
} else {
Expand Down
10 changes: 10 additions & 0 deletions tests/cpp/ir_simplify_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ TEST(IRSIMPLIFY, Mul) {
CHECK(is_zero(es));
}

TEST(IRSIMPLIFY, Mod) {
auto x = tvm::Integer(10);
auto y = tvm::Integer(12);
// Mod::make is used instead of % to avoid constant folding during
// calling operator%(x,y). Mod::make doesn't try constant folding,
// and therefore, the constant folding will be attempted in CanonicalSimplify
auto mod = tvm::ir::CanonicalSimplify(tvm::ir::Mod::make(x, y));
auto es = tvm::ir::CanonicalSimplify(mod - x);
CHECK(is_zero(es));
}
int main(int argc, char ** argv) {
testing::InitGoogleTest(&argc, argv);
testing::FLAGS_gtest_death_test_style = "threadsafe";
Expand Down