diff options
author | Alon Zakai <azakai@google.com> | 2024-05-14 10:10:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-14 10:10:54 -0700 |
commit | 4ca05f765ca6ec99b7582d357520ca217265677d (patch) | |
tree | acedda233346f51d2314d93748209bce60f25f1e /test | |
parent | 020d08e01ff506099c8293e69cd03f5f75f562d9 (diff) | |
download | binaryen-4ca05f765ca6ec99b7582d357520ca217265677d.tar.gz binaryen-4ca05f765ca6ec99b7582d357520ca217265677d.tar.bz2 binaryen-4ca05f765ca6ec99b7582d357520ca217265677d.zip |
LocalCSE: Check effects/generativity early (#6587)
Previously we checked late, and as a result might end up failing to optimize when
a sub-pattern could have worked. E.g.
(call
(A)
)
(call
(A)
)
The call cannot be optimized, but the A pattern repeats. Before this PR we'd
greedily focus on the entire call and then fail. After this PR we skip the call
before we commit to which patterns to try to optimize, so we succeed.
Add a isShallowlyGenerative helper here as we compute this step by step as
we go. Also remove a parameter to the generativity code (it did not use the
features it was passed).
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/local-cse.wast | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/test/lit/passes/local-cse.wast b/test/lit/passes/local-cse.wast index c38ca243a..8b0f51a7c 100644 --- a/test/lit/passes/local-cse.wast +++ b/test/lit/passes/local-cse.wast @@ -9,7 +9,9 @@ ;; CHECK: (type $1 (func (param i32) (result i32))) - ;; CHECK: (type $2 (func (result i64))) + ;; CHECK: (type $2 (func (param i32))) + + ;; CHECK: (type $3 (func (result i64))) ;; CHECK: (memory $0 100 100) @@ -315,6 +317,45 @@ (i32.const 10) ) + ;; CHECK: (func $in-calls (param $x i32) + ;; CHECK-NEXT: (local $1 i32) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (call $calls + ;; CHECK-NEXT: (local.tee $1 + ;; CHECK-NEXT: (i32.add + ;; CHECK-NEXT: (i32.const 10) + ;; CHECK-NEXT: (i32.const 20) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (call $calls + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $in-calls (param $x i32) + ;; The side effects of calls prevent optimization, but expressions nested in + ;; calls can be optimized. + (drop + (call $calls + (i32.add + (i32.const 10) + (i32.const 20) + ) + ) + ) + (drop + (call $calls + (i32.add + (i32.const 10) + (i32.const 20) + ) + ) + ) + ) + ;; CHECK: (func $many-sets (result i64) ;; CHECK-NEXT: (local $temp i64) ;; CHECK-NEXT: (local $1 i64) |