|
| 1 | +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. |
| 2 | +;; RUN: wasm-opt %s -all --merge-blocks -all -S -o - | filecheck %s |
| 3 | + |
| 4 | +(module |
| 5 | + ;; CHECK: (import "a" "b" (func $import (type $0))) |
| 6 | + (import "a" "b" (func $import)) |
| 7 | + |
| 8 | + ;; CHECK: (tag $empty) |
| 9 | + (tag $empty) |
| 10 | + |
| 11 | + ;; CHECK: (tag $i32 (param i32)) |
| 12 | + (tag $i32 (param i32)) |
| 13 | + |
| 14 | + ;; CHECK: (tag $exnref (param exnref)) |
| 15 | + (tag $exnref (param exnref)) |
| 16 | + |
| 17 | + ;; CHECK: (func $drop-block-try_catch_all_ref (type $0) |
| 18 | + ;; CHECK-NEXT: (block $catch |
| 19 | + ;; CHECK-NEXT: (try_table (catch_all $catch) |
| 20 | + ;; CHECK-NEXT: (call $import) |
| 21 | + ;; CHECK-NEXT: (unreachable) |
| 22 | + ;; CHECK-NEXT: ) |
| 23 | + ;; CHECK-NEXT: ) |
| 24 | + ;; CHECK-NEXT: ) |
| 25 | + (func $drop-block-try_catch_all_ref |
| 26 | + ;; This block is dropped, so the try_table's exnref value can be removed |
| 27 | + ;; by replacing catch_all_ref with catch_all. |
| 28 | + (drop |
| 29 | + (block $catch (result exnref) |
| 30 | + (try_table (catch_all_ref $catch) |
| 31 | + (call $import) |
| 32 | + (unreachable) |
| 33 | + ) |
| 34 | + ) |
| 35 | + ) |
| 36 | + ) |
| 37 | + |
| 38 | + ;; CHECK: (func $drop-block-try_catch_ref (type $0) |
| 39 | + ;; CHECK-NEXT: (block $catch |
| 40 | + ;; CHECK-NEXT: (try_table (catch $empty $catch) |
| 41 | + ;; CHECK-NEXT: (call $import) |
| 42 | + ;; CHECK-NEXT: (unreachable) |
| 43 | + ;; CHECK-NEXT: ) |
| 44 | + ;; CHECK-NEXT: ) |
| 45 | + ;; CHECK-NEXT: ) |
| 46 | + (func $drop-block-try_catch_ref |
| 47 | + ;; As above, but with catch_ref instead of catch_all_ref. We can still |
| 48 | + ;; optimize. |
| 49 | + (drop |
| 50 | + (block $catch (result exnref) |
| 51 | + (try_table (catch_ref $empty $catch) |
| 52 | + (call $import) |
| 53 | + (unreachable) |
| 54 | + ) |
| 55 | + ) |
| 56 | + ) |
| 57 | + ) |
| 58 | + |
| 59 | + ;; CHECK: (func $drop-block-try_catch_multi (type $0) |
| 60 | + ;; CHECK-NEXT: (block $catch |
| 61 | + ;; CHECK-NEXT: (try_table (catch $empty $catch) (catch_all $catch) |
| 62 | + ;; CHECK-NEXT: (call $import) |
| 63 | + ;; CHECK-NEXT: (unreachable) |
| 64 | + ;; CHECK-NEXT: ) |
| 65 | + ;; CHECK-NEXT: ) |
| 66 | + ;; CHECK-NEXT: ) |
| 67 | + (func $drop-block-try_catch_multi |
| 68 | + ;; As above, but with two catches, both of whom can be optimized. |
| 69 | + (drop |
| 70 | + (block $catch (result exnref) |
| 71 | + (try_table (catch_ref $empty $catch) (catch_all_ref $catch) |
| 72 | + (call $import) |
| 73 | + (unreachable) |
| 74 | + ) |
| 75 | + ) |
| 76 | + ) |
| 77 | + ) |
| 78 | + |
| 79 | + ;; CHECK: (func $drop-block-try_catch_all_i32 (type $0) |
| 80 | + ;; CHECK-NEXT: (tuple.drop 2 |
| 81 | + ;; CHECK-NEXT: (block $catch (type $1) (result i32 exnref) |
| 82 | + ;; CHECK-NEXT: (try_table (catch_ref $i32 $catch) |
| 83 | + ;; CHECK-NEXT: (call $import) |
| 84 | + ;; CHECK-NEXT: (unreachable) |
| 85 | + ;; CHECK-NEXT: ) |
| 86 | + ;; CHECK-NEXT: ) |
| 87 | + ;; CHECK-NEXT: ) |
| 88 | + ;; CHECK-NEXT: ) |
| 89 | + (func $drop-block-try_catch_all_i32 |
| 90 | + ;; Send a tag value + exnref. We don't handle this yet TODO |
| 91 | + (tuple.drop 2 |
| 92 | + (block $catch (result i32 exnref) |
| 93 | + (try_table (catch_ref $i32 $catch) |
| 94 | + (call $import) |
| 95 | + (unreachable) |
| 96 | + ) |
| 97 | + ) |
| 98 | + ) |
| 99 | + ) |
| 100 | + |
| 101 | + ;; CHECK: (func $drop-block-try_catch_multi_partial (type $0) |
| 102 | + ;; CHECK-NEXT: (tuple.drop 2 |
| 103 | + ;; CHECK-NEXT: (block $outer (type $1) (result i32 exnref) |
| 104 | + ;; CHECK-NEXT: (block $inner |
| 105 | + ;; CHECK-NEXT: (try_table (catch_ref $i32 $outer) (catch_all $inner) |
| 106 | + ;; CHECK-NEXT: (call $import) |
| 107 | + ;; CHECK-NEXT: (unreachable) |
| 108 | + ;; CHECK-NEXT: ) |
| 109 | + ;; CHECK-NEXT: ) |
| 110 | + ;; CHECK-NEXT: (unreachable) |
| 111 | + ;; CHECK-NEXT: ) |
| 112 | + ;; CHECK-NEXT: ) |
| 113 | + ;; CHECK-NEXT: ) |
| 114 | + (func $drop-block-try_catch_multi_partial |
| 115 | + ;; Two catches, one of which we can optimize, but not both. |
| 116 | + (tuple.drop 2 |
| 117 | + (block $outer (result i32 exnref) |
| 118 | + (drop |
| 119 | + (block $inner (result exnref) |
| 120 | + (try_table (catch_ref $i32 $outer) (catch_all_ref $inner) |
| 121 | + (call $import) |
| 122 | + (unreachable) |
| 123 | + ) |
| 124 | + ) |
| 125 | + ) |
| 126 | + (unreachable) |
| 127 | + ) |
| 128 | + ) |
| 129 | + ) |
| 130 | + |
| 131 | + ;; CHECK: (func $drop-block_try_catch_multi-fail (type $0) |
| 132 | + ;; CHECK-NEXT: (drop |
| 133 | + ;; CHECK-NEXT: (block $catch (result exnref) |
| 134 | + ;; CHECK-NEXT: (try_table (catch $exnref $catch) (catch_all_ref $catch) |
| 135 | + ;; CHECK-NEXT: (call $import) |
| 136 | + ;; CHECK-NEXT: (unreachable) |
| 137 | + ;; CHECK-NEXT: ) |
| 138 | + ;; CHECK-NEXT: ) |
| 139 | + ;; CHECK-NEXT: ) |
| 140 | + ;; CHECK-NEXT: ) |
| 141 | + (func $drop-block_try_catch_multi-fail |
| 142 | + (drop |
| 143 | + ;; This block is sent an exnref in two ways: once as the contents of a tag |
| 144 | + ;; and once as the ref of a catch_all_ref. We can remove the latter but |
| 145 | + ;; not the former, and they go to the same block, so we cannot optimize. |
| 146 | + (block $catch (result exnref) |
| 147 | + (try_table (catch $exnref $catch) (catch_all_ref $catch) |
| 148 | + (call $import) |
| 149 | + (unreachable) |
| 150 | + ) |
| 151 | + ) |
| 152 | + ) |
| 153 | + ) |
| 154 | + |
| 155 | + ;; CHECK: (func $drop-block-try_catch_all (type $0) |
| 156 | + ;; CHECK-NEXT: (block $catch |
| 157 | + ;; CHECK-NEXT: (try_table (catch_all $catch) |
| 158 | + ;; CHECK-NEXT: (call $import) |
| 159 | + ;; CHECK-NEXT: (unreachable) |
| 160 | + ;; CHECK-NEXT: ) |
| 161 | + ;; CHECK-NEXT: ) |
| 162 | + ;; CHECK-NEXT: ) |
| 163 | + (func $drop-block-try_catch_all |
| 164 | + ;; Without _ref, there is nothing to optimize (and we should not error). |
| 165 | + ;; Also since there is no ref, there is no drop anyhow. |
| 166 | + (block $catch |
| 167 | + (try_table (catch_all $catch) |
| 168 | + (call $import) |
| 169 | + (unreachable) |
| 170 | + ) |
| 171 | + ) |
| 172 | + ) |
| 173 | + |
| 174 | + ;; CHECK: (func $drop-block-try_catch (type $0) |
| 175 | + ;; CHECK-NEXT: (block $catch |
| 176 | + ;; CHECK-NEXT: (try_table (catch $empty $catch) |
| 177 | + ;; CHECK-NEXT: (call $import) |
| 178 | + ;; CHECK-NEXT: (unreachable) |
| 179 | + ;; CHECK-NEXT: ) |
| 180 | + ;; CHECK-NEXT: ) |
| 181 | + ;; CHECK-NEXT: ) |
| 182 | + (func $drop-block-try_catch |
| 183 | + ;; As above, but with a catch instead of catch_all. |
| 184 | + (block $catch |
| 185 | + (try_table (catch $empty $catch) |
| 186 | + (call $import) |
| 187 | + (unreachable) |
| 188 | + ) |
| 189 | + ) |
| 190 | + ) |
| 191 | + |
| 192 | + ;; CHECK: (func $drop-block-try_catch_i32 (type $0) |
| 193 | + ;; CHECK-NEXT: (drop |
| 194 | + ;; CHECK-NEXT: (block $catch (result i32) |
| 195 | + ;; CHECK-NEXT: (try_table (catch $i32 $catch) |
| 196 | + ;; CHECK-NEXT: (call $import) |
| 197 | + ;; CHECK-NEXT: (unreachable) |
| 198 | + ;; CHECK-NEXT: ) |
| 199 | + ;; CHECK-NEXT: ) |
| 200 | + ;; CHECK-NEXT: ) |
| 201 | + ;; CHECK-NEXT: ) |
| 202 | + (func $drop-block-try_catch_i32 |
| 203 | + ;; Send an i32 without a ref. We can't optimize here, as we can't prevent |
| 204 | + ;; the i32 from being sent. |
| 205 | + (drop |
| 206 | + (block $catch (result i32) |
| 207 | + (try_table (catch $i32 $catch) |
| 208 | + (call $import) |
| 209 | + (unreachable) |
| 210 | + ) |
| 211 | + ) |
| 212 | + ) |
| 213 | + ) |
| 214 | +) |
| 215 | + |
0 commit comments