Skip to content

Commit 10d80a7

Browse files
committed
test
1 parent 7691673 commit 10d80a7

File tree

1 file changed

+106
-2
lines changed

1 file changed

+106
-2
lines changed

test/lit/passes/gsi-desc.wast

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,64 @@
203203

204204
;; CHECK: (type $4 (func (param anyref)))
205205

206+
;; CHECK: (global $A.desc (ref $A.desc) (struct.new_default $A.desc))
207+
(global $A.desc (ref $A.desc) (struct.new $A.desc))
208+
206209
;; CHECK: (global $B.desc (ref $B.desc) (struct.new_default $B.desc))
207210
(global $B.desc (ref $B.desc) (struct.new $B.desc))
208211

212+
;; CHECK: (func $test (type $4) (param $any anyref)
213+
;; CHECK-NEXT: (drop
214+
;; CHECK-NEXT: (ref.cast (ref $A)
215+
;; CHECK-NEXT: (local.get $any)
216+
;; CHECK-NEXT: )
217+
;; CHECK-NEXT: )
218+
;; CHECK-NEXT: (drop
219+
;; CHECK-NEXT: (ref.cast_desc (ref $B)
220+
;; CHECK-NEXT: (local.get $any)
221+
;; CHECK-NEXT: (global.get $B.desc)
222+
;; CHECK-NEXT: )
223+
;; CHECK-NEXT: )
224+
;; CHECK-NEXT: )
225+
(func $test (param $any anyref)
226+
;; The second cast here is optimizable: it can only be to a single type with
227+
;; no subtypes, so we can use ref.cast_desc.
228+
(drop
229+
(ref.cast (ref $A)
230+
(local.get $any)
231+
)
232+
)
233+
(drop
234+
(ref.cast (ref $B)
235+
(local.get $any)
236+
)
237+
)
238+
)
239+
)
240+
241+
;; As above, but without subtyping between $A and $B.
242+
(module
243+
(rec
244+
;; CHECK: (rec
245+
;; CHECK-NEXT: (type $A (sub (descriptor $A.desc (struct))))
246+
(type $A (sub (descriptor $A.desc (struct))))
247+
;; CHECK: (type $A.desc (sub (describes $A (struct))))
248+
(type $A.desc (sub (describes $A (struct))))
249+
250+
;; CHECK: (type $B (sub (descriptor $B.desc (struct))))
251+
(type $B (sub (descriptor $B.desc (struct))))
252+
;; CHECK: (type $B.desc (sub $A.desc (describes $B (struct))))
253+
(type $B.desc (sub $A.desc (describes $B (struct))))
254+
)
255+
256+
;; CHECK: (type $4 (func (param anyref)))
257+
209258
;; CHECK: (global $A.desc (ref $A.desc) (struct.new_default $A.desc))
210259
(global $A.desc (ref $A.desc) (struct.new $A.desc))
211260

261+
;; CHECK: (global $B.desc (ref $B.desc) (struct.new_default $B.desc))
262+
(global $B.desc (ref $B.desc) (struct.new $B.desc))
263+
212264
;; CHECK: (func $test (type $4) (param $any anyref)
213265
;; CHECK-NEXT: (drop
214266
;; CHECK-NEXT: (ref.cast (ref $A)
@@ -223,8 +275,60 @@
223275
;; CHECK-NEXT: )
224276
;; CHECK-NEXT: )
225277
(func $test (param $any anyref)
226-
;; The second cast here is optimizable: it can only be to a single type with
227-
;; no subtypes, so we can use ref.cast_desc.
278+
;; We still cannot optimize $A: while $A has no subtypes, the descriptor
279+
;; $A.desc has a subtype. We could optimize this TODO
280+
(drop
281+
(ref.cast (ref $A)
282+
(local.get $any)
283+
)
284+
)
285+
(drop
286+
(ref.cast (ref $B)
287+
(local.get $any)
288+
)
289+
)
290+
)
291+
)
292+
293+
;; As above, but without subtyping between $A.desc and $B.desc.
294+
(module
295+
(rec
296+
;; CHECK: (rec
297+
;; CHECK-NEXT: (type $A (sub (descriptor $A.desc (struct))))
298+
(type $A (sub (descriptor $A.desc (struct))))
299+
;; CHECK: (type $A.desc (sub (describes $A (struct))))
300+
(type $A.desc (sub (describes $A (struct))))
301+
302+
;; CHECK: (type $B (sub (descriptor $B.desc (struct))))
303+
(type $B (sub (descriptor $B.desc (struct))))
304+
;; CHECK: (type $B.desc (sub (describes $B (struct))))
305+
(type $B.desc (sub (describes $B (struct))))
306+
)
307+
308+
;; CHECK: (type $4 (func (param anyref)))
309+
310+
;; CHECK: (global $A.desc (ref $A.desc) (struct.new_default $A.desc))
311+
(global $A.desc (ref $A.desc) (struct.new $A.desc))
312+
313+
;; CHECK: (global $B.desc (ref $B.desc) (struct.new_default $B.desc))
314+
(global $B.desc (ref $B.desc) (struct.new $B.desc))
315+
316+
;; CHECK: (func $test (type $4) (param $any anyref)
317+
;; CHECK-NEXT: (drop
318+
;; CHECK-NEXT: (ref.cast_desc (ref $A)
319+
;; CHECK-NEXT: (local.get $any)
320+
;; CHECK-NEXT: (global.get $A.desc)
321+
;; CHECK-NEXT: )
322+
;; CHECK-NEXT: )
323+
;; CHECK-NEXT: (drop
324+
;; CHECK-NEXT: (ref.cast_desc (ref $B)
325+
;; CHECK-NEXT: (local.get $any)
326+
;; CHECK-NEXT: (global.get $B.desc)
327+
;; CHECK-NEXT: )
328+
;; CHECK-NEXT: )
329+
;; CHECK-NEXT: )
330+
(func $test (param $any anyref)
331+
;; We can fully optimize these two independent cases.
228332
(drop
229333
(ref.cast (ref $A)
230334
(local.get $any)

0 commit comments

Comments
 (0)