diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-08-05 11:53:48 -0700 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-08-05 13:46:02 -0700 |
commit | cc193a49fa612142fdea016ed8fe8a527be7c835 (patch) | |
tree | ad3fe7ac6265afd1abfe08e65be69d137b80a639 | |
parent | 077c531131be9404e97e94147fc5c5af9006ef07 (diff) | |
download | binaryen-cc193a49fa612142fdea016ed8fe8a527be7c835.tar.gz binaryen-cc193a49fa612142fdea016ed8fe8a527be7c835.tar.bz2 binaryen-cc193a49fa612142fdea016ed8fe8a527be7c835.zip |
don't turn untaken br_ifs into ifs in remove-unused-brs
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 4 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.txt | 11 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.wast | 11 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 9fed3e4a5..8994c7fe2 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -481,7 +481,9 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { // format. We need to flip the condition, which at worst adds 1. if (curr->name.is()) { auto* br = list[0]->dynCast<Break>(); - if (br && br->condition && br->name == curr->name) { + // we seek a regular br_if; if the type is unreachable that means it is not + // actually taken, so ignore + if (br && br->condition && br->name == curr->name && br->type != unreachable) { assert(!br->value); // can't, it would be dropped or last in the block if (BranchUtils::BranchSeeker::countNamed(curr, curr->name) == 1) { // no other breaks to that name, so we can do this diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index 355f8a531..fe0c59fca 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -1048,4 +1048,15 @@ ) ) ) + (func $untaken-br_if-then-if (type $1) + (block $label$0 + (br_if $label$0 + (unreachable) + ) + (if + (i32.const 0) + (nop) + ) + ) + ) ) diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index e7c221fa4..996b05264 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -932,5 +932,16 @@ ) ) ) + (func $untaken-br_if-then-if + (block $label$0 + (br_if $label$0 + (unreachable) + ) + (if + (i32.const 0) + (nop) + ) + ) + ) ) |