blob: 674361080a5cc8ee5633508ccc91639a3c4c3df8 (
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
|
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --simplify-locals -all -S -o - | filecheck %s
(module
;; CHECK: (func $test-nn (type $0)
;; CHECK-NEXT: (local $nn anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: (try
;; CHECK-NEXT: (do
;; CHECK-NEXT: (local.set $nn
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (catch_all
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (local.get $nn)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test-nn
(local $nn (ref any))
;; We can sink this set into the try, but the spec does not allow it to
;; remain non-nullable. Even though we are not changing dominance (we are
;; not changing it, because there is nothing that can throw in the try's
;; body that can reach the catch_all before the local.set that we move
;; there). See
;; https://github.com/WebAssembly/function-references/issues/44#issuecomment-1083146887
(local.set $nn
(ref.as_non_null
(ref.null any)
)
)
(try
(do
(drop
(local.get $nn)
)
)
(catch_all
(drop
(local.get $nn)
)
)
)
)
;; CHECK: (func $test-nn-tuple (type $0)
;; CHECK-NEXT: (local $nn (tuple i32 anyref i64))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: (try
;; CHECK-NEXT: (do
;; CHECK-NEXT: (local.set $nn
;; CHECK-NEXT: (tuple.make 3
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: (i64.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (catch_all
;; CHECK-NEXT: (tuple.drop 3
;; CHECK-NEXT: (tuple.make 3
;; CHECK-NEXT: (tuple.extract 3 0
;; CHECK-NEXT: (local.get $nn)
;; CHECK-NEXT: )
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (tuple.extract 3 1
;; CHECK-NEXT: (local.get $nn)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (tuple.extract 3 2
;; CHECK-NEXT: (local.get $nn)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test-nn-tuple
;; Same as above, but now the local is a tuple containing a non-nullable element
(local $nn (tuple i32 (ref any) i64))
(local.set $nn
(tuple.make 3
(i32.const 0)
(ref.as_non_null
(ref.null any)
)
(i64.const 0)
)
)
(try
(do
(tuple.drop 3
(local.get $nn)
)
)
(catch_all
(tuple.drop 3
(local.get $nn)
)
)
)
)
;; CHECK: (func $test-nullable (type $0)
;; CHECK-NEXT: (local $nullable anyref)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: (try
;; CHECK-NEXT: (do
;; CHECK-NEXT: (local.set $nullable
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (catch_all
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.get $nullable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test-nullable
;; As above, but now the local is nullable. Here we can optimize the set
;; into the try, with no other necessary changes.
(local $nullable (ref null any))
(local.set $nullable
(ref.as_non_null
(ref.null any)
)
)
(try
(do
(drop
(local.get $nullable)
)
)
(catch_all
(drop
(local.get $nullable)
)
)
)
)
;; CHECK: (func $if-return-tuple-nn (type $0)
;; CHECK-NEXT: (local $temp (tuple (ref func) nullref))
;; CHECK-NEXT: (if
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $if-return-tuple-nn
(local $temp (tuple (ref func) (ref null none)))
;; We should not emit a return value for this if, as the tuple has a non-
;; nullable element, so it is nondefaultable.
;;
;; Instead, we can remove the local.set entirely, as it has no gets.
(if
(i32.const 0)
(then
(local.set $temp
(tuple.make 2
(ref.func $if-return-tuple-nn)
(ref.null none)
)
)
)
)
)
)
|