From 8cb36c66366212b148e75623f34ba5a48181eecf Mon Sep 17 00:00:00 2001 From: xumingkuan Date: Mon, 20 Apr 2020 17:59:26 -0400 Subject: [PATCH] Eliminate WhileControlStmt with non-zero const conditions --- taichi/transforms/alg_simp.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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;