Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/tir/transforms/remove_no_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class NoOpRemover : public arith::IRMutatorWithAnalyzer {
Stmt VisitStmt_(const IfThenElseNode* op) final {
Stmt stmt = Parent::VisitStmt_(op);
op = stmt.as<IfThenElseNode>();
// Sometimes the condition can be statically determined,
// in which the type of the `stmt` will not be IfThenElseNode.
if (!op) {
return stmt;
}
if (op->else_case) {
bool no_op_else = is_no_op(op->else_case.value());
bool no_op_then = is_no_op(op->then_case);
Expand Down
14 changes: 14 additions & 0 deletions tests/python/unittest/test_tir_transform_remove_no_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,5 +603,19 @@ def expected(A: T.Buffer[16, "int32"], C: T.Buffer[1, "int32"]):
C[0] = C[0] + B[i]


class TestCertainConditon(BaseBeforeAfter):
"""The conditon of the If-Else node is certain.
This would cause `Segmentation fault` error before."""

def before():
if True:
T.evaluate(0)
else:
T.evaluate(0)

def expected():
T.evaluate(0)


if __name__ == "__main__":
tvm.testing.main()