Skip to content

Commit

Permalink
[TIR]Fix the crash of the pass RemoveNoOp (apache#13808)
Browse files Browse the repository at this point in the history
Fix the crash of the pass RemoveNoOp.

Co-authored-by: lightzhan-intellif <zhan.liang@intellif.com>
  • Loading branch information
2 people authored and fzi-peccia committed Mar 27, 2023
1 parent b516451 commit 53f5148
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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()

0 comments on commit 53f5148

Please sign in to comment.