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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --remove-unused-brs -all -S --shrink-level=0 -o - | filecheck %s --check-prefix=SHRINK_0
;; RUN: wasm-opt %s --remove-unused-brs -all -S --shrink-level=1 -o - | filecheck %s --check-prefix=SHRINK_1
;; RUN: wasm-opt %s --remove-unused-brs -all -S --shrink-level=2 -o - | filecheck %s --check-prefix=SHRINK_2
(module
;; SHRINK_0: (type $struct (sub (struct)))
;; SHRINK_1: (type $struct (sub (struct)))
;; SHRINK_2: (type $struct (sub (struct)))
(type $struct (sub (struct)))
;; SHRINK_0: (type $substruct (sub $struct (struct)))
;; SHRINK_1: (type $substruct (sub $struct (struct)))
;; SHRINK_2: (type $substruct (sub $struct (struct)))
(type $substruct (sub $struct (struct)))
;; SHRINK_0: (func $selectify-division (type $2) (param $x i32) (result i32)
;; SHRINK_0-NEXT: (if (result i32)
;; SHRINK_0-NEXT: (i32.eq
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: (i32.const 53498923)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (then
;; SHRINK_0-NEXT: (i32.div_s
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: (i32.const 13)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (else
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_1: (func $selectify-division (type $2) (param $x i32) (result i32)
;; SHRINK_1-NEXT: (select
;; SHRINK_1-NEXT: (i32.div_s
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: (i32.const 13)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: (i32.eq
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: (i32.const 53498923)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_2: (func $selectify-division (type $2) (param $x i32) (result i32)
;; SHRINK_2-NEXT: (select
;; SHRINK_2-NEXT: (i32.div_s
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: (i32.const 13)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: (i32.eq
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: (i32.const 53498923)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
(func $selectify-division (param $x i32) (result i32)
;; See #5983: this if, if turned into a select, becomes almost 5x slower.
;; We only want to selectify here when the shrink level is 1 or 2.
(if (result i32)
(i32.eq
(local.get $x)
(i32.const 53498923)
)
(then
(i32.div_s
(local.get $x)
(i32.const 13)
)
)
(else
(local.get $x)
)
)
)
;; SHRINK_0: (func $selectify-division2 (type $2) (param $x i32) (result i32)
;; SHRINK_0-NEXT: (if (result i32)
;; SHRINK_0-NEXT: (i32.eq
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: (i32.const 53498923)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (then
;; SHRINK_0-NEXT: (i32.div_s
;; SHRINK_0-NEXT: (i32.div_s
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: (i32.const 13)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (i32.const 13)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (else
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_1: (func $selectify-division2 (type $2) (param $x i32) (result i32)
;; SHRINK_1-NEXT: (if (result i32)
;; SHRINK_1-NEXT: (i32.eq
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: (i32.const 53498923)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: (then
;; SHRINK_1-NEXT: (i32.div_s
;; SHRINK_1-NEXT: (i32.div_s
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: (i32.const 13)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: (i32.const 13)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: (else
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_2: (func $selectify-division2 (type $2) (param $x i32) (result i32)
;; SHRINK_2-NEXT: (select
;; SHRINK_2-NEXT: (i32.div_s
;; SHRINK_2-NEXT: (i32.div_s
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: (i32.const 13)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: (i32.const 13)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: (i32.eq
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: (i32.const 53498923)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
(func $selectify-division2 (param $x i32) (result i32)
;; As above, but now only with a shrink level of 2 should we selectify, as
;; there are two divisions.
(if (result i32)
(i32.eq
(local.get $x)
(i32.const 53498923)
)
(then
(i32.div_s
(i32.div_s
(local.get $x)
(i32.const 13)
)
(i32.const 13)
)
)
(else
(local.get $x)
)
)
)
;; SHRINK_0: (func $if-tests (type $3) (param $x (ref $struct)) (param $y (ref $struct)) (result i32)
;; SHRINK_0-NEXT: (if (result i32)
;; SHRINK_0-NEXT: (ref.test (ref $substruct)
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (then
;; SHRINK_0-NEXT: (ref.test (ref $substruct)
;; SHRINK_0-NEXT: (local.get $y)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (else
;; SHRINK_0-NEXT: (i32.const 0)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_1: (func $if-tests (type $3) (param $x (ref $struct)) (param $y (ref $struct)) (result i32)
;; SHRINK_1-NEXT: (select
;; SHRINK_1-NEXT: (ref.test (ref $substruct)
;; SHRINK_1-NEXT: (local.get $y)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: (i32.const 0)
;; SHRINK_1-NEXT: (ref.test (ref $substruct)
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_2: (func $if-tests (type $3) (param $x (ref $struct)) (param $y (ref $struct)) (result i32)
;; SHRINK_2-NEXT: (select
;; SHRINK_2-NEXT: (ref.test (ref $substruct)
;; SHRINK_2-NEXT: (local.get $y)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: (i32.const 0)
;; SHRINK_2-NEXT: (ref.test (ref $substruct)
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
(func $if-tests (param $x (ref $struct)) (param $y (ref $struct)) (result i32)
;; An If with a test in one arm (and also in a condition). We do not
;; normally turn this into a Select, as the test is more costly than the If.
;; But we do so when optimizing for size.
;;
;; TODO: Consider optimizing this because the other arm is a 0, which means
;; the Select can turn into an And later.
(if (result i32)
(ref.test (ref $substruct)
(local.get $x)
)
(then
(ref.test (ref $substruct)
(local.get $y)
)
)
(else
(i32.const 0)
)
)
)
;; SHRINK_0: (func $if-tests-arms (type $4) (param $x (ref $struct)) (param $y (ref $struct)) (param $z (ref $struct)) (result i32)
;; SHRINK_0-NEXT: (if (result i32)
;; SHRINK_0-NEXT: (ref.test (ref $substruct)
;; SHRINK_0-NEXT: (local.get $x)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (then
;; SHRINK_0-NEXT: (ref.test (ref $substruct)
;; SHRINK_0-NEXT: (local.get $y)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: (else
;; SHRINK_0-NEXT: (ref.test (ref $substruct)
;; SHRINK_0-NEXT: (local.get $z)
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_0-NEXT: )
;; SHRINK_1: (func $if-tests-arms (type $4) (param $x (ref $struct)) (param $y (ref $struct)) (param $z (ref $struct)) (result i32)
;; SHRINK_1-NEXT: (select
;; SHRINK_1-NEXT: (ref.test (ref $substruct)
;; SHRINK_1-NEXT: (local.get $y)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: (ref.test (ref $substruct)
;; SHRINK_1-NEXT: (local.get $z)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: (ref.test (ref $substruct)
;; SHRINK_1-NEXT: (local.get $x)
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_1-NEXT: )
;; SHRINK_2: (func $if-tests-arms (type $4) (param $x (ref $struct)) (param $y (ref $struct)) (param $z (ref $struct)) (result i32)
;; SHRINK_2-NEXT: (select
;; SHRINK_2-NEXT: (ref.test (ref $substruct)
;; SHRINK_2-NEXT: (local.get $y)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: (ref.test (ref $substruct)
;; SHRINK_2-NEXT: (local.get $z)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: (ref.test (ref $substruct)
;; SHRINK_2-NEXT: (local.get $x)
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
;; SHRINK_2-NEXT: )
(func $if-tests-arms (param $x (ref $struct)) (param $y (ref $struct)) (param $z (ref $struct)) (result i32)
;; As above but now with a test in both arms. The outcomes are the same.
(if (result i32)
(ref.test (ref $substruct)
(local.get $x)
)
(then
(ref.test (ref $substruct)
(local.get $y)
)
)
(else
(ref.test (ref $substruct)
(local.get $z)
)
)
)
)
)
|