diff options
-rw-r--r-- | src/passes/MergeBlocks.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 4 | ||||
-rw-r--r-- | test/passes/merge-blocks.txt | 13 | ||||
-rw-r--r-- | test/passes/merge-blocks.wast | 13 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.txt | 13 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.wast | 13 |
6 files changed, 56 insertions, 2 deletions
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp index 455e54971..d32948bee 100644 --- a/src/passes/MergeBlocks.cpp +++ b/src/passes/MergeBlocks.cpp @@ -213,7 +213,7 @@ static void optimizeBlock(Block* curr, Module* module) { break; } } - if (changed) curr->finalize(); + if (changed) curr->finalize(curr->type); } void BreakValueDropper::visitBlock(Block* curr) { 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/merge-blocks.txt b/test/passes/merge-blocks.txt index dd496df2f..545438b1d 100644 --- a/test/passes/merge-blocks.txt +++ b/test/passes/merge-blocks.txt @@ -87,4 +87,17 @@ ) ) ) + (func $drop-block-squared-iloop (type $0) + (drop + (block $label$0 (result i32) + (block $label$1 + (drop + (loop $label$2 + (br $label$2) + ) + ) + ) + ) + ) + ) ) diff --git a/test/passes/merge-blocks.wast b/test/passes/merge-blocks.wast index 4b2f248e2..e998060c4 100644 --- a/test/passes/merge-blocks.wast +++ b/test/passes/merge-blocks.wast @@ -69,5 +69,18 @@ ) ) ) + (func $drop-block-squared-iloop + (drop + (block $label$0 (result i32) ;; this block's type should not change, so the drop remains none and valid + (drop + (block $label$1 + (loop $label$2 + (br $label$2) + ) + ) + ) + ) + ) + ) ) 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) + ) + ) + ) + ) + ) + ) ) |