diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-10-29 11:02:28 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-10-29 12:12:37 -0700 |
commit | 68bf64141dc4d35e6ff174fb68ce5bc50ff27c79 (patch) | |
tree | 45be7bbad13ed1eeaacfb7f9998076b4c96323a0 | |
parent | c7cb56099d6a3b8b1dfb540cc64f6572c1101ed4 (diff) | |
download | binaryen-68bf64141dc4d35e6ff174fb68ce5bc50ff27c79.tar.gz binaryen-68bf64141dc4d35e6ff174fb68ce5bc50ff27c79.tar.bz2 binaryen-68bf64141dc4d35e6ff174fb68ce5bc50ff27c79.zip |
fix break value removal in merge-blocks: a br_if's type changes without a value, so finalize the node, and remove the drop
-rw-r--r-- | src/passes/MergeBlocks.cpp | 11 | ||||
-rw-r--r-- | test/passes/merge-blocks.txt | 14 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp index f7fac9594..edfa1336b 100644 --- a/src/passes/MergeBlocks.cpp +++ b/src/passes/MergeBlocks.cpp @@ -116,8 +116,17 @@ struct BreakValueDropper : public ControlFlowWalker<BreakValueDropper, Visitor<B void visitBreak(Break* curr) { if (curr->value && curr->name == origin) { Builder builder(*getModule()); - replaceCurrent(builder.makeSequence(builder.makeDrop(curr->value), curr)); + auto* value = curr->value; curr->value = nullptr; + curr->finalize(); + replaceCurrent(builder.makeSequence(builder.makeDrop(value), curr)); + } + } + + void visitDrop(Drop* curr) { + // if we dropped a br_if whose value we removed, then we are now dropping a (block (drop value) (br_if)) with type none, which does not need a drop + if (curr->value->type == none) { + replaceCurrent(curr->value); } } }; diff --git a/test/passes/merge-blocks.txt b/test/passes/merge-blocks.txt index 152e6fbae..1116e0d28 100644 --- a/test/passes/merge-blocks.txt +++ b/test/passes/merge-blocks.txt @@ -29,14 +29,12 @@ (func $drop-block-br-if (type $0) (block $block (block $x - (drop - (block i32 - (drop - (i32.const 1) - ) - (br_if $x - (i32.const 2) - ) + (block + (drop + (i32.const 1) + ) + (br_if $x + (i32.const 2) ) ) (drop |