summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/RemoveUnusedBrs.cpp15
-rw-r--r--test/emcc_O2_hello_world.fromasm68
-rw-r--r--test/emcc_hello_world.fromasm105
-rw-r--r--test/passes/O.txt205
-rw-r--r--test/passes/remove-unused-brs.txt17
-rw-r--r--test/passes/remove-unused-brs.wast16
-rw-r--r--test/unit.fromasm42
7 files changed, 246 insertions, 222 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 245642055..c7fa43df9 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -28,7 +28,15 @@ struct RemoveUnusedBrs : public WalkerPass<WasmWalker<RemoveUnusedBrs>> {
// specifically for if-else, turn an if-else with branches to the same target at the end of each
// child, and with a value, to a branch to that target containing the if-else
void visitIf(If* curr) {
- if (!curr->ifFalse) return;
+ if (!curr->ifFalse) {
+ // try to reduce an if (condition) br => br_if (condition) , which might open up other optimization opportunities
+ Break* br = curr->ifTrue->dyn_cast<Break>();
+ if (br && !br->condition) { // TODO: if there is a condition, join them
+ br->condition = curr->condition;
+ replaceCurrent(br);
+ }
+ return;
+ }
if (curr->type != none) return; // already has a returned value
// an if_else that indirectly returns a value by breaking to the same target can potentially remove both breaks, and break outside once
auto getLast = [](Expression *side) -> Expression* {
@@ -66,9 +74,10 @@ struct RemoveUnusedBrs : public WalkerPass<WasmWalker<RemoveUnusedBrs>> {
void visitBlock(Block *curr) {
if (curr->name.isNull()) return;
if (curr->list.size() == 0) return;
- // preparation - remove all code after a break, since it can't execute, and it might confuse us (we look at the last)
+ // preparation - remove all code after an unconditional break, since it can't execute, and it might confuse us (we look at the last)
for (size_t i = 0; i < curr->list.size()-1; i++) {
- if (curr->list[i]->is<Break>()) {
+ Break* br = curr->list[i]->dyn_cast<Break>();
+ if (br && !br->condition) {
curr->list.resize(i+1);
break;
}
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index 57bbe33bc..574759517 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -1304,12 +1304,12 @@
(get_local $i24)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i24)
(i32.const 0)
)
- (br $do-once$8)
+ $do-once$8
)
)
)
@@ -2647,12 +2647,12 @@
(get_local $i45)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i45)
(i32.const 0)
)
- (br $do-once$17)
+ $do-once$17
)
)
)
@@ -3982,7 +3982,7 @@
(i32.const 616)
)
)
- (if
+ (br_if
(if_else
(i32.ne
(get_local $i45)
@@ -4000,7 +4000,7 @@
)
(i32.const 0)
)
- (br $do-once$25)
+ $do-once$25
)
(set_local $i45
(call_import $_sbrk
@@ -4966,12 +4966,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i54)
(i32.const 0)
)
- (br $label$break$L331)
+ $label$break$L331
)
(set_local $i55
(i32.load align=4
@@ -5033,12 +5033,12 @@
(get_local $i72)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i72)
(i32.const 0)
)
- (br $label$break$L331)
+ $label$break$L331
)
)
(block
@@ -5046,9 +5046,9 @@
(get_local $i5)
(get_local $i72)
)
- (if
+ (br_if
(get_local $i72)
- (br $do-once$36)
+ $do-once$36
)
(i32.store align=4
(i32.const 180)
@@ -5136,12 +5136,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i45)
(i32.const 0)
)
- (br $label$break$L331)
+ $label$break$L331
)
(if_else
(i32.lt_u
@@ -5213,7 +5213,7 @@
)
(call_import $_abort)
)
- (if
+ (br_if
(i32.eq
(i32.load align=4
(i32.add
@@ -5223,7 +5223,7 @@
)
(get_local $i43)
)
- (br $do-once$38)
+ $do-once$38
)
(call_import $_abort)
)
@@ -7061,12 +7061,12 @@
(local $i36 i32)
(local $i37 i32)
(block $topmost
- (if
+ (br_if
(i32.eq
(get_local $i1)
(i32.const 0)
)
- (br $topmost)
+ $topmost
)
(set_local $i2
(i32.add
@@ -7134,12 +7134,12 @@
(get_local $i2)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i1)
(i32.const 0)
)
- (br $topmost)
+ $topmost
)
(set_local $i8
(i32.add
@@ -7926,14 +7926,14 @@
(i32.const 1)
)
)
- (if
+ (br_if
(i32.ne
(get_local $i12)
(i32.load align=4
(i32.const 196)
)
)
- (br $topmost)
+ $topmost
)
(i32.store align=4
(i32.const 196)
@@ -8330,12 +8330,12 @@
(get_local $i23)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i23)
(i32.const 0)
)
- (br $do-once$5)
+ $do-once$5
)
)
)
@@ -10664,17 +10664,16 @@
(func $_memcpy (param $i1 i32) (param $i2 i32) (param $i3 i32) (result i32)
(local $i4 i32)
(block $topmost
- (if
+ (br_if
(i32.ge_s
(get_local $i3)
(i32.const 4096)
)
- (br $topmost
- (call_import $_emscripten_memcpy_big
- (get_local $i1)
- (get_local $i2)
- (get_local $i3)
- )
+ $topmost
+ (call_import $_emscripten_memcpy_big
+ (get_local $i1)
+ (get_local $i2)
+ (get_local $i3)
)
)
(set_local $i4
@@ -10701,14 +10700,13 @@
(nop)
(br $while-out$0)
)
- (if
+ (br_if
(i32.eq
(get_local $i3)
(i32.const 0)
)
- (br $topmost
- (get_local $i4)
- )
+ $topmost
+ (get_local $i4)
)
(i32.store8 align=1
(get_local $i1)
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index abccc648f..bc32b67e4 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -12364,12 +12364,12 @@
(i32.const 0)
)
)
- (if
+ (br_if
(i32.eq
(get_local $$tobool$i$449$i)
(i32.const 0)
)
- (br $do-once$95)
+ $do-once$95
)
(call $___fwritex
(i32.const 4143)
@@ -12930,12 +12930,12 @@
(i32.const 0)
)
)
- (if
+ (br_if
(i32.eq
(get_local $$tobool$i$i)
(i32.const 0)
)
- (br $do-once$89)
+ $do-once$89
)
(set_local $$sub$ptr$rhs$cast812$i
(get_local $$estr$2$i)
@@ -19092,9 +19092,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp126$i)
- (br $do-once$8)
+ $do-once$8
)
)
)
@@ -20928,9 +20928,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp217$i)
- (br $do-once$17)
+ $do-once$17
)
)
)
@@ -22780,9 +22780,9 @@
(get_local $$cmp66$i$190)
)
)
- (if
+ (br_if
(get_local $$or$cond2$i)
- (br $do-once$25)
+ $do-once$25
)
)
)
@@ -24166,9 +24166,9 @@
(get_local $$add$ptr16$i$i)
)
)
- (if
+ (br_if
(get_local $$cmp44$i$i)
- (br $do-once$35)
+ $do-once$35
)
(call_import $_abort)
)
@@ -24569,9 +24569,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp120$i$53$i)
- (br $label$break$L331)
+ $label$break$L331
)
(set_local $$index$i$54$i
(i32.add
@@ -24618,12 +24618,12 @@
(i32.const 0)
)
)
- (if
+ (br_if
(i32.eq
(get_local $$cond2$i$i)
(i32.const 0)
)
- (br $do-once$40)
+ $do-once$40
)
(set_local $$shl131$i$i
(i32.shl
@@ -24712,9 +24712,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp156$i$i)
- (br $label$break$L331)
+ $label$break$L331
)
)
)
@@ -24821,9 +24821,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp185$i$i)
- (br $label$break$L331)
+ $label$break$L331
)
(set_local $$171
(i32.load align=4
@@ -27306,9 +27306,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp)
- (br $topmost)
+ $topmost
)
(set_local $$add$ptr
(i32.add
@@ -27397,9 +27397,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp13)
- (br $topmost)
+ $topmost
)
(set_local $$idx$neg
(i32.sub
@@ -28481,12 +28481,12 @@
(get_local $$31)
)
)
- (if
+ (br_if
(i32.eq
(get_local $$cmp249)
(i32.const 0)
)
- (br $topmost)
+ $topmost
)
(i32.store align=4
(i32.const 196)
@@ -29226,9 +29226,9 @@
(i32.const 0)
)
)
- (if
+ (br_if
(get_local $$cmp432)
- (br $do-once$5)
+ $do-once$5
)
)
)
@@ -30598,17 +30598,16 @@
(func $_memcpy (param $dest i32) (param $src i32) (param $num i32) (result i32)
(local $ret i32)
(block $topmost
- (if
+ (br_if
(i32.ge_s
(get_local $num)
(i32.const 4096)
)
- (br $topmost
- (call_import $_emscripten_memcpy_big
- (get_local $dest)
- (get_local $src)
- (get_local $num)
- )
+ $topmost
+ (call_import $_emscripten_memcpy_big
+ (get_local $dest)
+ (get_local $src)
+ (get_local $num)
)
)
(set_local $ret
@@ -30635,14 +30634,13 @@
(nop)
(br $while-out$0)
)
- (if
+ (br_if
(i32.eq
(get_local $num)
(i32.const 0)
)
- (br $topmost
- (get_local $ret)
- )
+ $topmost
+ (get_local $ret)
)
(i32.store8 align=1
(get_local $dest)
@@ -30826,14 +30824,13 @@
)
)
)
- (if
+ (br_if
(i32.lt_s
(get_local $ret)
(i32.const 8)
)
- (br $topmost
- (get_local $ret)
- )
+ $topmost
+ (get_local $ret)
)
(set_local $ret
(i32.load8_s align=1
@@ -30851,16 +30848,15 @@
)
)
)
- (if
+ (br_if
(i32.lt_s
(get_local $ret)
(i32.const 8)
)
- (br $topmost
- (i32.add
- (get_local $ret)
- (i32.const 8)
- )
+ $topmost
+ (i32.add
+ (get_local $ret)
+ (i32.const 8)
)
)
(set_local $ret
@@ -30879,16 +30875,15 @@
)
)
)
- (if
+ (br_if
(i32.lt_s
(get_local $ret)
(i32.const 8)
)
- (br $topmost
- (i32.add
- (get_local $ret)
- (i32.const 16)
- )
+ $topmost
+ (i32.add
+ (get_local $ret)
+ (i32.const 16)
)
)
(i32.add
diff --git a/test/passes/O.txt b/test/passes/O.txt
index 090388d1b..28255f4d1 100644
--- a/test/passes/O.txt
+++ b/test/passes/O.txt
@@ -1219,12 +1219,12 @@
(get_local $i13)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i13)
(i32.const 0)
)
- (br $do-once$8)
+ $do-once$8
)
)
)
@@ -1904,12 +1904,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i1)
(i32.const 0)
)
- (br $do-once$0)
+ $do-once$0
)
(set_local $i16
(i32.add
@@ -2468,12 +2468,12 @@
(get_local $i18)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i18)
(i32.const 0)
)
- (br $do-once$17)
+ $do-once$17
)
)
)
@@ -3783,7 +3783,7 @@
(i32.const 4100)
)
)
- (if
+ (br_if
(if_else
(i32.ne
(get_local $i21)
@@ -3801,7 +3801,7 @@
)
(i32.const 0)
)
- (br $do-once$25)
+ $do-once$25
)
(set_local $i2
(call_import $_sbrk
@@ -4732,12 +4732,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i7)
(i32.const 0)
)
- (br $label$break$L331)
+ $label$break$L331
)
(set_local $i2
(i32.load align=4
@@ -4799,12 +4799,12 @@
(get_local $i35)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i35)
(i32.const 0)
)
- (br $label$break$L331)
+ $label$break$L331
)
)
(block
@@ -4812,9 +4812,9 @@
(get_local $i3)
(get_local $i35)
)
- (if
+ (br_if
(get_local $i35)
- (br $do-once$36)
+ $do-once$36
)
(i32.store align=4
(i32.const 3664)
@@ -4902,12 +4902,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i2)
(i32.const 0)
)
- (br $label$break$L331)
+ $label$break$L331
)
(if_else
(i32.lt_u
@@ -4979,7 +4979,7 @@
)
(call_import $_abort)
)
- (if
+ (br_if
(i32.eq
(i32.load align=4
(i32.add
@@ -4989,7 +4989,7 @@
)
(get_local $i1)
)
- (br $do-once$38)
+ $do-once$38
)
(call_import $_abort)
)
@@ -7105,7 +7105,7 @@
(set_local $i26
(i32.const 0)
)
- (if
+ (br_if
(i32.ne
(i32.load8_s align=1
(i32.add
@@ -7115,7 +7115,7 @@
)
(i32.const 37)
)
- (br $label$break$L12)
+ $label$break$L12
)
(set_local $i4
(i32.add
@@ -9204,7 +9204,7 @@
(i32.const 1)
)
(block
- (if
+ (br_if
(i32.and
(get_local $i5)
(i32.and
@@ -9215,7 +9215,7 @@
)
)
)
- (br $do-once$55)
+ $do-once$55
)
(i32.store8 align=1
(get_local $i3)
@@ -9624,12 +9624,12 @@
)
)
(loop $while-out$63 $while-in$64
- (if
+ (br_if
(i32.le_u
(get_local $i5)
(get_local $i7)
)
- (br $while-out$63)
+ $while-out$63
)
(set_local $i4
(i32.add
@@ -10177,14 +10177,14 @@
(if
(get_local $i21)
(block
- (if
+ (br_if
(i32.ne
(i32.load8_s align=1
(get_local $i22)
)
(i32.const 45)
)
- (br $do-once$76)
+ $do-once$76
)
(set_local $d13
(f64.neg
@@ -10507,9 +10507,9 @@
(i32.const 8)
)
)
- (if
+ (br_if
(get_local $i5)
- (br $do-once$83)
+ $do-once$83
)
(block $do-once$84
(if_else
@@ -10906,12 +10906,12 @@
(get_local $i7)
)
(block
- (if
+ (br_if
(i32.ne
(get_local $i5)
(get_local $i33)
)
- (br $do-once$92)
+ $do-once$92
)
(i32.store8 align=1
(get_local $i35)
@@ -10922,12 +10922,12 @@
)
)
(block
- (if
+ (br_if
(i32.le_u
(get_local $i5)
(get_local $i46)
)
- (br $do-once$92)
+ $do-once$92
)
(call $_memset
(get_local $i46)
@@ -10992,14 +10992,14 @@
(if
(get_local $i11)
(block
- (if
+ (br_if
(i32.and
(i32.load align=4
(get_local $i50)
)
(i32.const 32)
)
- (br $do-once$95)
+ $do-once$95
)
(call $___fwritex
(i32.const 3610)
@@ -11258,12 +11258,12 @@
)
)
(block
- (if
+ (br_if
(i32.le_u
(get_local $i4)
(get_local $i46)
)
- (br $do-once$102)
+ $do-once$102
)
(call $_memset
(get_local $i46)
@@ -11358,14 +11358,14 @@
(i32.const 18)
(i32.const 0)
)
- (if
+ (br_if
(i32.and
(i32.load align=4
(get_local $i50)
)
(i32.const 32)
)
- (br $do-once$89)
+ $do-once$89
)
(call $___fwritex
(get_local $i10)
@@ -11831,12 +11831,12 @@
(get_local $i9)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i7)
(i32.const 0)
)
- (br $while-out$109)
+ $while-out$109
)
(set_local $i4
(call $_wctomb
@@ -11844,7 +11844,7 @@
(get_local $i7)
)
)
- (if
+ (br_if
(i32.or
(i32.lt_s
(get_local $i4)
@@ -11858,7 +11858,7 @@
)
)
)
- (br $while-out$109)
+ $while-out$109
)
(set_local $i5
(i32.add
@@ -12287,12 +12287,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i2)
(i32.const 0)
)
- (br $while-out$113)
+ $while-out$113
)
(call $_pop_arg_529
(i32.add
@@ -12403,12 +12403,12 @@
(local $i15 i32)
(local $i16 i32)
(block $topmost
- (if
+ (br_if
(i32.eq
(get_local $i1)
(i32.const 0)
)
- (br $topmost)
+ $topmost
)
(set_local $i3
(i32.add
@@ -12476,12 +12476,12 @@
(get_local $i3)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i2)
(i32.const 0)
)
- (br $topmost)
+ $topmost
)
(set_local $i10
(i32.add
@@ -13247,14 +13247,14 @@
(i32.const 1)
)
)
- (if
+ (br_if
(i32.ne
(get_local $i16)
(i32.load align=4
(i32.const 3680)
)
)
- (br $topmost)
+ $topmost
)
(i32.store align=4
(i32.const 3680)
@@ -13630,12 +13630,12 @@
(get_local $i13)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i13)
(i32.const 0)
)
- (br $do-once$5)
+ $do-once$5
)
)
)
@@ -15973,12 +15973,12 @@
(i32.const -1)
)
)
- (if
+ (br_if
(i32.gt_s
(get_local $i19)
(i32.const 1)
)
- (br $label$continue$L5)
+ $label$continue$L5
)
(set_local $i3
(i32.add
@@ -16369,12 +16369,12 @@
(i32.const -1)
)
)
- (if
+ (br_if
(i32.gt_s
(get_local $i19)
(i32.const 1)
)
- (br $label$continue$L35)
+ $label$continue$L35
)
(set_local $i1
(i32.add
@@ -16694,12 +16694,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i1)
(get_local $i9)
)
- (br $label$break$L9)
+ $label$break$L9
)
(loop $while-out$10 $while-in$11
(set_local $i5
@@ -16791,12 +16791,12 @@
(i32.const -1)
)
)
- (if
+ (br_if
(i32.gt_s
(get_local $i12)
(i32.const 1)
)
- (br $while-out$10)
+ $while-out$10
)
(set_local $i1
(i32.add
@@ -16804,12 +16804,12 @@
(i32.const 1)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i1)
(get_local $i9)
)
- (br $label$break$L9)
+ $label$break$L9
)
(br $while-in$11)
)
@@ -16878,12 +16878,12 @@
)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i1)
(get_local $i9)
)
- (br $label$break$L9)
+ $label$break$L9
)
(loop $while-out$18 $while-in$19
(set_local $i5
@@ -16975,12 +16975,12 @@
(i32.const -1)
)
)
- (if
+ (br_if
(i32.gt_s
(get_local $i12)
(i32.const 1)
)
- (br $while-out$18)
+ $while-out$18
)
(set_local $i1
(i32.add
@@ -16988,12 +16988,12 @@
(i32.const 1)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i1)
(get_local $i9)
)
- (br $label$break$L9)
+ $label$break$L9
)
(br $while-in$19)
)
@@ -18587,7 +18587,7 @@
(get_local $i3)
)
)
- (if
+ (br_if
(i32.and
(i32.xor
(i32.and
@@ -18601,7 +18601,7 @@
(i32.const -16843009)
)
)
- (br $while-out$2)
+ $while-out$2
)
(set_local $i1
(i32.add
@@ -18653,7 +18653,7 @@
)
)
(loop $while-out$4 $while-in$5
- (if
+ (br_if
(i32.eq
(i32.load8_s align=1
(get_local $i1)
@@ -18666,7 +18666,7 @@
(i32.const 24)
)
)
- (br $label$break$L8)
+ $label$break$L8
)
(set_local $i1
(i32.add
@@ -18860,7 +18860,7 @@
)
(br $while-in$1)
)
- (if
+ (br_if
(i32.lt_u
(call_indirect $FUNCSIG$iiii
(i32.add
@@ -18881,7 +18881,7 @@
)
(get_local $i1)
)
- (br $label$break$L5)
+ $label$break$L5
)
(set_local $i4
(i32.sub
@@ -19802,12 +19802,12 @@
(br $do-once$0)
)
)
- (if
+ (br_if
(i32.eq
(get_local $i3)
(i32.const 0)
)
- (br $do-once$0)
+ $do-once$0
)
)
(call $___fwritex
@@ -20569,17 +20569,16 @@
(func $_memcpy (param $i1 i32) (param $i4 i32) (param $i2 i32) (result i32)
(local $i3 i32)
(block $topmost
- (if
+ (br_if
(i32.ge_s
(get_local $i2)
(i32.const 4096)
)
- (br $topmost
- (call_import $_emscripten_memcpy_big
- (get_local $i1)
- (get_local $i4)
- (get_local $i2)
- )
+ $topmost
+ (call_import $_emscripten_memcpy_big
+ (get_local $i1)
+ (get_local $i4)
+ (get_local $i2)
)
)
(set_local $i3
@@ -20606,14 +20605,13 @@
(nop)
(br $while-out$0)
)
- (if
+ (br_if
(i32.eq
(get_local $i2)
(i32.const 0)
)
- (br $topmost
- (get_local $i3)
- )
+ $topmost
+ (get_local $i3)
)
(i32.store8 align=1
(get_local $i1)
@@ -20866,14 +20864,14 @@
(get_local $i4)
)
(loop $while-out$0 $while-in$1
- (if
+ (br_if
(i32.eq
(i32.load8_s align=1
(get_local $i2)
)
(i32.const 0)
)
- (br $label$break$L1)
+ $label$break$L1
)
(set_local $i2
(i32.add
@@ -21952,14 +21950,13 @@
)
)
)
- (if
+ (br_if
(i32.lt_s
(get_local $i1)
(i32.const 8)
)
- (br $topmost
- (get_local $i1)
- )
+ $topmost
+ (get_local $i1)
)
(set_local $i1
(i32.load8_s align=1
@@ -21977,16 +21974,15 @@
)
)
)
- (if
+ (br_if
(i32.lt_s
(get_local $i1)
(i32.const 8)
)
- (br $topmost
- (i32.add
- (get_local $i1)
- (i32.const 8)
- )
+ $topmost
+ (i32.add
+ (get_local $i1)
+ (i32.const 8)
)
)
(set_local $i1
@@ -22005,16 +22001,15 @@
)
)
)
- (if
+ (br_if
(i32.lt_s
(get_local $i1)
(i32.const 8)
)
- (br $topmost
- (i32.add
- (get_local $i1)
- (i32.const 16)
- )
+ $topmost
+ (i32.add
+ (get_local $i1)
+ (i32.const 16)
)
)
(i32.add
diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt
index 5f65d04d6..5759203b4 100644
--- a/test/passes/remove-unused-brs.txt
+++ b/test/passes/remove-unused-brs.txt
@@ -147,4 +147,21 @@
)
)
)
+ (func $b15
+ (block $topmost
+ (br_if
+ (i32.const 17)
+ $topmost
+ )
+ )
+ )
+ (func $b15 (result i32)
+ (block $topmost
+ (br_if
+ (i32.const 18)
+ $topmost
+ (i32.const 0)
+ )
+ )
+ )
)
diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast
index 8f90c75b0..ddf5e2fa7 100644
--- a/test/passes/remove-unused-brs.wast
+++ b/test/passes/remove-unused-brs.wast
@@ -137,5 +137,21 @@
)
)
)
+ (func $b15
+ (block $topmost
+ (if
+ (i32.const 17)
+ (br $topmost)
+ )
+ )
+ )
+ (func $b15 (result i32)
+ (block $topmost
+ (if
+ (i32.const 18)
+ (br $topmost (i32.const 0))
+ )
+ )
+ )
)
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 7eaf4029f..34990e297 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -53,27 +53,25 @@
)
)
)
- (if
+ (br_if
(i32.gt_s
(i32.load align=4
(i32.const 24)
)
(i32.const 0)
)
- (br $topmost
- (f64.const -3.4)
- )
+ $topmost
+ (f64.const -3.4)
)
- (if
+ (br_if
(f64.gt
(f64.load align=8
(i32.const 32)
)
(f64.const 0)
)
- (br $topmost
- (f64.const 5.6)
- )
+ $topmost
+ (f64.const 5.6)
)
(f64.const 1.2)
)
@@ -83,41 +81,37 @@
(local $Int f64)
(local $Double i32)
(block $topmost
- (if
+ (br_if
(f64.gt
(get_local $x)
(f64.const 0)
)
- (br $topmost
- (f64.const 1.2)
- )
+ $topmost
+ (f64.const 1.2)
)
- (if
+ (br_if
(f64.gt
(get_local $Int)
(f64.const 0)
)
- (br $topmost
- (f64.const -3.4)
- )
+ $topmost
+ (f64.const -3.4)
)
- (if
+ (br_if
(i32.gt_s
(get_local $Double)
(i32.const 0)
)
- (br $topmost
- (f64.const 5.6)
- )
+ $topmost
+ (f64.const 5.6)
)
- (if
+ (br_if
(f64.lt
(get_local $x)
(get_local $y)
)
- (br $topmost
- (get_local $x)
- )
+ $topmost
+ (get_local $x)
)
(get_local $y)
)