diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/gsi.wast | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/test/lit/passes/gsi.wast b/test/lit/passes/gsi.wast index 4cec6aa3c..6fe4da95a 100644 --- a/test/lit/passes/gsi.wast +++ b/test/lit/passes/gsi.wast @@ -1268,3 +1268,162 @@ ) ) ) + +;; Two subtypes, each with a global. A get of the parent can be optimized into +;; a select, as it must read one of the children. +(module + ;; CHECK: (type $struct (struct (field i32))) + (type $struct (struct_subtype i32 data)) + + ;; CHECK: (type $sub-struct1 (struct_subtype (field i32) $struct)) + (type $sub-struct1 (struct_subtype i32 $struct)) + + ;; CHECK: (type $sub-struct2 (struct_subtype (field i32) $struct)) + (type $sub-struct2 (struct_subtype i32 $struct)) + + ;; CHECK: (type $ref?|$struct|_=>_none (func (param (ref null $struct)))) + + ;; CHECK: (global $global1 (ref $sub-struct1) (struct.new $sub-struct1 + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: )) + (global $global1 (ref $sub-struct1) (struct.new $sub-struct1 + (i32.const 42) + )) + + ;; CHECK: (global $global2 (ref $sub-struct2) (struct.new $sub-struct2 + ;; CHECK-NEXT: (i32.const 1337) + ;; CHECK-NEXT: )) + (global $global2 (ref $sub-struct2) (struct.new $sub-struct2 + (i32.const 1337) + )) + + ;; CHECK: (func $test (type $ref?|$struct|_=>_none) (param $struct (ref null $struct)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (select + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: (i32.const 1337) + ;; CHECK-NEXT: (ref.eq + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (local.get $struct) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (global.get $global1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $test (param $struct (ref null $struct)) + (drop + (struct.get $struct 0 + (local.get $struct) + ) + ) + ) +) + +;; As above, but now the parent is unoptimizable due to a struct.new in a +;; function. We must not optimize here to a select. +(module + ;; CHECK: (type $struct (struct (field i32))) + (type $struct (struct_subtype i32 data)) + + ;; CHECK: (type $sub-struct1 (struct_subtype (field i32) $struct)) + (type $sub-struct1 (struct_subtype i32 $struct)) + + ;; CHECK: (type $sub-struct2 (struct_subtype (field i32) $struct)) + (type $sub-struct2 (struct_subtype i32 $struct)) + + ;; CHECK: (type $ref?|$struct|_=>_none (func (param (ref null $struct)))) + + ;; CHECK: (global $global1 (ref $sub-struct1) (struct.new $sub-struct1 + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: )) + (global $global1 (ref $sub-struct1) (struct.new $sub-struct1 + (i32.const 42) + )) + + ;; CHECK: (global $global2 (ref $sub-struct2) (struct.new $sub-struct2 + ;; CHECK-NEXT: (i32.const 1337) + ;; CHECK-NEXT: )) + (global $global2 (ref $sub-struct2) (struct.new $sub-struct2 + (i32.const 1337) + )) + + ;; CHECK: (func $test (type $ref?|$struct|_=>_none) (param $struct (ref null $struct)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.new $struct + ;; CHECK-NEXT: (i32.const 999999) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.get $struct 0 + ;; CHECK-NEXT: (local.get $struct) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $test (param $struct (ref null $struct)) + (drop + (struct.new $struct + (i32.const 999999) + ) + ) + (drop + (struct.get $struct 0 + (local.get $struct) + ) + ) + ) +) + +;; As above, the struct.new in a function is of a subtype. Again, we cannot +;; optimize, as unoptimizability spreads to supertypes. +(module + ;; CHECK: (type $struct (struct (field i32))) + (type $struct (struct_subtype i32 data)) + + ;; CHECK: (type $sub-struct1 (struct_subtype (field i32) $struct)) + (type $sub-struct1 (struct_subtype i32 $struct)) + + ;; CHECK: (type $sub-struct2 (struct_subtype (field i32) $struct)) + (type $sub-struct2 (struct_subtype i32 $struct)) + + ;; CHECK: (type $ref?|$struct|_=>_none (func (param (ref null $struct)))) + + ;; CHECK: (global $global1 (ref $sub-struct1) (struct.new $sub-struct1 + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: )) + (global $global1 (ref $sub-struct1) (struct.new $sub-struct1 + (i32.const 42) + )) + + ;; CHECK: (global $global2 (ref $sub-struct2) (struct.new $sub-struct2 + ;; CHECK-NEXT: (i32.const 1337) + ;; CHECK-NEXT: )) + (global $global2 (ref $sub-struct2) (struct.new $sub-struct2 + (i32.const 1337) + )) + + ;; CHECK: (func $test (type $ref?|$struct|_=>_none) (param $struct (ref null $struct)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.new $sub-struct1 + ;; CHECK-NEXT: (i32.const 999999) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.get $struct 0 + ;; CHECK-NEXT: (local.get $struct) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $test (param $struct (ref null $struct)) + (drop + (struct.new $sub-struct1 + (i32.const 999999) + ) + ) + (drop + (struct.get $struct 0 + (local.get $struct) + ) + ) + ) +) |