diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-07-22 21:07:03 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2017-07-22 21:07:03 -0700 |
commit | 93dcb15eba5051f36dad86d479935dede6f0b05f (patch) | |
tree | 9cd4269fbc5a876ff98447a9d8d74cf1015b64d1 | |
parent | cfe0fa129be2022ba9521bbd9355bd4b0aa1f01d (diff) | |
download | binaryen-93dcb15eba5051f36dad86d479935dede6f0b05f.tar.gz binaryen-93dcb15eba5051f36dad86d479935dede6f0b05f.tar.bz2 binaryen-93dcb15eba5051f36dad86d479935dede6f0b05f.zip |
ignore untaken branches in determining block type
-rw-r--r-- | src/wasm/wasm.cpp | 4 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.txt | 13 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.wast | 13 |
3 files changed, 29 insertions, 1 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 4f5f46f0a..635d14354 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -109,18 +109,20 @@ struct TypeSeeker : public PostWalker<TypeSeeker> { Name targetName; std::vector<WasmType> types; + TypeSeeker(Expression* target, Name targetName) : target(target), targetName(targetName) { Expression* temp = target; walk(temp); } void visitBreak(Break* curr) { - if (curr->name == targetName) { + if (curr->name == targetName && BranchUtils::isBranchTaken(curr)) { types.push_back(curr->value ? curr->value->type : none); } } void visitSwitch(Switch* curr) { + if (!BranchUtils::isBranchTaken(curr)) return; for (auto name : curr->targets) { if (name == targetName) types.push_back(curr->value ? curr->value->type : none); } diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index 417bd3728..355f8a531 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -1035,4 +1035,17 @@ ) ) ) + (func $untaken-br-with-concrete-last-element (type $2) (result i32) + (block $label$8 (result i32) + (block $label$11 (result i32) + (block $label$14 + (br_if $label$8 + (br $label$11 + (i32.const 103) + ) + ) + ) + ) + ) + ) ) diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index d694bd4d0..e7c221fa4 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -919,5 +919,18 @@ ) ) ) + (func $untaken-br-with-concrete-last-element (result i32) + (block $label$8 (result i32) + (block $label$11 (result i32) + (block $label$14 + (br_if $label$14 + (br $label$11 + (i32.const 103) + ) + ) + ) + ) + ) + ) ) |