|
| 1 | +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. |
| 2 | + |
| 3 | +;; RUN: wasm-opt %s -all --closed-world --gto --preserve-type-order -S -o - | filecheck %s |
| 4 | + |
| 5 | +(module |
| 6 | + (rec |
| 7 | + ;; CHECK: (rec |
| 8 | + ;; CHECK-NEXT: (type $struct (descriptor $desc (struct (field i32)))) |
| 9 | + (type $struct (descriptor $desc (struct (field i32)))) |
| 10 | + ;; CHECK: (type $desc (describes $struct (struct))) |
| 11 | + (type $desc (describes $struct (struct))) |
| 12 | + ;; CHECK: (type $pair (struct)) |
| 13 | + (type $pair (struct (field (ref $struct)) (field (ref $struct)))) |
| 14 | + ;; CHECK: (type $used-pair (struct (field (ref $struct)) (field (ref $struct)))) |
| 15 | + (type $used-pair (struct (field (ref $struct)) (field (ref $struct)))) |
| 16 | + ) |
| 17 | + |
| 18 | + ;; CHECK: (type $4 (func (param (ref $struct) (ref $used-pair)))) |
| 19 | + |
| 20 | + ;; CHECK: (global $nullable-desc (ref null (exact $desc)) (struct.new_default $desc)) |
| 21 | + (global $nullable-desc (ref null (exact $desc)) (struct.new $desc)) |
| 22 | + |
| 23 | + ;; Check that we generate fresh names for added globals. |
| 24 | + ;; CHECK: (global $gto-removed-1 nullref (ref.null none)) |
| 25 | + (global $gto-removed-1 nullref (ref.null none)) |
| 26 | + |
| 27 | + ;; CHECK: (global $second-traps (ref $pair) (struct.new_default $pair)) |
| 28 | + (global $second-traps (ref $pair) |
| 29 | + ;; Both fields will be removed, but only the second can trap, so only the |
| 30 | + ;; second will be moved to a new global. |
| 31 | + (struct.new $pair |
| 32 | + (struct.new $struct |
| 33 | + (i32.const 0) |
| 34 | + (struct.new $desc) |
| 35 | + ) |
| 36 | + (struct.new $struct |
| 37 | + (i32.const 1) |
| 38 | + (ref.null none) |
| 39 | + ) |
| 40 | + ) |
| 41 | + ) |
| 42 | + |
| 43 | + ;; CHECK: (global $first-traps (ref $pair) (struct.new_default $pair)) |
| 44 | + (global $first-traps (ref $pair) |
| 45 | + ;; Same as above, but now the first traps (or at least we assume it can |
| 46 | + ;; based on its type). |
| 47 | + (struct.new $pair |
| 48 | + (struct.new $struct |
| 49 | + (i32.const 2) |
| 50 | + (global.get $nullable-desc) |
| 51 | + ) |
| 52 | + (struct.new $struct |
| 53 | + (i32.const 3) |
| 54 | + (struct.new $desc) |
| 55 | + ) |
| 56 | + ) |
| 57 | + ) |
| 58 | + |
| 59 | + ;; CHECK: (global $used-traps (ref $used-pair) (struct.new $used-pair |
| 60 | + ;; CHECK-NEXT: (struct.new $struct |
| 61 | + ;; CHECK-NEXT: (i32.const 4) |
| 62 | + ;; CHECK-NEXT: (ref.null none) |
| 63 | + ;; CHECK-NEXT: ) |
| 64 | + ;; CHECK-NEXT: (struct.new $struct |
| 65 | + ;; CHECK-NEXT: (i32.const 5) |
| 66 | + ;; CHECK-NEXT: (ref.null none) |
| 67 | + ;; CHECK-NEXT: ) |
| 68 | + ;; CHECK-NEXT: )) |
| 69 | + (global $used-traps (ref $used-pair) |
| 70 | + ;; Now both trap, but they are also used, so they will not be removed and no |
| 71 | + ;; globals will be created. |
| 72 | + (struct.new $used-pair |
| 73 | + (struct.new $struct |
| 74 | + (i32.const 4) |
| 75 | + (ref.null none) |
| 76 | + ) |
| 77 | + (struct.new $struct |
| 78 | + (i32.const 5) |
| 79 | + (ref.null none) |
| 80 | + ) |
| 81 | + ) |
| 82 | + ) |
| 83 | + |
| 84 | + ;; CHECK: (global $gto-removed-0 (ref (exact $struct)) (struct.new $struct |
| 85 | + ;; CHECK-NEXT: (i32.const 1) |
| 86 | + ;; CHECK-NEXT: (ref.null none) |
| 87 | + ;; CHECK-NEXT: )) |
| 88 | + |
| 89 | + ;; CHECK: (global $gto-removed-1_6 (ref (exact $struct)) (struct.new $struct |
| 90 | + ;; CHECK-NEXT: (i32.const 2) |
| 91 | + ;; CHECK-NEXT: (global.get $nullable-desc) |
| 92 | + ;; CHECK-NEXT: )) |
| 93 | + |
| 94 | + ;; CHECK: (func $use-struct-fields (type $4) (param $0 (ref $struct)) (param $1 (ref $used-pair)) |
| 95 | + ;; CHECK-NEXT: (drop |
| 96 | + ;; CHECK-NEXT: (struct.get $struct 0 |
| 97 | + ;; CHECK-NEXT: (local.get $0) |
| 98 | + ;; CHECK-NEXT: ) |
| 99 | + ;; CHECK-NEXT: ) |
| 100 | + ;; CHECK-NEXT: (drop |
| 101 | + ;; CHECK-NEXT: (struct.get $used-pair 0 |
| 102 | + ;; CHECK-NEXT: (local.get $1) |
| 103 | + ;; CHECK-NEXT: ) |
| 104 | + ;; CHECK-NEXT: ) |
| 105 | + ;; CHECK-NEXT: (drop |
| 106 | + ;; CHECK-NEXT: (struct.get $used-pair 1 |
| 107 | + ;; CHECK-NEXT: (local.get $1) |
| 108 | + ;; CHECK-NEXT: ) |
| 109 | + ;; CHECK-NEXT: ) |
| 110 | + ;; CHECK-NEXT: ) |
| 111 | + (func $use-struct-fields (param (ref $struct)) (param (ref $used-pair)) |
| 112 | + ;; Prevent the i32s in the initializers from being removed. |
| 113 | + (drop |
| 114 | + (struct.get $struct 0 |
| 115 | + (local.get 0) |
| 116 | + ) |
| 117 | + ) |
| 118 | + ;; Prevent the fields in used-pair from being removed. |
| 119 | + (drop |
| 120 | + (struct.get $used-pair 0 |
| 121 | + (local.get 1) |
| 122 | + ) |
| 123 | + ) |
| 124 | + (drop |
| 125 | + (struct.get $used-pair 1 |
| 126 | + (local.get 1) |
| 127 | + ) |
| 128 | + ) |
| 129 | + ) |
| 130 | +) |
0 commit comments