Skip to content

Commit

Permalink
[opt] Eliminate WhileControlStmt with non-zero const conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
xumingkuan authored Apr 20, 2020
1 parent 1046995 commit 24009bb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions taichi/transforms/alg_simp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ class AlgSimp : public BasicStmtVisitor {
}
}

void visit(WhileControlStmt *stmt) override {
auto cond = stmt->cond->cast<ConstStmt>();
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;
Expand Down

0 comments on commit 24009bb

Please sign in to comment.