diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-05-01 15:11:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-01 15:11:08 -0700 |
commit | b6d42e0c28460667d9e9c992833be668d0897362 (patch) | |
tree | 4b40df398f07064b4b7a956d7fd4e24564dce143 | |
parent | 5bd7b2869f9ec664fd3e8746c1d469a04566a548 (diff) | |
download | binaryen-b6d42e0c28460667d9e9c992833be668d0897362.tar.gz binaryen-b6d42e0c28460667d9e9c992833be668d0897362.tar.bz2 binaryen-b6d42e0c28460667d9e9c992833be668d0897362.zip |
handle a drop of an if with both arms unreachable, which is possible since wasm added if types, which mean the if can be i32 even if the arms are unreachable etc (#991)
-rw-r--r-- | src/passes/Vacuum.cpp | 6 | ||||
-rw-r--r-- | test/passes/vacuum.txt | 18 | ||||
-rw-r--r-- | test/passes/vacuum.wast | 18 |
3 files changed, 38 insertions, 4 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 63a098fc0..13b9c62fd 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -288,14 +288,12 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> { auto* iff = curr->value->dynCast<If>(); if (iff && iff->ifFalse && isConcreteWasmType(iff->type)) { // reuse the drop in both cases - if (iff->ifTrue->type == unreachable) { - assert(isConcreteWasmType(iff->ifFalse->type)); + if (iff->ifTrue->type == unreachable && isConcreteWasmType(iff->ifFalse->type)) { curr->value = iff->ifFalse; iff->ifFalse = curr; iff->type = none; replaceCurrent(iff); - } else if (iff->ifFalse->type == unreachable) { - assert(isConcreteWasmType(iff->ifTrue->type)); + } else if (iff->ifFalse->type == unreachable && isConcreteWasmType(iff->ifTrue->type)) { curr->value = iff->ifTrue; iff->ifTrue = curr; iff->type = none; diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt index dda7d8abf..f64ef0868 100644 --- a/test/passes/vacuum.txt +++ b/test/passes/vacuum.txt @@ -241,4 +241,22 @@ (i32.const 7) ) ) + (func $drop-if-both-unreachable (type $1) (param $0 i32) + (block $out + (drop + (if i32 + (get_local $0) + (br $out) + (br $out) + ) + ) + ) + (drop + (if i32 + (get_local $0) + (unreachable) + (unreachable) + ) + ) + ) ) diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast index 06dea2034..8b97b9386 100644 --- a/test/passes/vacuum.wast +++ b/test/passes/vacuum.wast @@ -445,4 +445,22 @@ (if (i32.const 0) (call $if-const (i32.const 4)) (call $if-const (i32.const 5))) (if (i32.const 6) (call $if-const (i32.const 7)) (call $if-const (i32.const 8))) ) + (func $drop-if-both-unreachable (param $0 i32) + (block $out + (drop + (if i32 + (get_local $0) + (br $out) + (br $out) + ) + ) + ) + (drop + (if i32 + (get_local $0) + (unreachable) + (unreachable) + ) + ) + ) ) |