Commit 3d8b75cb by Umang Yadav Committed by Tianqi Chen

Take zero extent loops as NoOp and remove it and add unittest for the same (#3724)

parent 6b6e3888
......@@ -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 {
......
......@@ -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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment