diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-01-08 15:11:34 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-01-08 15:11:34 -0800 |
commit | 02910f3defc1be94ee1d4af6d43ec05b1c37d18d (patch) | |
tree | 9b128fe5a1aa8334561018ede7d1694f00f23b58 | |
parent | 382ea607d99c73a6e893f4f92b0b63bde698e487 (diff) | |
download | binaryen-02910f3defc1be94ee1d4af6d43ec05b1c37d18d.tar.gz binaryen-02910f3defc1be94ee1d4af6d43ec05b1c37d18d.tar.bz2 binaryen-02910f3defc1be94ee1d4af6d43ec05b1c37d18d.zip |
RemoveUnneededBrs: remove all code in a block after a break
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 7 | ||||
-rw-r--r-- | test/two_sides.fromasm | 111 |
2 files changed, 60 insertions, 58 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index a89c69312..395b0f1ba 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -66,6 +66,13 @@ struct RemoveUnusedBrs : public Pass { void visitBlock(Block *curr) override { 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) + for (size_t i = 0; i < curr->list.size()-1; i++) { + if (curr->list[i]->is<Break>()) { + curr->list.resize(i+1); + break; + } + } Expression* last = curr->list.back(); if (Break* br = last->dyn_cast<Break>()) { if (br->condition) return; diff --git a/test/two_sides.fromasm b/test/two_sides.fromasm index 9bf643e2a..aff27f665 100644 --- a/test/two_sides.fromasm +++ b/test/two_sides.fromasm @@ -4,80 +4,75 @@ (export "_test" $_test) (func $_test (param $i1 i32) (param $i2 i32) (param $i3 i32) (param $i4 i32) (param $i5 i32) (result i32) (local $d6 f64) - (block $topmost - (br $topmost - (if_else - (i32.eq - (get_local $i5) - (i32.const 0) + (if_else + (i32.eq + (get_local $i5) + (i32.const 0) + ) + (block + (set_local $d6 + (f64.convert_s/i32 + (i32.mul + (get_local $i4) + (get_local $i3) + ) ) - (block - (set_local $d6 + ) + (set_local $d6 + (f64.mul + (f64.add (f64.convert_s/i32 - (i32.mul - (get_local $i4) - (get_local $i3) - ) + (get_local $i3) ) + (get_local $d6) ) - (set_local $d6 - (f64.mul - (f64.add - (f64.convert_s/i32 - (get_local $i3) - ) - (get_local $d6) - ) - (f64.add - (f64.convert_s/i32 - (get_local $i4) - ) - (get_local $d6) - ) + (f64.add + (f64.convert_s/i32 + (get_local $i4) ) + (get_local $d6) ) - (set_local $i5 - (call_import $f64-to-int - (get_local $d6) - ) + ) + ) + (set_local $i5 + (call_import $f64-to-int + (get_local $d6) + ) + ) + (get_local $i5) + ) + (block + (set_local $d6 + (f64.convert_s/i32 + (i32.mul + (get_local $i2) + (get_local $i1) ) - (get_local $i5) ) - (block - (set_local $d6 + ) + (set_local $d6 + (f64.mul + (f64.add (f64.convert_s/i32 - (i32.mul - (get_local $i2) - (get_local $i1) - ) - ) - ) - (set_local $d6 - (f64.mul - (f64.add - (f64.convert_s/i32 - (get_local $i3) - ) - (get_local $d6) - ) - (f64.add - (get_local $d6) - (f64.convert_s/i32 - (get_local $i4) - ) - ) + (get_local $i3) ) + (get_local $d6) ) - (set_local $i5 - (call_import $f64-to-int - (get_local $d6) + (f64.add + (get_local $d6) + (f64.convert_s/i32 + (get_local $i4) ) ) - (get_local $i5) ) ) + (set_local $i5 + (call_import $f64-to-int + (get_local $d6) + ) + ) + (get_local $i5) ) - (i32.const 0) ) ) ) |