summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/MergeBlocks.cpp8
-rw-r--r--test/passes/merge-blocks.txt12
-rw-r--r--test/passes/merge-blocks.wast16
3 files changed, 35 insertions, 1 deletions
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp
index 8ffbb345d..2c983d991 100644
--- a/src/passes/MergeBlocks.cpp
+++ b/src/passes/MergeBlocks.cpp
@@ -122,6 +122,11 @@ struct BreakValueDropper : public ControlFlowWalker<BreakValueDropper> {
if (curr->value && curr->name == origin) {
Builder builder(*getModule());
auto* value = curr->value;
+ if (value->type == unreachable) {
+ // the break isn't even reached
+ replaceCurrent(value);
+ return;
+ }
curr->value = nullptr;
curr->finalize();
replaceCurrent(builder.makeSequence(builder.makeDrop(value), curr));
@@ -130,7 +135,8 @@ struct BreakValueDropper : public ControlFlowWalker<BreakValueDropper> {
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) {
+ // likewise, unreachable does not need to be dropped, so we just leave drops of concrete values
+ if (!isConcreteWasmType(curr->value->type)) {
replaceCurrent(curr->value);
}
}
diff --git a/test/passes/merge-blocks.txt b/test/passes/merge-blocks.txt
index 33f16785a..dd496df2f 100644
--- a/test/passes/merge-blocks.txt
+++ b/test/passes/merge-blocks.txt
@@ -1,6 +1,7 @@
(module
(type $0 (func))
(type $1 (func (param i32)))
+ (type $2 (func (result i32)))
(memory $0 0)
(func $drop-block (type $0)
(block $block
@@ -75,4 +76,15 @@
)
)
)
+ (func $drop-unreachable-br_if (type $2) (result i32)
+ (block $label$0 (result i32)
+ (block $label$2
+ (drop
+ (br $label$0
+ (i32.const 538976371)
+ )
+ )
+ )
+ )
+ )
)
diff --git a/test/passes/merge-blocks.wast b/test/passes/merge-blocks.wast
index a61027778..4b2f248e2 100644
--- a/test/passes/merge-blocks.wast
+++ b/test/passes/merge-blocks.wast
@@ -53,5 +53,21 @@
)
)
)
+ (func $drop-unreachable-br_if (result i32)
+ (block $label$0 (result i32)
+ (drop
+ (block $label$2
+ (drop
+ (br_if $label$2
+ (br $label$0
+ (i32.const 538976371)
+ )
+ (i32.const 1918987552)
+ )
+ )
+ )
+ )
+ )
+ )
)