summaryrefslogtreecommitdiff
path: root/test/lit/passes/vacuum-eh.wast
blob: d42fed56ba32b8cbb457cc6630a6194976f9493f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --vacuum -all -S -o - | filecheck %s

(module
  ;; CHECK:      (type $void (func))
  (type $void (func))

  ;; CHECK:      (table $t 0 funcref)
  (table $t 0 funcref)

  ;; CHECK:      (tag $e (param i32))
  (tag $e (param i32))
  ;; CHECK:      (tag $e2 (param i32))
  (tag $e2 (param i32))

  ;; CHECK:      (func $try_table-test (type $void)
  ;; CHECK-NEXT:  (nop)
  ;; CHECK-NEXT: )
  (func $try_table-test
    ;; When try_table body does not throw, the try_table can be replaced with
    ;; its body
    (block $tryend
      (drop
        (block $catch (result i32)
          (try_table (catch $e $catch)
            (drop (i32.const 0))
          )
          (br $tryend)
        )
      )
    )
  )

  ;; CHECK:      (func $inner-try_table-catch_all-test (type $2) (result i32)
  ;; CHECK-NEXT:  (local $0 i32)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (block
  ;; CHECK-NEXT:    (block $inner-catch
  ;; CHECK-NEXT:     (try_table (catch_all $inner-catch)
  ;; CHECK-NEXT:      (throw $e
  ;; CHECK-NEXT:       (i32.const 0)
  ;; CHECK-NEXT:      )
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:    (return
  ;; CHECK-NEXT:     (i32.const 1)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (i32.const 2)
  ;; CHECK-NEXT: )
  (func $inner-try_table-catch_all-test (result i32)
    (local $0 i32)
    ;; The exception thrown in the inner try_table is caught by the inner
    ;; catch_all, so the outer try_table body does not throw and the outer
    ;; try_table can be removed
    (block $outer-tryend
      (drop
        (block $outer-catch (result i32)
          (try_table (catch $e $outer-catch)
            (block $inner-catch
              (try_table (catch_all $inner-catch)
                (throw $e (i32.const 0))
              )
              (unreachable)
            )
            (return (i32.const 1))
          )
          (br $outer-tryend)
        )
      )
    )
    (i32.const 2)
  )

  ;; CHECK:      (func $inner-try_table-catch-test (type $void)
  ;; CHECK-NEXT:  (local $0 i32)
  ;; CHECK-NEXT:  (block $outer-tryend
  ;; CHECK-NEXT:   (drop
  ;; CHECK-NEXT:    (block $outer-catch (result i32)
  ;; CHECK-NEXT:     (try_table (catch $e $outer-catch)
  ;; CHECK-NEXT:      (block $inner-tryend
  ;; CHECK-NEXT:       (drop
  ;; CHECK-NEXT:        (block $inner-catch (result i32)
  ;; CHECK-NEXT:         (try_table (catch $e $inner-catch)
  ;; CHECK-NEXT:          (throw $e2
  ;; CHECK-NEXT:           (i32.const 0)
  ;; CHECK-NEXT:          )
  ;; CHECK-NEXT:         )
  ;; CHECK-NEXT:        )
  ;; CHECK-NEXT:       )
  ;; CHECK-NEXT:       (local.set $0
  ;; CHECK-NEXT:        (i32.const 1)
  ;; CHECK-NEXT:       )
  ;; CHECK-NEXT:      )
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:     (br $outer-tryend)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $inner-try_table-catch-test (local $0 i32)
    ;; The exception thrown in the inner try_table will not be caught by the
    ;; inner catch, so the outer try_table cannot be removed.
    (block $outer-tryend
      (drop
        (block $outer-catch (result i32)
          (try_table (catch $e $outer-catch)
            (block $inner-tryend
              (drop
                (block $inner-catch (result i32)
                  (try_table (catch $e $inner-catch)
                    (throw $e2 (i32.const 0))
                  )
                  (br $inner-tryend)
                )
              )
              (local.set $0 (i32.const 1))
            )
          )
          (br $outer-tryend)
        )
      )
    )
  )

  ;; CHECK:      (func $trivial-catch-all-of-throw (type $void)
  ;; CHECK-NEXT:  (local $0 i32)
  ;; CHECK-NEXT:  (block $catch
  ;; CHECK-NEXT:   (try_table (catch_all $catch)
  ;; CHECK-NEXT:    (throw $e
  ;; CHECK-NEXT:     (i32.const 0)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (block $catch0
  ;; CHECK-NEXT:   (try_table (catch_all $catch0)
  ;; CHECK-NEXT:    (if
  ;; CHECK-NEXT:     (local.get $0)
  ;; CHECK-NEXT:     (then
  ;; CHECK-NEXT:      (throw $e
  ;; CHECK-NEXT:       (i32.const 0)
  ;; CHECK-NEXT:      )
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:     (else
  ;; CHECK-NEXT:      (unreachable)
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $trivial-catch-all-of-throw (local $0 i32)
    ;; This try_table's body throws, but the catch_all catches it, so the entire
    ;; try_table could be optimized out. We do this for `try` but not for
    ;; `try_table` - we leave such optimizations to --remove-unused-brs (that
    ;; pass can see that the throw can be converted to a br).
    
    (block $catch
      (try_table (catch_all $catch)
        (throw $e (i32.const 0))
      )
    )
    ;; Here we also have a possible trap, so we can't do it.
    (block $catch
      (try_table (catch_all $catch)
        (if
          (local.get $0)
          (then
            (throw $e (i32.const 0))
          )
          (else
            (unreachable)
          )
        )
      )
    )
  )

  ;; CHECK:      (func $throw (type $void)
  ;; CHECK-NEXT:  (throw $e
  ;; CHECK-NEXT:   (i32.const 0)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $throw
    ;; Helper for the tail call tests below.
    (throw $e
      (i32.const 0)
    )
  )

  ;; CHECK:      (func $return-call-catch (type $void)
  ;; CHECK-NEXT:  (return_call $throw)
  ;; CHECK-NEXT: )
  (func $return-call-catch
    (block $catch
      (try_table (catch_all $catch)
        ;; This returns before it throws, so we can optimize out the surrounding
        ;; try_table.
        (return_call $throw)
      )
    )
  )

  ;; CHECK:      (func $return-call-indirect-catch (type $void)
  ;; CHECK-NEXT:  (return_call_indirect $t (type $void)
  ;; CHECK-NEXT:   (i32.const 0)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $return-call-indirect-catch
    (block $catch
      (try_table (catch_all $catch)
        ;; This returns before it throws, so we can optimize out the surrounding
        ;; try_table.
        (return_call_indirect
          (i32.const 0)
        )
      )
    )
  )

  ;; CHECK:      (func $return-call-ref-catch (type $void)
  ;; CHECK-NEXT:  (return_call_ref $void
  ;; CHECK-NEXT:   (ref.func $throw)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $return-call-ref-catch
    (block $catch
      (try_table (catch_all $catch)
        ;; This returns before it throws, so we can optimize out the surrounding
        ;; try_table.
        (return_call_ref $void
          (ref.func $throw)
        )
      )
    )
  )
)