Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take zero extent loops as NoOp and remove it #3724

Merged
merged 1 commit into from
Aug 7, 2019
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
3 changes: 3 additions & 0 deletions src/pass/remove_no_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class NoOpRemover : public IRMutator {
Stmt Mutate_(const For* op, const Stmt& s) final {
Stmt stmt = IRMutator::Mutate_(op, s);
op = stmt.as<For>();
if (is_zero(op->extent)) {
return Evaluate::make(0);
}
return is_no_op(op->body) ? MakeEvaluate({op->min, op->extent}) : stmt;
}
Stmt Mutate_(const Allocate* op, const Stmt& s) final {
Expand Down
5 changes: 4 additions & 1 deletion tests/python/unittest/test_pass_remove_no_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def test_remove_no_op():
i + 1)
stmt2 = tvm.make.Block(stmt, store)
assert(tvm.ir_pass.RemoveNoOp(stmt2) == store)

# remove zero extent loop
stmt3 = tvm.make.For(i, 0, 0, 0, 0, store)
ret = tvm.ir_pass.RemoveNoOp(stmt3)
assert(isinstance(ret, tvm.stmt.Evaluate))

if __name__ == "__main__":
test_remove_no_op()