diff --git a/taichi/transforms/alg_simp.cpp b/taichi/transforms/alg_simp.cpp index ad8abff42d953..637c5b3f50924 100644 --- a/taichi/transforms/alg_simp.cpp +++ b/taichi/transforms/alg_simp.cpp @@ -74,6 +74,17 @@ class AlgSimp : public BasicStmtVisitor { } } + void visit(WhileControlStmt *stmt) override { + auto cond = stmt->cond->cast(); + if (!cond) + return; + if (!alg_is_zero(cond)) { + // this statement has no effect + stmt->parent->erase(stmt); + throw IRModified(); + } + } + static bool alg_is_zero(ConstStmt *stmt) { if (!stmt) return false;