diff options
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 8 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.txt | 122 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.wast | 44 |
3 files changed, 168 insertions, 6 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index ff50847de..5f3018c5f 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -29,9 +29,13 @@ struct RemoveUnusedBrs : public Pass { if (curr->list.size() == 0) return; Break* last = curr->list.back()->dyn_cast<Break>(); if (!last) return; - if (last->value) return; + if (last->condition) return; if (last->name == curr->name) { - curr->list.pop_back(); + if (!last->value) { + curr->list.pop_back(); + } else { + curr->list[curr->list.size()-1] = last->value; // can replace with the value + } } } }; diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index b42347fc3..af5b9d1ed 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -44,6 +44,65 @@ ) ) ) + (func $b6 (param $i1 i32) + (block $topmost + (br_if + (i32.const 1) + $topmost + ) + ) + ) + (func $b7 (param $i1 i32) + (block $topmost + (br_if + (i32.const 1) + $topmost + (i32.const 0) + ) + ) + ) + (func $b8 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $topmost + ) + ) + ) + ) + (func $b9 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $inner + ) + ) + ) + ) + (func $b10 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $topmost + (i32.const 0) + ) + ) + ) + ) + (func $b11 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $inner + (i32.const 0) + ) + ) + ) + ) ) (module (memory 16777216 16777216) @@ -53,9 +112,7 @@ ) (func $b1 (param $i1 i32) (block $topmost - (br $topmost - (i32.const 0) - ) + (i32.const 0) ) ) (func $b2 (param $i1 i32) @@ -83,7 +140,64 @@ (func $b5 (param $i1 i32) (block $topmost (block $inner - (br $inner + (i32.const 0) + ) + ) + ) + (func $b6 (param $i1 i32) + (block $topmost + (br_if + (i32.const 1) + $topmost + ) + ) + ) + (func $b7 (param $i1 i32) + (block $topmost + (br_if + (i32.const 1) + $topmost + (i32.const 0) + ) + ) + ) + (func $b8 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $topmost + ) + ) + ) + ) + (func $b9 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $inner + ) + ) + ) + ) + (func $b10 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $topmost + (i32.const 0) + ) + ) + ) + ) + (func $b11 (param $i1 i32) + (block $topmost + (block $inner + (br_if + (i32.const 1) + $inner (i32.const 0) ) ) diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index e03ba8847..b4a2cc5fe 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -44,5 +44,49 @@ ) ) ) + (func $b6 (param $i1 i32) + (block $topmost + (br_if (i32.const 1) $topmost) + ) + ) + (func $b7 (param $i1 i32) + (block $topmost + (br_if (i32.const 1) $topmost + (i32.const 0) + ) + ) + ) + (func $b8 (param $i1 i32) + (block $topmost + (block $inner + (br_if (i32.const 1) $topmost) + ) + ) + ) + (func $b9 (param $i1 i32) + (block $topmost + (block $inner + (br_if (i32.const 1) $inner) + ) + ) + ) + (func $b10 (param $i1 i32) + (block $topmost + (block $inner + (br_if (i32.const 1) $topmost + (i32.const 0) + ) + ) + ) + ) + (func $b11 (param $i1 i32) + (block $topmost + (block $inner + (br_if (i32.const 1) $inner + (i32.const 0) + ) + ) + ) + ) ) |