diff options
author | Alon Zakai <azakai@google.com> | 2021-04-21 19:54:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-21 19:54:38 -0700 |
commit | 0e0147dd18a3875bde24f418b23230d454942c4a (patch) | |
tree | 8ecb81e690058954e22ea3bd813b3ead0a9b4db3 /test/lit/passes/optimize-instructions-gc.wast | |
parent | cb776da297a845e15171405b7f7518619122d7aa (diff) | |
download | binaryen-0e0147dd18a3875bde24f418b23230d454942c4a.tar.gz binaryen-0e0147dd18a3875bde24f418b23230d454942c4a.tar.bz2 binaryen-0e0147dd18a3875bde24f418b23230d454942c4a.zip |
Generalize moving of identical code from if/select arms (#3833)
Effects are fine in the moved code, if we are doing so on an if
(which runs just one arm anyhow).
Allow unreachable, which lets us hoist returns for example.
Allow none, which lets us hoist drop and call for example. For
this we also need to be careful with subtyping, as at least drop
is polymorphic, so the child types may not have an LUB (see
example in code).
Adds a small ShallowEffectAnalyzer child of EffectAnalyzer that
calls visit to just do a shallow analysis (instead of walk which
walks the children).
Diffstat (limited to 'test/lit/passes/optimize-instructions-gc.wast')
-rw-r--r-- | test/lit/passes/optimize-instructions-gc.wast | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/test/lit/passes/optimize-instructions-gc.wast b/test/lit/passes/optimize-instructions-gc.wast index 3ae0e1d91..c0474a823 100644 --- a/test/lit/passes/optimize-instructions-gc.wast +++ b/test/lit/passes/optimize-instructions-gc.wast @@ -849,7 +849,7 @@ ) ) ) - ;; CHECK: (func $ternary-identical-arms-but-side-effect (param $x (ref null $struct)) (param $y (ref null $struct)) (param $z i32) + ;; CHECK: (func $select-identical-arms-but-side-effect (param $x (ref null $struct)) (param $y (ref null $struct)) (param $z i32) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (select ;; CHECK-NEXT: (struct.get_u $struct $i8 @@ -862,7 +862,7 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - (func $ternary-identical-arms-but-side-effect (param $x (ref null $struct)) (param $y (ref null $struct)) (param $z i32) + (func $select-identical-arms-but-side-effect (param $x (ref null $struct)) (param $y (ref null $struct)) (param $z i32) (drop (select ;; the arms are equal but have side effects @@ -901,4 +901,30 @@ ) ) ) + ;; CHECK: (func $if-identical-arms-with-side-effect (param $x (ref null $struct)) (param $y (ref null $struct)) (param $z i32) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.get_u $struct $i8 + ;; CHECK-NEXT: (if (result (ref null $struct)) + ;; CHECK-NEXT: (local.get $z) + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $if-identical-arms-with-side-effect (param $x (ref null $struct)) (param $y (ref null $struct)) (param $z i32) + (drop + (if (result i32) + (local.get $z) + ;; the arms are equal and have side effects, but that is ok with an if + ;; which only executes one side anyhow + (struct.get_u $struct 0 + (local.get $x) + ) + (struct.get_u $struct 0 + (local.get $y) + ) + ) + ) + ) ) |