summaryrefslogtreecommitdiff
path: root/test/lit/passes/optimize-instructions-gc-extern.wast
blob: 633a18a3325d18dfb13995e79f563e482017e3e9 (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
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --optimize-instructions -all -S -o - \
;; RUN:   | filecheck %s

(module
  ;; CHECK:      (type $array (array (mut i8)))
  (type $array (array (mut i8)))

  ;; CHECK:      (func $extern.convert_any (type $0) (param $x anyref) (param $y externref)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (extern.convert_any
  ;; CHECK-NEXT:    (local.get $x)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (ref.as_non_null
  ;; CHECK-NEXT:    (extern.convert_any
  ;; CHECK-NEXT:     (local.get $x)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (any.convert_extern
  ;; CHECK-NEXT:    (local.get $y)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (ref.as_non_null
  ;; CHECK-NEXT:    (any.convert_extern
  ;; CHECK-NEXT:     (local.get $y)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $extern.convert_any (param $x (ref null any)) (param $y (ref null extern))
    ;; We should not change anything here, and also not hit an internal error.
    (drop
      (extern.convert_any
        (local.get $x)
      )
    )
    ;; We can reorder the externalize with the ref.as_non_null, which sometimes
    ;; helps later optimizations, see below.
    (drop
      (extern.convert_any
        (ref.as_non_null
          (local.get $x)
        )
      )
    )
    ;; As the above two cases, but for internalize.
    (drop
      (any.convert_extern
        (local.get $y)
      )
    )
    (drop
      (any.convert_extern
        (ref.as_non_null
          (local.get $y)
        )
      )
    )
  )

  ;; CHECK:      (func $convert.optimize.parent (type $1) (param $ext externref)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (ref.cast (ref $array)
  ;; CHECK-NEXT:    (any.convert_extern
  ;; CHECK-NEXT:     (local.get $ext)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $convert.optimize.parent (param $ext externref)
    ;; The ref.cast can fold in the ref.as_non_null, after it is moved
    ;; outside of the any.convert_extern.
    (drop
      (ref.cast (ref null $array)
        (any.convert_extern
          (ref.as_non_null
            (local.get $ext)
          )
        )
      )
    )
  )

  ;; CHECK:      (func $extern.intern (type $3) (param $ext externref) (param $any anyref)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (local.get $any)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (local.get $ext)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $extern.intern (param $ext externref) (param $any anyref)
    ;; Internalize/externalize operations cancel out.
    (drop
      (any.convert_extern
        (extern.convert_any
          (local.get $any)
        )
      )
    )
    (drop
      (extern.convert_any
        (any.convert_extern
          (local.get $ext)
        )
      )
    )
  )
)