diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-12-04 12:33:36 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-04 12:33:36 -0800 |
commit | 26ef829628b1dd0d4b36a173e3db53a8b148f8b0 (patch) | |
tree | 0b3ebca72a668378a83b3384ab04095addb2686c | |
parent | b650f20121d7e1e79c12e6abfaf317f0d00e5f3b (diff) | |
download | binaryen-26ef829628b1dd0d4b36a173e3db53a8b148f8b0.tar.gz binaryen-26ef829628b1dd0d4b36a173e3db53a8b148f8b0.tar.bz2 binaryen-26ef829628b1dd0d4b36a173e3db53a8b148f8b0.zip |
remove unnecessary constraint on remove-unused-br optimization of if-br-* into br_if,* - we can handle a concretely typed if as well, which can happen at the end of a block (#1799)
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 2 | ||||
-rw-r--r-- | test/lld/hello_world.wast.mem | bin | 0 -> 581 bytes | |||
-rw-r--r-- | test/passes/remove-unused-brs.txt | 38 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.wast | 21 |
4 files changed, 52 insertions, 9 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 361e57ad6..cb3ff69ee 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -633,7 +633,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { auto& list = curr->list; for (Index i = 0; i < list.size(); i++) { auto* iff = list[i]->dynCast<If>(); - if (!iff || !iff->ifFalse || isConcreteType(iff->type)) continue; // if it lacked an if-false, it would already be a br_if, as that's the easy case + if (!iff || !iff->ifFalse) continue; // if it lacked an if-false, it would already be a br_if, as that's the easy case auto* ifTrueBreak = iff->ifTrue->dynCast<Break>(); if (ifTrueBreak && !ifTrueBreak->condition && canTurnIfIntoBrIf(iff->condition, ifTrueBreak->value, passOptions)) { // we are an if-else where the ifTrue is a break without a condition, so we can do this diff --git a/test/lld/hello_world.wast.mem b/test/lld/hello_world.wast.mem Binary files differnew file mode 100644 index 000000000..674c410a9 --- /dev/null +++ b/test/lld/hello_world.wast.mem diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index daa7eca3c..48cfad529 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -938,15 +938,16 @@ (loop $typed (result i32) (block $outer (result i32) (block (result i32) - (if (result i32) - (i32.const 2) - (block $block (result i32) - (drop - (call $loop-if) - ) - (i32.const 0) + (br_if $typed + (i32.eqz + (i32.const 2) ) - (br $typed) + ) + (block $block (result i32) + (drop + (call $loop-if) + ) + (i32.const 0) ) ) ) @@ -2382,4 +2383,25 @@ (br $top) ) ) + (func $loop-end-set (; 111 ;) (type $10) (param $x i32) (result i32) + (loop $loop + (nop) + (br_if $loop + (get_local $x) + ) + (set_local $x + (i32.const 1) + ) + ) + (get_local $x) + ) + (func $loop-end-value (; 112 ;) (type $10) (param $x i32) (result i32) + (loop $loop (result i32) + (nop) + (br_if $loop + (get_local $x) + ) + (i32.const 1) + ) + ) ) diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index fe195317d..9d53f4fda 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -1990,5 +1990,26 @@ (br $top) ) ) + (func $loop-end-set (param $x i32) (result i32) + (loop $loop + (nop) + (if + (get_local $x) + (br $loop) + (set_local $x (i32.const 1)) + ) + ) + (get_local $x) + ) + (func $loop-end-value (param $x i32) (result i32) + (loop $loop (result i32) + (nop) + (if (result i32) + (get_local $x) + (br $loop) + (i32.const 1) + ) + ) + ) ) |