|
| 1 | +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. |
| 2 | +;; RUN: wasm-opt %s --ignore-implicit-traps --optimize-instructions -all -S -o - \ |
| 3 | +;; RUN: | filecheck %s |
| 4 | + |
| 5 | +(module |
| 6 | + ;; CHECK: (type $struct.A (struct (field i32))) |
| 7 | + (type $struct.A (struct i32)) |
| 8 | + ;; CHECK: (global $g-struct.A (rtt $struct.A) (rtt.canon $struct.A)) |
| 9 | + |
| 10 | + ;; CHECK: (tag $e (param (ref null $struct.A))) |
| 11 | + (tag $e (param (ref null $struct.A))) |
| 12 | + (global $g-struct.A (rtt $struct.A) (rtt.canon $struct.A)) |
| 13 | + |
| 14 | + ;; CHECK: (func $ref-cast-statically-removed |
| 15 | + ;; CHECK-NEXT: (local $0 (ref null $struct.A)) |
| 16 | + ;; CHECK-NEXT: (local $1 (ref null $struct.A)) |
| 17 | + ;; CHECK-NEXT: (try $try |
| 18 | + ;; CHECK-NEXT: (do |
| 19 | + ;; CHECK-NEXT: (nop) |
| 20 | + ;; CHECK-NEXT: ) |
| 21 | + ;; CHECK-NEXT: (catch $e |
| 22 | + ;; CHECK-NEXT: (local.set $1 |
| 23 | + ;; CHECK-NEXT: (pop (ref null $struct.A)) |
| 24 | + ;; CHECK-NEXT: ) |
| 25 | + ;; CHECK-NEXT: (throw $e |
| 26 | + ;; CHECK-NEXT: (block (result (ref null $struct.A)) |
| 27 | + ;; CHECK-NEXT: (local.set $0 |
| 28 | + ;; CHECK-NEXT: (local.get $1) |
| 29 | + ;; CHECK-NEXT: ) |
| 30 | + ;; CHECK-NEXT: (drop |
| 31 | + ;; CHECK-NEXT: (global.get $g-struct.A) |
| 32 | + ;; CHECK-NEXT: ) |
| 33 | + ;; CHECK-NEXT: (local.get $0) |
| 34 | + ;; CHECK-NEXT: ) |
| 35 | + ;; CHECK-NEXT: ) |
| 36 | + ;; CHECK-NEXT: ) |
| 37 | + ;; CHECK-NEXT: ) |
| 38 | + ;; CHECK-NEXT: ) |
| 39 | + (func $ref-cast-statically-removed |
| 40 | + (try |
| 41 | + (do) |
| 42 | + (catch $e |
| 43 | + (throw $e |
| 44 | + ;; Because --ignore-implicit-traps is given, this ref.cast is assumed |
| 45 | + ;; not to throw so this ref.cast can be statically removed. But that |
| 46 | + ;; creates a block around this, making 'pop' nested into it, which is |
| 47 | + ;; invalid. We fix this up at the end up OptimizeInstruction, |
| 48 | + ;; assigning the 'pop' to a local at the start of this 'catch' body |
| 49 | + ;; and later using 'local.get' to get it. |
| 50 | + (ref.cast |
| 51 | + (pop (ref null $struct.A)) |
| 52 | + (global.get $g-struct.A) |
| 53 | + ) |
| 54 | + ) |
| 55 | + ) |
| 56 | + ) |
| 57 | + ) |
| 58 | +) |
0 commit comments