diff options
author | Alon Zakai <azakai@google.com> | 2021-09-13 14:27:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-13 14:27:10 -0700 |
commit | 181b0e7037bc2999a24cb45a02523f3da04b254d (patch) | |
tree | 6f03f5577b2b819cd6bcfd03f6533f146e05f8bd /test | |
parent | ec2c5df877c479855bd13d280b98220e50bb99f9 (diff) | |
download | binaryen-181b0e7037bc2999a24cb45a02523f3da04b254d.tar.gz binaryen-181b0e7037bc2999a24cb45a02523f3da04b254d.tar.bz2 binaryen-181b0e7037bc2999a24cb45a02523f3da04b254d.zip |
RemoveUnusedBrs::tablify() improvements: handle EqZ and tee (#4144)
tablify() attempts to turns a sequence of br_ifs into a single
br_table. This PR adds some flexibility to the specific pattern it
looks for, specifically:
* Accept i32.eqz as a comparison to zero, and not just to look
for i32.eq against a constant.
* Allow the first condition to be a tee. If it is, compare later
conditions to local.get of that local.
This will allow more br_tables to be emitted in j2cl output.
Diffstat (limited to 'test')
-rw-r--r-- | test/passes/remove-unused-brs_enable-multivalue.txt | 103 | ||||
-rw-r--r-- | test/passes/remove-unused-brs_enable-multivalue.wast | 87 |
2 files changed, 190 insertions, 0 deletions
diff --git a/test/passes/remove-unused-brs_enable-multivalue.txt b/test/passes/remove-unused-brs_enable-multivalue.txt index 29b5eca5e..46938f784 100644 --- a/test/passes/remove-unused-brs_enable-multivalue.txt +++ b/test/passes/remove-unused-brs_enable-multivalue.txt @@ -1669,6 +1669,109 @@ ) (unreachable) ) + (func $br-to-table-initial-tee (param $a i32) + (block $x + (block $y + (block $z + (nop) + (nop) + (block $tablify|0 + (br_table $x $y $z $tablify|0 + (i32.sub + (local.tee $a + (i32.add + (i32.const 10) + (i32.const 1) + ) + ) + (i32.const 10) + ) + ) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (func $br-to-table-initial-tee-wrong-index (param $a i32) + (local $b i32) + (block $x + (block $y + (block $z + (br_if $x + (i32.eq + (local.tee $a + (i32.const 99) + ) + (i32.const 10) + ) + ) + (br_if $y + (i32.eq + (local.get $b) + (i32.const 11) + ) + ) + (br_if $z + (i32.eq + (local.get $b) + (i32.const 12) + ) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (func $br-to-table-eqz (param $a i32) + (block $x + (block $y + (block $z + (nop) + (nop) + (block $tablify|0 + (br_table $x $y $z $tablify|0 + (local.get $a) + ) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (func $br-to-table-tee-eqz (param $a i32) + (block $x + (block $y + (block $z + (nop) + (nop) + (block $tablify|0 + (br_table $x $y $z $tablify|0 + (local.tee $a + (i32.add + (i32.const 0) + (i32.const 1) + ) + ) + ) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) (func $tiny-switch (if (i32.const 0) diff --git a/test/passes/remove-unused-brs_enable-multivalue.wast b/test/passes/remove-unused-brs_enable-multivalue.wast index afc8c3836..ae8878e00 100644 --- a/test/passes/remove-unused-brs_enable-multivalue.wast +++ b/test/passes/remove-unused-brs_enable-multivalue.wast @@ -1353,6 +1353,93 @@ ) (unreachable) ) + (func $br-to-table-initial-tee (param $a i32) + (block $x + (block $y + (block $z + (br_if $x + (i32.eq + (local.tee $a + (i32.add + (i32.const 10) + (i32.const 1) + ) + ) + (i32.const 10) + ) + ) + (br_if $y (i32.eq (local.get $a) (i32.const 11))) + (br_if $z (i32.eq (local.get $a) (i32.const 12))) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (func $br-to-table-initial-tee-wrong-index (param $a i32) + (local $b i32) + (block $x + (block $y + (block $z + (br_if $x + (i32.eq + (local.tee $a (i32.const 99)) + (i32.const 10) + ) + ) + ;; The subsequent conditions use a different local, $b, so we cannot + ;; optimize here. + (br_if $y (i32.eq (local.get $b) (i32.const 11))) + (br_if $z (i32.eq (local.get $b) (i32.const 12))) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (func $br-to-table-eqz (param $a i32) + (block $x + (block $y + (block $z + (br_if $x (i32.eqz (local.get $a))) + (br_if $y (i32.eq (local.get $a) (i32.const 1))) + (br_if $z (i32.eq (local.get $a) (i32.const 2))) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (func $br-to-table-tee-eqz (param $a i32) + (block $x + (block $y + (block $z + (br_if $x + (i32.eqz + (local.tee $a + (i32.add + (i32.const 0) + (i32.const 1) + ) + ) + ) + ) + (br_if $y (i32.eq (local.get $a) (i32.const 1))) + (br_if $z (i32.eq (local.get $a) (i32.const 2))) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) + (unreachable) + ) (func $tiny-switch (block $x (block $y |