summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/RemoveUnusedBrs.cpp13
-rw-r--r--test/passes/remove-unused-brs_enable-multivalue.txt13
2 files changed, 8 insertions, 18 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 3c4723c7f..b867dc4c2 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -203,11 +203,14 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
if (skip > 0) {
flows.resize(size - skip);
}
- // drop a nop at the end of a block, which prevents a value flowing
- while (list.size() > 0 && list.back()->is<Nop>()) {
- list.resize(list.size() - 1);
- self->anotherCycle = true;
- }
+ }
+ // Drop a nop at the end of a block, which prevents a value flowing. Note
+ // that this is worth doing regardless of whether we have a name on this
+ // block or not (which the if right above us checks) - such a nop is
+ // always unneeded and can limit later optimizations.
+ while (list.size() > 0 && list.back()->is<Nop>()) {
+ list.resize(list.size() - 1);
+ self->anotherCycle = true;
}
// A value flowing is only valid if it is a value that the block actually
// flows out. If it is never reached, it does not flow out, and may be
diff --git a/test/passes/remove-unused-brs_enable-multivalue.txt b/test/passes/remove-unused-brs_enable-multivalue.txt
index 8240bba22..d3180299c 100644
--- a/test/passes/remove-unused-brs_enable-multivalue.txt
+++ b/test/passes/remove-unused-brs_enable-multivalue.txt
@@ -23,7 +23,6 @@
(drop
(i32.const 0)
)
- (nop)
)
)
)
@@ -46,7 +45,6 @@
(drop
(i32.const 0)
)
- (nop)
)
)
)
@@ -58,7 +56,6 @@
(drop
(i32.const 0)
)
- (nop)
)
)
)
@@ -140,7 +137,6 @@
(drop
(i32.const 1)
)
- (nop)
)
)
)
@@ -152,7 +148,6 @@
(drop
(i32.const 2)
)
- (nop)
)
)
)
@@ -231,7 +226,6 @@
(drop
(i32.const 0)
)
- (nop)
)
)
)
@@ -385,7 +379,6 @@
(drop
(i32.const 1)
)
- (nop)
)
)
(block $a20
@@ -393,7 +386,6 @@
(drop
(i32.const 2)
)
- (nop)
)
)
)
@@ -526,7 +518,6 @@
(block $out49
(block
(call $loops)
- (nop)
)
)
(br $in48)
@@ -997,7 +988,6 @@
(br_if $shape$6$continue
(local.get $0)
)
- (nop)
)
)
)
@@ -1790,7 +1780,6 @@
(drop
(i32.const 0)
)
- (nop)
)
)
)
@@ -2326,8 +2315,6 @@
(i32.const 0)
(block $label$3
(block
- (nop)
- (nop)
)
)
(return