|
203 | 203 |
|
204 | 204 | ;; CHECK: (type $4 (func (param anyref)))
|
205 | 205 |
|
| 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 | + |
206 | 209 | ;; CHECK: (global $B.desc (ref $B.desc) (struct.new_default $B.desc))
|
207 | 210 | (global $B.desc (ref $B.desc) (struct.new $B.desc))
|
208 | 211 |
|
| 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 | + |
209 | 258 | ;; CHECK: (global $A.desc (ref $A.desc) (struct.new_default $A.desc))
|
210 | 259 | (global $A.desc (ref $A.desc) (struct.new $A.desc))
|
211 | 260 |
|
| 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 | + |
212 | 264 | ;; CHECK: (func $test (type $4) (param $any anyref)
|
213 | 265 | ;; CHECK-NEXT: (drop
|
214 | 266 | ;; CHECK-NEXT: (ref.cast (ref $A)
|
|
223 | 275 | ;; CHECK-NEXT: )
|
224 | 276 | ;; CHECK-NEXT: )
|
225 | 277 | (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. |
228 | 332 | (drop
|
229 | 333 | (ref.cast (ref $A)
|
230 | 334 | (local.get $any)
|
|
0 commit comments