diff options
author | Alon Zakai <azakai@google.com> | 2021-08-18 14:08:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 14:08:51 -0700 |
commit | 3d6ddaf16232c42ab9a82f5114d562c2d8807870 (patch) | |
tree | d3f3e84498a6035278a2083e70e82dbfb2d9ff5f /test/lit/passes/local-cse_all-features.wast | |
parent | 8d95402260d268966eb0b06c5f4da7e1c5854418 (diff) | |
download | binaryen-3d6ddaf16232c42ab9a82f5114d562c2d8807870.tar.gz binaryen-3d6ddaf16232c42ab9a82f5114d562c2d8807870.tar.bz2 binaryen-3d6ddaf16232c42ab9a82f5114d562c2d8807870.zip |
[Wasm GC] Effects: Differentiate Struct and Array types (#4088)
This allows common patterns in J2CL to be optimized, where we write
to various array indices and get the values or the reference from a
struct.
It would be nice to do even better here, and look at actually specific
types, but I think we should be careful to keep the runtime constant.
That seems hard to do if we accumulate a list of types and do
Type::isSubType on them etc. But maybe someone has a better
idea than this PR?
Diffstat (limited to 'test/lit/passes/local-cse_all-features.wast')
-rw-r--r-- | test/lit/passes/local-cse_all-features.wast | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/test/lit/passes/local-cse_all-features.wast b/test/lit/passes/local-cse_all-features.wast index b5a619997..8ff3bc253 100644 --- a/test/lit/passes/local-cse_all-features.wast +++ b/test/lit/passes/local-cse_all-features.wast @@ -60,16 +60,18 @@ ;; CHECK: (type $A (struct (field i32))) (type $A (struct (field i32))) - ;; CHECK: (type $ref|$A|_=>_none (func (param (ref $A)))) - ;; CHECK: (type $B (array (mut i32))) (type $B (array (mut i32))) + ;; CHECK: (type $ref|$A|_=>_none (func (param (ref $A)))) + ;; CHECK: (type $ref?|$A|_=>_none (func (param (ref null $A)))) ;; CHECK: (type $none_=>_none (func)) + ;; CHECK: (type $ref?|$B|_ref|$A|_=>_none (func (param (ref null $B) (ref $A)))) + ;; CHECK: (func $struct-gets-nullable (param $ref (ref null $A)) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (drop @@ -241,6 +243,55 @@ ) ) ) + + ;; CHECK: (func $structs-and-arrays-do-not-alias (param $array (ref null $B)) (param $struct (ref $A)) + ;; CHECK-NEXT: (local $2 i32) + ;; CHECK-NEXT: (array.set $B + ;; CHECK-NEXT: (local.get $array) + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: (local.tee $2 + ;; CHECK-NEXT: (struct.get $A 0 + ;; CHECK-NEXT: (local.get $struct) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (array.set $B + ;; CHECK-NEXT: (local.get $array) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (array.set $B + ;; CHECK-NEXT: (local.get $array) + ;; CHECK-NEXT: (i32.const 2) + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $structs-and-arrays-do-not-alias (param $array (ref null $B)) (param $struct (ref $A)) + ;; ArraySets to consecutive elements, using some fixed StructGet value. This + ;; common pattern in j2cl can be optimized, as structs and arrays do not + ;; alias. + (array.set $B + (local.get $array) + (i32.const 0) + (struct.get $A 0 + (local.get $struct) + ) + ) + (array.set $B + (local.get $array) + (i32.const 1) + (struct.get $A 0 + (local.get $struct) + ) + ) + (array.set $B + (local.get $array) + (i32.const 2) + (struct.get $A 0 + (local.get $struct) + ) + ) + ) ) (module |