From 24009bbd6d99b8c72d320effb9a3fbb0ac09600e Mon Sep 17 00:00:00 2001 From: xumingkuan Date: Mon, 20 Apr 2020 19:13:10 -0400 Subject: [PATCH] [opt] 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;