Skip to content

Commit

Permalink
Take zero extent loops as NoOp and remove it and add unittest for the…
Browse files Browse the repository at this point in the history
… same (#3724)
  • Loading branch information
umangyadav authored and tqchen committed Aug 7, 2019
1 parent 6b6e388 commit 3d8b75c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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()

0 comments on commit 3d8b75c

Please sign in to comment.