Debian Codegraph @

internal/engine/wazevo/frontend/frontend_test.go

raw
1 package frontend
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/tetratelabs/wazero/api"
8 "github.com/tetratelabs/wazero/experimental"
9 "github.com/tetratelabs/wazero/internal/engine/wazevo/ssa"
10 "github.com/tetratelabs/wazero/internal/engine/wazevo/testcases"
11 "github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi"
12 "github.com/tetratelabs/wazero/internal/testing/require"
13 "github.com/tetratelabs/wazero/internal/wasm"
14 )
15
16 func TestCompiler_LowerToSSA(t *testing.T) {
17 // Most of the logic should look similar to Cranelift's Wasm frontend, so when you want to see
18 // what output should look like, you can run:
19 // `~/wasmtime/target/debug/clif-util wasm --target aarch64-apple-darwin testcase.wat -p -t`
20 for _, tc := range []struct {
21 name string
22 ensureTermination bool
23 needListener bool
24 // m is the *wasm.Module to be compiled in this test.
25 m *wasm.Module
26 // targetIndex is the index of a local function to be compiled in this test.
27 targetIndex wasm.Index
28 // exp is the *unoptimized* expected SSA IR for the function m.FunctionSection[targetIndex].
29 exp string
30 // expAfterPasses is not empty when we want to check the result after SSA passes.
31 expAfterPasses string
32 features api.CoreFeatures
33 }{
34 {
35 name: "empty", m: testcases.Empty.Module,
36 exp: `
37 blk0: (exec_ctx:i64, module_ctx:i64)
38 Jump blk_ret
39 `,
40 },
41 {
42 name: "unreachable", m: testcases.Unreachable.Module,
43 exp: `
44 blk0: (exec_ctx:i64, module_ctx:i64)
45 Exit exec_ctx, unreachable
46 `,
47 },
48 {
49 name: testcases.OnlyReturn.Name, m: testcases.OnlyReturn.Module,
50 exp: `
51 blk0: (exec_ctx:i64, module_ctx:i64)
52 Return
53 `,
54 },
55 {
56 name: "params", m: testcases.Params.Module,
57 exp: `
58 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:f32, v4:f64)
59 Return
60 `,
61 },
62 {
63 name: "add/sub params return", m: testcases.AddSubParamsReturn.Module,
64 exp: `
65 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
66 v4:i32 = Iadd v2, v3
67 v5:i32 = Isub v4, v2
68 Jump blk_ret, v5
69 `,
70 },
71 {
72 name: "add/sub params return / listener", m: testcases.AddSubParamsReturn.Module,
73 needListener: true,
74 exp: `
75 signatures:
76 sig1: i64i32i32i32_v
77 sig2: i64i32i32_v
78
79 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
80 Store module_ctx, exec_ctx, 0x8
81 v4:i64 = Load module_ctx, 0x8
82 v5:i64 = Load v4, 0x0
83 v6:i32 = Iconst_32 0x0
84 CallIndirect v5:sig1, exec_ctx, v6, v2, v3
85 v7:i32 = Iadd v2, v3
86 v8:i32 = Isub v7, v2
87 Store module_ctx, exec_ctx, 0x8
88 v9:i64 = Load module_ctx, 0x10
89 v10:i64 = Load v9, 0x0
90 v11:i32 = Iconst_32 0x0
91 CallIndirect v10:sig2, exec_ctx, v11, v8
92 Jump blk_ret, v8
93 `,
94 },
95 {
96 name: "locals", m: testcases.Locals.Module,
97 exp: `
98 blk0: (exec_ctx:i64, module_ctx:i64)
99 v2:i32 = Iconst_32 0x0
100 v3:i64 = Iconst_64 0x0
101 v4:f32 = F32const 0.000000
102 v5:f64 = F64const 0.000000
103 Jump blk_ret
104 `,
105 expAfterPasses: `
106 blk0: (exec_ctx:i64, module_ctx:i64)
107 Jump blk_ret
108 `,
109 },
110 {
111 name: "selects", m: testcases.Selects.Module,
112 exp: `
113 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i64, v5:i64, v6:f32, v7:f32, v8:f64, v9:f64)
114 v10:i32 = Icmp eq, v4, v5
115 v11:i32 = Select v10, v2, v3
116 v12:i64 = Select v3, v4, v5
117 v13:i32 = Fcmp gt, v8, v9
118 v14:f32 = Select v13, v6, v7
119 v15:i32 = Fcmp neq, v6, v7
120 v16:f64 = Select v15, v8, v9
121 Jump blk_ret, v11, v12, v14, v16
122 `,
123 },
124 {
125 name: "local param tee return", m: testcases.LocalParamTeeReturn.Module,
126 exp: `
127 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
128 v3:i32 = Iconst_32 0x0
129 Jump blk_ret, v2, v2
130 `,
131 expAfterPasses: `
132 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
133 Jump blk_ret, v2, v2
134 `,
135 },
136 {
137 name: "locals + params", m: testcases.LocalsParams.Module,
138 exp: `
139 blk0: (exec_ctx:i64, module_ctx:i64, v2:i64, v3:f32, v4:f64)
140 v5:i32 = Iconst_32 0x0
141 v6:i64 = Iconst_64 0x0
142 v7:f32 = F32const 0.000000
143 v8:f64 = F64const 0.000000
144 v9:i64 = Iadd v2, v2
145 v10:i64 = Isub v9, v2
146 v11:f32 = Fadd v3, v3
147 v12:f32 = Fsub v11, v3
148 v13:f32 = Fmul v12, v3
149 v14:f32 = Fdiv v13, v3
150 v15:f32 = Fmax v14, v3
151 v16:f32 = Fmin v15, v3
152 v17:f64 = Fadd v4, v4
153 v18:f64 = Fsub v17, v4
154 v19:f64 = Fmul v18, v4
155 v20:f64 = Fdiv v19, v4
156 v21:f64 = Fmax v20, v4
157 v22:f64 = Fmin v21, v4
158 Jump blk_ret, v10, v16, v22
159 `,
160 expAfterPasses: `
161 blk0: (exec_ctx:i64, module_ctx:i64, v2:i64, v3:f32, v4:f64)
162 v9:i64 = Iadd v2, v2
163 v10:i64 = Isub v9, v2
164 v11:f32 = Fadd v3, v3
165 v12:f32 = Fsub v11, v3
166 v13:f32 = Fmul v12, v3
167 v14:f32 = Fdiv v13, v3
168 v15:f32 = Fmax v14, v3
169 v16:f32 = Fmin v15, v3
170 v17:f64 = Fadd v4, v4
171 v18:f64 = Fsub v17, v4
172 v19:f64 = Fmul v18, v4
173 v20:f64 = Fdiv v19, v4
174 v21:f64 = Fmax v20, v4
175 v22:f64 = Fmin v21, v4
176 Jump blk_ret, v10, v16, v22
177 `,
178 },
179 {
180 name: "locals + params + return", m: testcases.LocalParamReturn.Module,
181 exp: `
182 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
183 v3:i32 = Iconst_32 0x0
184 Jump blk_ret, v2, v3
185 `,
186 },
187 {
188 name: "swap param and return", m: testcases.SwapParamAndReturn.Module,
189 exp: `
190 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
191 Jump blk_ret, v3, v2
192 `,
193 },
194 {
195 name: "swap params and return", m: testcases.SwapParamsAndReturn.Module,
196 exp: `
197 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
198 Jump blk1
199
200 blk1: () <-- (blk0)
201 Jump blk_ret, v3, v2
202 `,
203 },
204 {
205 name: "block - br", m: testcases.BlockBr.Module,
206 exp: `
207 blk0: (exec_ctx:i64, module_ctx:i64)
208 v2:i32 = Iconst_32 0x0
209 v3:i64 = Iconst_64 0x0
210 v4:f32 = F32const 0.000000
211 v5:f64 = F64const 0.000000
212 Jump blk1
213
214 blk1: () <-- (blk0)
215 Jump blk_ret
216 `,
217 },
218 {
219 name: "block - br_if", m: testcases.BlockBrIf.Module,
220 exp: `
221 blk0: (exec_ctx:i64, module_ctx:i64)
222 v2:i32 = Iconst_32 0x0
223 Brnz v2, blk1
224 Jump blk2
225
226 blk1: () <-- (blk0)
227 Jump blk_ret
228
229 blk2: () <-- (blk0)
230 Exit exec_ctx, unreachable
231 `,
232 },
233 {
234 name: "loop - br", m: testcases.LoopBr.Module,
235 exp: `
236 blk0: (exec_ctx:i64, module_ctx:i64)
237 Jump blk1
238
239 blk1: () <-- (blk0,blk1)
240 Jump blk1
241
242 blk2: ()
243 `,
244 expAfterPasses: `
245 blk0: (exec_ctx:i64, module_ctx:i64)
246 Jump fallthrough
247
248 blk1: () <-- (blk0,blk1)
249 Jump blk1
250 `,
251 },
252 {
253 name: "loop - br / ensure termination", m: testcases.LoopBr.Module,
254 ensureTermination: true,
255 exp: `
256 signatures:
257 sig2: i64_v
258
259 blk0: (exec_ctx:i64, module_ctx:i64)
260 Jump blk1
261
262 blk1: () <-- (blk0,blk1)
263 v2:i64 = Load exec_ctx, 0x58
264 CallIndirect v2:sig2, exec_ctx
265 Jump blk1
266
267 blk2: ()
268 `,
269 expAfterPasses: `
270 signatures:
271 sig2: i64_v
272
273 blk0: (exec_ctx:i64, module_ctx:i64)
274 Jump fallthrough
275
276 blk1: () <-- (blk0,blk1)
277 v2:i64 = Load exec_ctx, 0x58
278 CallIndirect v2:sig2, exec_ctx
279 Jump blk1
280 `,
281 },
282 {
283 name: "loop - br_if", m: testcases.LoopBrIf.Module,
284 exp: `
285 blk0: (exec_ctx:i64, module_ctx:i64)
286 Jump blk1
287
288 blk1: () <-- (blk0,blk1)
289 v2:i32 = Iconst_32 0x1
290 Brnz v2, blk1
291 Jump blk3
292
293 blk2: ()
294
295 blk3: () <-- (blk1)
296 Return
297 `,
298 expAfterPasses: `
299 blk0: (exec_ctx:i64, module_ctx:i64)
300 Jump fallthrough
301
302 blk1: () <-- (blk0,blk4)
303 v2:i32 = Iconst_32 0x1
304 Brz v2, blk3
305 Jump fallthrough
306
307 blk4: () <-- (blk1)
308 Jump blk1
309
310 blk3: () <-- (blk1)
311 Return
312 `,
313 },
314 {
315 name: "block - block - br", m: testcases.BlockBlockBr.Module,
316 exp: `
317 blk0: (exec_ctx:i64, module_ctx:i64)
318 v2:i32 = Iconst_32 0x0
319 v3:i64 = Iconst_64 0x0
320 v4:f32 = F32const 0.000000
321 v5:f64 = F64const 0.000000
322 Jump blk1
323
324 blk1: () <-- (blk0)
325 Jump blk_ret
326
327 blk2: ()
328 `,
329 expAfterPasses: `
330 blk0: (exec_ctx:i64, module_ctx:i64)
331 Jump fallthrough
332
333 blk1: () <-- (blk0)
334 Jump blk_ret
335 `,
336 },
337 {
338 name: "if without else", m: testcases.IfWithoutElse.Module,
339 exp: `
340 blk0: (exec_ctx:i64, module_ctx:i64)
341 v2:i32 = Iconst_32 0x0
342 Brz v2, blk2
343 Jump blk1
344
345 blk1: () <-- (blk0)
346 Jump blk3
347
348 blk2: () <-- (blk0)
349 Jump blk3
350
351 blk3: () <-- (blk1,blk2)
352 Jump blk_ret
353 `,
354 },
355 {
356 name: "if-else", m: testcases.IfElse.Module,
357 exp: `
358 blk0: (exec_ctx:i64, module_ctx:i64)
359 v2:i32 = Iconst_32 0x0
360 Brz v2, blk2
361 Jump blk1
362
363 blk1: () <-- (blk0)
364 Jump blk3
365
366 blk2: () <-- (blk0)
367 Jump blk_ret
368
369 blk3: () <-- (blk1)
370 Jump blk_ret
371 `,
372 },
373 {
374 name: "single predecessor local refs", m: testcases.SinglePredecessorLocalRefs.Module,
375 exp: `
376 blk0: (exec_ctx:i64, module_ctx:i64)
377 v2:i32 = Iconst_32 0x0
378 Brz v2, blk2
379 Jump blk1
380
381 blk1: () <-- (blk0)
382 Return v2
383
384 blk2: () <-- (blk0)
385 Jump blk3
386
387 blk3: () <-- (blk2)
388 Jump blk_ret, v2
389 `,
390 expAfterPasses: `
391 blk0: (exec_ctx:i64, module_ctx:i64)
392 v2:i32 = Iconst_32 0x0
393 Brz v2, blk2
394 Jump fallthrough
395
396 blk1: () <-- (blk0)
397 Return v2
398
399 blk2: () <-- (blk0)
400 Jump fallthrough
401
402 blk3: () <-- (blk2)
403 Jump blk_ret, v2
404 `,
405 },
406 {
407 name: "multi predecessors local ref",
408 m: testcases.MultiPredecessorLocalRef.Module,
409 exp: `
410 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
411 v4:i32 = Iconst_32 0x0
412 Brz v2, blk2
413 Jump blk1
414
415 blk1: () <-- (blk0)
416 Jump blk3, v2
417
418 blk2: () <-- (blk0)
419 Jump blk3, v3
420
421 blk3: (v5:i32) <-- (blk1,blk2)
422 Jump blk_ret, v5
423 `,
424 expAfterPasses: `
425 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
426 Brz v2, blk2
427 Jump fallthrough
428
429 blk1: () <-- (blk0)
430 Jump blk3, v2
431
432 blk2: () <-- (blk0)
433 Jump fallthrough, v3
434
435 blk3: (v5:i32) <-- (blk1,blk2)
436 Jump blk_ret, v5
437 `,
438 },
439 {
440 name: "reference value from unsealed block",
441 m: testcases.ReferenceValueFromUnsealedBlock.Module,
442 exp: `
443 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
444 v3:i32 = Iconst_32 0x0
445 Jump blk1, v2
446
447 blk1: (v4:i32) <-- (blk0)
448 Return v4
449
450 blk2: ()
451 `,
452 expAfterPasses: `
453 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
454 Jump fallthrough
455
456 blk1: () <-- (blk0)
457 Return v2
458 `,
459 },
460 {
461 name: "reference value from unsealed block - #2",
462 m: testcases.ReferenceValueFromUnsealedBlock2.Module,
463 exp: `
464 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
465 Jump blk1, v2
466
467 blk1: (v3:i32) <-- (blk0,blk1)
468 Brnz v3, blk1, v3
469 Jump blk4
470
471 blk2: () <-- (blk3)
472 v4:i32 = Iconst_32 0x0
473 Jump blk_ret, v4
474
475 blk3: () <-- (blk4)
476 Jump blk2
477
478 blk4: () <-- (blk1)
479 Jump blk3
480 `,
481 expAfterPasses: `
482 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
483 Jump fallthrough
484
485 blk1: () <-- (blk0,blk5)
486 Brz v2, blk4
487 Jump fallthrough
488
489 blk5: () <-- (blk1)
490 Jump blk1
491
492 blk4: () <-- (blk1)
493 Jump fallthrough
494
495 blk3: () <-- (blk4)
496 Jump fallthrough
497
498 blk2: () <-- (blk3)
499 v4:i32 = Iconst_32 0x0
500 Jump blk_ret, v4
501 `,
502 },
503 {
504 name: "reference value from unsealed block - #3",
505 m: testcases.ReferenceValueFromUnsealedBlock3.Module,
506 exp: `
507 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
508 Jump blk1, v2
509
510 blk1: (v3:i32) <-- (blk0,blk3)
511 Brnz v3, blk_ret
512 Jump blk4
513
514 blk2: ()
515
516 blk3: () <-- (blk4)
517 v4:i32 = Iconst_32 0x1
518 Jump blk1, v4
519
520 blk4: () <-- (blk1)
521 Jump blk3
522 `,
523 expAfterPasses: `
524 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
525 Jump fallthrough, v2
526
527 blk1: (v3:i32) <-- (blk0,blk3)
528 Brnz v3, blk5
529 Jump blk4
530
531 blk5: () <-- (blk1)
532 Jump blk_ret
533
534 blk4: () <-- (blk1)
535 Jump fallthrough
536
537 blk3: () <-- (blk4)
538 v4:i32 = Iconst_32 0x1
539 Jump blk1, v4
540 `,
541 },
542 {
543 name: "call",
544 m: testcases.Call.Module,
545 exp: `
546 signatures:
547 sig1: i64i64_i32
548 sig2: i64i64i32i32_i32
549 sig3: i64i64i32_i32i32
550
551 blk0: (exec_ctx:i64, module_ctx:i64)
552 v2:i32 = Call f1:sig1, exec_ctx, module_ctx
553 v3:i32 = Iconst_32 0x5
554 v4:i32 = Call f2:sig2, exec_ctx, module_ctx, v2, v3
555 v5:i32, v6:i32 = Call f3:sig3, exec_ctx, module_ctx, v4
556 Jump blk_ret, v5, v6
557 `,
558 },
559 {
560 name: "call_many_params",
561 m: testcases.CallManyParams.Module,
562 exp: `
563 signatures:
564 sig1: i64i64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64_v
565
566 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64)
567 Call f1:sig1, exec_ctx, module_ctx, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5
568 Jump blk_ret
569 `,
570 },
571 {
572 name: "call_many_returns",
573 m: testcases.CallManyReturns.Module,
574 exp: `
575 signatures:
576 sig0: i64i64i32i64f32f64_i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64i32i64f32f64
577
578 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64)
579 v6:i32, v7:i64, v8:f32, v9:f64, v10:i32, v11:i64, v12:f32, v13:f64, v14:i32, v15:i64, v16:f32, v17:f64, v18:i32, v19:i64, v20:f32, v21:f64, v22:i32, v23:i64, v24:f32, v25:f64, v26:i32, v27:i64, v28:f32, v29:f64, v30:i32, v31:i64, v32:f32, v33:f64, v34:i32, v35:i64, v36:f32, v37:f64, v38:i32, v39:i64, v40:f32, v41:f64, v42:i32, v43:i64, v44:f32, v45:f64 = Call f1:sig0, exec_ctx, module_ctx, v2, v3, v4, v5
580 Jump blk_ret, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45
581 `,
582 },
583 {
584 name: "integer comparisons", m: testcases.IntegerComparisons.Module,
585 exp: `
586 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i64, v5:i64)
587 v6:i32 = Icmp eq, v2, v3
588 v7:i32 = Icmp eq, v4, v5
589 v8:i32 = Icmp neq, v2, v3
590 v9:i32 = Icmp neq, v4, v5
591 v10:i32 = Icmp lt_s, v2, v3
592 v11:i32 = Icmp lt_s, v4, v5
593 v12:i32 = Icmp lt_u, v2, v3
594 v13:i32 = Icmp lt_u, v4, v5
595 v14:i32 = Icmp gt_s, v2, v3
596 v15:i32 = Icmp gt_s, v4, v5
597 v16:i32 = Icmp gt_u, v2, v3
598 v17:i32 = Icmp gt_u, v4, v5
599 v18:i32 = Icmp le_s, v2, v3
600 v19:i32 = Icmp le_s, v4, v5
601 v20:i32 = Icmp le_u, v2, v3
602 v21:i32 = Icmp le_u, v4, v5
603 v22:i32 = Icmp ge_s, v2, v3
604 v23:i32 = Icmp ge_s, v4, v5
605 v24:i32 = Icmp ge_u, v2, v3
606 v25:i32 = Icmp ge_u, v4, v5
607 Jump blk_ret, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25
608 `,
609 expAfterPasses: `
610 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i64, v5:i64)
611 v6:i32 = Icmp eq, v2, v3
612 v7:i32 = Icmp eq, v4, v5
613 v8:i32 = Icmp neq, v2, v3
614 v9:i32 = Icmp neq, v4, v5
615 v10:i32 = Icmp lt_s, v2, v3
616 v11:i32 = Icmp lt_s, v4, v5
617 v12:i32 = Icmp lt_u, v2, v3
618 v13:i32 = Icmp lt_u, v4, v5
619 v14:i32 = Icmp gt_s, v2, v3
620 v15:i32 = Icmp gt_s, v4, v5
621 v16:i32 = Icmp gt_u, v2, v3
622 v17:i32 = Icmp gt_u, v4, v5
623 v18:i32 = Icmp le_s, v2, v3
624 v19:i32 = Icmp le_s, v4, v5
625 v20:i32 = Icmp le_u, v2, v3
626 v21:i32 = Icmp le_u, v4, v5
627 v22:i32 = Icmp ge_s, v2, v3
628 v23:i32 = Icmp ge_s, v4, v5
629 v24:i32 = Icmp ge_u, v2, v3
630 v25:i32 = Icmp ge_u, v4, v5
631 Jump blk_ret, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25
632 `,
633 },
634 {
635 name: "integer bitwise", m: testcases.IntegerBitwise.Module,
636 exp: `
637 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i64, v5:i64)
638 v6:i32 = Band v2, v3
639 v7:i32 = Bor v2, v3
640 v8:i32 = Bxor v2, v3
641 v9:i32 = Rotr v2, v3
642 v10:i64 = Band v4, v5
643 v11:i64 = Bor v4, v5
644 v12:i64 = Bxor v4, v5
645 v13:i64 = Iconst_64 0x8
646 v14:i64 = Ishl v5, v13
647 v15:i64 = Bxor v4, v14
648 v16:i64 = Rotl v4, v5
649 v17:i64 = Rotr v4, v5
650 Jump blk_ret, v6, v7, v8, v9, v10, v11, v12, v15, v16, v17
651 `,
652 },
653 {
654 name: "integer shift", m: testcases.IntegerShift.Module,
655 exp: `
656 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i64, v5:i64)
657 v6:i32 = Ishl v2, v3
658 v7:i32 = Iconst_32 0x1f
659 v8:i32 = Ishl v2, v7
660 v9:i64 = Ishl v4, v5
661 v10:i64 = Iconst_64 0x20
662 v11:i64 = Ishl v4, v10
663 v12:i32 = Ushr v2, v3
664 v13:i32 = Iconst_32 0x1f
665 v14:i32 = Ushr v2, v13
666 v15:i64 = Ushr v4, v5
667 v16:i64 = Iconst_64 0x20
668 v17:i64 = Ushr v4, v16
669 v18:i32 = Sshr v2, v3
670 v19:i32 = Iconst_32 0x1f
671 v20:i32 = Sshr v2, v19
672 v21:i64 = Sshr v4, v5
673 v22:i64 = Iconst_64 0x20
674 v23:i64 = Sshr v4, v22
675 Jump blk_ret, v6, v8, v9, v11, v12, v14, v15, v17, v18, v20, v21, v23
676 `,
677 },
678 {
679 name: "integer extension", m: testcases.IntegerExtensions.Module,
680 exp: `
681 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64)
682 v4:i64 = SExtend v2, 32->64
683 v5:i64 = UExtend v2, 32->64
684 v6:i64 = SExtend v3, 8->64
685 v7:i64 = SExtend v3, 16->64
686 v8:i64 = SExtend v3, 32->64
687 v9:i32 = SExtend v2, 8->32
688 v10:i32 = SExtend v2, 16->32
689 Jump blk_ret, v4, v5, v6, v7, v8, v9, v10
690 `,
691 },
692 {
693 name: "integer bit counts", m: testcases.IntegerBitCounts.Module,
694 exp: `
695 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64)
696 v4:i32 = Clz v2
697 v5:i32 = Ctz v2
698 v6:i32 = Popcnt v2
699 v7:i64 = Clz v3
700 v8:i64 = Ctz v3
701 v9:i64 = Popcnt v3
702 Jump blk_ret, v4, v5, v6, v7, v8, v9
703 `,
704 },
705 {
706 name: "float comparisons", m: testcases.FloatComparisons.Module,
707 exp: `
708 blk0: (exec_ctx:i64, module_ctx:i64, v2:f32, v3:f32, v4:f64, v5:f64)
709 v6:i32 = Fcmp eq, v2, v3
710 v7:i32 = Fcmp neq, v2, v3
711 v8:i32 = Fcmp lt, v2, v3
712 v9:i32 = Fcmp gt, v2, v3
713 v10:i32 = Fcmp le, v2, v3
714 v11:i32 = Fcmp ge, v2, v3
715 v12:i32 = Fcmp eq, v4, v5
716 v13:i32 = Fcmp neq, v4, v5
717 v14:i32 = Fcmp lt, v4, v5
718 v15:i32 = Fcmp gt, v4, v5
719 v16:i32 = Fcmp le, v4, v5
720 v17:i32 = Fcmp ge, v4, v5
721 Jump blk_ret, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17
722 `,
723 },
724 {
725 name: "float conversions", m: testcases.FloatConversions.Module,
726 exp: `
727 blk0: (exec_ctx:i64, module_ctx:i64, v2:f64, v3:f32)
728 v4:i64 = FcvtToSint v2
729 v5:i64 = FcvtToSint v3
730 v6:i32 = FcvtToSint v2
731 v7:i32 = FcvtToSint v3
732 v8:i64 = FcvtToUint v2
733 v9:i64 = FcvtToUint v3
734 v10:i32 = FcvtToUint v2
735 v11:i32 = FcvtToUint v3
736 v12:f32 = Fdemote v2
737 v13:f64 = Fpromote v3
738 Jump blk_ret, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13
739 `,
740 },
741 {
742 name: "non-trapping float conversions", m: testcases.NonTrappingFloatConversions.Module,
743 exp: `
744 blk0: (exec_ctx:i64, module_ctx:i64, v2:f64, v3:f32)
745 v4:i64 = FcvtToSintSat v2
746 v5:i64 = FcvtToSintSat v3
747 v6:i32 = FcvtToSintSat v2
748 v7:i32 = FcvtToSintSat v3
749 v8:i64 = FcvtToUintSat v2
750 v9:i64 = FcvtToUintSat v3
751 v10:i32 = FcvtToUintSat v2
752 v11:i32 = FcvtToUintSat v3
753 Jump blk_ret, v4, v5, v6, v7, v8, v9, v10, v11
754 `,
755 },
756 {
757 name: "loop with param and results", m: testcases.LoopBrWithParamResults.Module,
758 exp: `
759 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
760 Jump blk1, v2, v3
761
762 blk1: (v4:i32,v5:i32) <-- (blk0,blk1)
763 v7:i32 = Iconst_32 0x1
764 Brnz v7, blk1, v4, v5
765 Jump blk3
766
767 blk2: (v6:i32) <-- (blk3)
768 Jump blk_ret, v6
769
770 blk3: () <-- (blk1)
771 Jump blk2, v4
772 `,
773 expAfterPasses: `
774 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
775 Jump fallthrough
776
777 blk1: () <-- (blk0,blk4)
778 v7:i32 = Iconst_32 0x1
779 Brz v7, blk3
780 Jump fallthrough
781
782 blk4: () <-- (blk1)
783 Jump blk1
784
785 blk3: () <-- (blk1)
786 Jump fallthrough
787
788 blk2: () <-- (blk3)
789 Jump blk_ret, v2
790 `,
791 },
792 {
793 name: "many_params_small_results",
794 m: testcases.ManyParamsSmallResults.Module,
795 targetIndex: 0,
796 exp: `
797 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64, v6:i32, v7:i64, v8:f32, v9:f64, v10:i32, v11:i64, v12:f32, v13:f64, v14:i32, v15:i64, v16:f32, v17:f64, v18:i32, v19:i64, v20:f32, v21:f64, v22:i32, v23:i64, v24:f32, v25:f64, v26:i32, v27:i64, v28:f32, v29:f64, v30:i32, v31:i64, v32:f32, v33:f64, v34:i32, v35:i64, v36:f32, v37:f64, v38:i32, v39:i64, v40:f32, v41:f64)
798 Jump blk_ret, v2, v11, v20, v29
799 `,
800 expAfterPasses: `
801 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64, v6:i32, v7:i64, v8:f32, v9:f64, v10:i32, v11:i64, v12:f32, v13:f64, v14:i32, v15:i64, v16:f32, v17:f64, v18:i32, v19:i64, v20:f32, v21:f64, v22:i32, v23:i64, v24:f32, v25:f64, v26:i32, v27:i64, v28:f32, v29:f64, v30:i32, v31:i64, v32:f32, v33:f64, v34:i32, v35:i64, v36:f32, v37:f64, v38:i32, v39:i64, v40:f32, v41:f64)
802 Jump blk_ret, v2, v11, v20, v29
803 `,
804 },
805 {
806 name: "small_params_many_results",
807 m: testcases.SmallParamsManyResults.Module,
808 targetIndex: 0,
809 exp: `
810 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64)
811 Jump blk_ret, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5
812 `,
813 expAfterPasses: `
814 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64)
815 Jump blk_ret, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5, v2, v3, v4, v5
816 `,
817 },
818 {
819 name: "many_params_many_results",
820 m: testcases.ManyParamsManyResults.Module,
821 targetIndex: 0,
822 exp: `
823 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64, v6:i32, v7:i64, v8:f32, v9:f64, v10:i32, v11:i64, v12:f32, v13:f64, v14:i32, v15:i64, v16:f32, v17:f64, v18:i32, v19:i64, v20:f32, v21:f64, v22:i32, v23:i64, v24:f32, v25:f64, v26:i32, v27:i64, v28:f32, v29:f64, v30:i32, v31:i64, v32:f32, v33:f64, v34:i32, v35:i64, v36:f32, v37:f64, v38:i32, v39:i64, v40:f32, v41:f64)
824 Jump blk_ret, v41, v40, v39, v38, v37, v36, v35, v34, v33, v32, v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16, v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2
825 `,
826 expAfterPasses: `
827 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:f32, v5:f64, v6:i32, v7:i64, v8:f32, v9:f64, v10:i32, v11:i64, v12:f32, v13:f64, v14:i32, v15:i64, v16:f32, v17:f64, v18:i32, v19:i64, v20:f32, v21:f64, v22:i32, v23:i64, v24:f32, v25:f64, v26:i32, v27:i64, v28:f32, v29:f64, v30:i32, v31:i64, v32:f32, v33:f64, v34:i32, v35:i64, v36:f32, v37:f64, v38:i32, v39:i64, v40:f32, v41:f64)
828 Jump blk_ret, v41, v40, v39, v38, v37, v36, v35, v34, v33, v32, v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16, v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2
829 `,
830 },
831 {
832 name: "many_middle_values",
833 m: testcases.ManyMiddleValues.Module,
834 exp: `
835 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:f32)
836 v4:i32 = Iconst_32 0x1
837 v5:i32 = Imul v2, v4
838 v6:i32 = Iconst_32 0x2
839 v7:i32 = Imul v2, v6
840 v8:i32 = Iconst_32 0x3
841 v9:i32 = Imul v2, v8
842 v10:i32 = Iconst_32 0x4
843 v11:i32 = Imul v2, v10
844 v12:i32 = Iconst_32 0x5
845 v13:i32 = Imul v2, v12
846 v14:i32 = Iconst_32 0x6
847 v15:i32 = Imul v2, v14
848 v16:i32 = Iconst_32 0x7
849 v17:i32 = Imul v2, v16
850 v18:i32 = Iconst_32 0x8
851 v19:i32 = Imul v2, v18
852 v20:i32 = Iconst_32 0x9
853 v21:i32 = Imul v2, v20
854 v22:i32 = Iconst_32 0xa
855 v23:i32 = Imul v2, v22
856 v24:i32 = Iconst_32 0xb
857 v25:i32 = Imul v2, v24
858 v26:i32 = Iconst_32 0xc
859 v27:i32 = Imul v2, v26
860 v28:i32 = Iconst_32 0xd
861 v29:i32 = Imul v2, v28
862 v30:i32 = Iconst_32 0xe
863 v31:i32 = Imul v2, v30
864 v32:i32 = Iconst_32 0xf
865 v33:i32 = Imul v2, v32
866 v34:i32 = Iconst_32 0x10
867 v35:i32 = Imul v2, v34
868 v36:i32 = Iconst_32 0x11
869 v37:i32 = Imul v2, v36
870 v38:i32 = Iconst_32 0x12
871 v39:i32 = Imul v2, v38
872 v40:i32 = Iconst_32 0x13
873 v41:i32 = Imul v2, v40
874 v42:i32 = Iconst_32 0x14
875 v43:i32 = Imul v2, v42
876 v44:i32 = Iadd v41, v43
877 v45:i32 = Iadd v39, v44
878 v46:i32 = Iadd v37, v45
879 v47:i32 = Iadd v35, v46
880 v48:i32 = Iadd v33, v47
881 v49:i32 = Iadd v31, v48
882 v50:i32 = Iadd v29, v49
883 v51:i32 = Iadd v27, v50
884 v52:i32 = Iadd v25, v51
885 v53:i32 = Iadd v23, v52
886 v54:i32 = Iadd v21, v53
887 v55:i32 = Iadd v19, v54
888 v56:i32 = Iadd v17, v55
889 v57:i32 = Iadd v15, v56
890 v58:i32 = Iadd v13, v57
891 v59:i32 = Iadd v11, v58
892 v60:i32 = Iadd v9, v59
893 v61:i32 = Iadd v7, v60
894 v62:i32 = Iadd v5, v61
895 v63:f32 = F32const 1.000000
896 v64:f32 = Fmul v3, v63
897 v65:f32 = F32const 2.000000
898 v66:f32 = Fmul v3, v65
899 v67:f32 = F32const 3.000000
900 v68:f32 = Fmul v3, v67
901 v69:f32 = F32const 4.000000
902 v70:f32 = Fmul v3, v69
903 v71:f32 = F32const 5.000000
904 v72:f32 = Fmul v3, v71
905 v73:f32 = F32const 6.000000
906 v74:f32 = Fmul v3, v73
907 v75:f32 = F32const 7.000000
908 v76:f32 = Fmul v3, v75
909 v77:f32 = F32const 8.000000
910 v78:f32 = Fmul v3, v77
911 v79:f32 = F32const 9.000000
912 v80:f32 = Fmul v3, v79
913 v81:f32 = F32const 10.000000
914 v82:f32 = Fmul v3, v81
915 v83:f32 = F32const 11.000000
916 v84:f32 = Fmul v3, v83
917 v85:f32 = F32const 12.000000
918 v86:f32 = Fmul v3, v85
919 v87:f32 = F32const 13.000000
920 v88:f32 = Fmul v3, v87
921 v89:f32 = F32const 14.000000
922 v90:f32 = Fmul v3, v89
923 v91:f32 = F32const 15.000000
924 v92:f32 = Fmul v3, v91
925 v93:f32 = F32const 16.000000
926 v94:f32 = Fmul v3, v93
927 v95:f32 = F32const 17.000000
928 v96:f32 = Fmul v3, v95
929 v97:f32 = F32const 18.000000
930 v98:f32 = Fmul v3, v97
931 v99:f32 = F32const 19.000000
932 v100:f32 = Fmul v3, v99
933 v101:f32 = F32const 20.000000
934 v102:f32 = Fmul v3, v101
935 v103:f32 = Fadd v100, v102
936 v104:f32 = Fadd v98, v103
937 v105:f32 = Fadd v96, v104
938 v106:f32 = Fadd v94, v105
939 v107:f32 = Fadd v92, v106
940 v108:f32 = Fadd v90, v107
941 v109:f32 = Fadd v88, v108
942 v110:f32 = Fadd v86, v109
943 v111:f32 = Fadd v84, v110
944 v112:f32 = Fadd v82, v111
945 v113:f32 = Fadd v80, v112
946 v114:f32 = Fadd v78, v113
947 v115:f32 = Fadd v76, v114
948 v116:f32 = Fadd v74, v115
949 v117:f32 = Fadd v72, v116
950 v118:f32 = Fadd v70, v117
951 v119:f32 = Fadd v68, v118
952 v120:f32 = Fadd v66, v119
953 v121:f32 = Fadd v64, v120
954 Jump blk_ret, v62, v121
955 `,
956 },
957 {
958 name: "recursive_fibonacci", m: testcases.FibonacciRecursive.Module,
959 exp: `
960 signatures:
961 sig0: i64i64i32_i32
962
963 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
964 v3:i32 = Iconst_32 0x2
965 v4:i32 = Icmp lt_s, v2, v3
966 Brz v4, blk2
967 Jump blk1
968
969 blk1: () <-- (blk0)
970 Return v2
971
972 blk2: () <-- (blk0)
973 Jump blk3
974
975 blk3: () <-- (blk2)
976 v5:i32 = Iconst_32 0x1
977 v6:i32 = Isub v2, v5
978 v7:i32 = Call f0:sig0, exec_ctx, module_ctx, v6
979 v8:i32 = Iconst_32 0x2
980 v9:i32 = Isub v2, v8
981 v10:i32 = Call f0:sig0, exec_ctx, module_ctx, v9
982 v11:i32 = Iadd v7, v10
983 Jump blk_ret, v11
984 `,
985 expAfterPasses: `
986 signatures:
987 sig0: i64i64i32_i32
988
989 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
990 v3:i32 = Iconst_32 0x2
991 v4:i32 = Icmp lt_s, v2, v3
992 Brz v4, blk2
993 Jump fallthrough
994
995 blk1: () <-- (blk0)
996 Return v2
997
998 blk2: () <-- (blk0)
999 Jump fallthrough
1000
1001 blk3: () <-- (blk2)
1002 v5:i32 = Iconst_32 0x1
1003 v6:i32 = Isub v2, v5
1004 v7:i32 = Call f0:sig0, exec_ctx, module_ctx, v6
1005 v8:i32 = Iconst_32 0x2
1006 v9:i32 = Isub v2, v8
1007 v10:i32 = Call f0:sig0, exec_ctx, module_ctx, v9
1008 v11:i32 = Iadd v7, v10
1009 Jump blk_ret, v11
1010 `,
1011 },
1012 {
1013 name: "memory_store_basic", m: testcases.MemoryStoreBasic.Module,
1014 exp: `
1015 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
1016 v4:i64 = Iconst_64 0x4
1017 v5:i64 = UExtend v2, 32->64
1018 v6:i64 = Uload32 module_ctx, 0x10
1019 v7:i64 = Iadd v5, v4
1020 v8:i32 = Icmp lt_u, v6, v7
1021 ExitIfTrue v8, exec_ctx, memory_out_of_bounds
1022 v9:i64 = Load module_ctx, 0x8
1023 v10:i64 = Iadd v9, v5
1024 Store v3, v10, 0x0
1025 v11:i32 = Load v10, 0x0
1026 Jump blk_ret, v11
1027 `,
1028 },
1029 {
1030 name: "memory_load_basic", m: testcases.MemoryLoadBasic.Module,
1031 exp: `
1032 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
1033 v3:i64 = Iconst_64 0x4
1034 v4:i64 = UExtend v2, 32->64
1035 v5:i64 = Uload32 module_ctx, 0x10
1036 v6:i64 = Iadd v4, v3
1037 v7:i32 = Icmp lt_u, v5, v6
1038 ExitIfTrue v7, exec_ctx, memory_out_of_bounds
1039 v8:i64 = Load module_ctx, 0x8
1040 v9:i64 = Iadd v8, v4
1041 v10:i32 = Load v9, 0x0
1042 Jump blk_ret, v10
1043 `,
1044 },
1045 {
1046 name: "memory_load_basic2", m: testcases.MemoryLoadBasic2.Module,
1047 exp: `
1048 signatures:
1049 sig1: i64i64_v
1050
1051 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
1052 v3:i32 = Iconst_32 0x0
1053 v4:i32 = Icmp eq, v2, v3
1054 Brz v4, blk2
1055 Jump blk1
1056
1057 blk1: () <-- (blk0)
1058 Call f1:sig1, exec_ctx, module_ctx
1059 v5:i64 = Load module_ctx, 0x8
1060 v6:i64 = Uload32 module_ctx, 0x10
1061 Jump blk3
1062
1063 blk2: () <-- (blk0)
1064 Jump blk3
1065
1066 blk3: () <-- (blk1,blk2)
1067 v8:i64 = Iconst_64 0x4
1068 v9:i64 = UExtend v2, 32->64
1069 v10:i64 = Uload32 module_ctx, 0x10
1070 v11:i64 = Iadd v9, v8
1071 v12:i32 = Icmp lt_u, v10, v11
1072 ExitIfTrue v12, exec_ctx, memory_out_of_bounds
1073 v13:i64 = Load module_ctx, 0x8
1074 v14:i64 = Iadd v13, v9
1075 v15:i32 = Load v14, 0x0
1076 Jump blk_ret, v15
1077 `,
1078 expAfterPasses: `
1079 signatures:
1080 sig1: i64i64_v
1081
1082 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
1083 v3:i32 = Iconst_32 0x0
1084 v4:i32 = Icmp eq, v2, v3
1085 Brz v4, blk2
1086 Jump fallthrough
1087
1088 blk1: () <-- (blk0)
1089 Call f1:sig1, exec_ctx, module_ctx
1090 Jump blk3
1091
1092 blk2: () <-- (blk0)
1093 Jump fallthrough
1094
1095 blk3: () <-- (blk1,blk2)
1096 v8:i64 = Iconst_64 0x4
1097 v9:i64 = UExtend v2, 32->64
1098 v10:i64 = Uload32 module_ctx, 0x10
1099 v11:i64 = Iadd v9, v8
1100 v12:i32 = Icmp lt_u, v10, v11
1101 ExitIfTrue v12, exec_ctx, memory_out_of_bounds
1102 v13:i64 = Load module_ctx, 0x8
1103 v14:i64 = Iadd v13, v9
1104 v15:i32 = Load v14, 0x0
1105 Jump blk_ret, v15
1106 `,
1107 },
1108 {
1109 name: "imported_function_call", m: testcases.ImportedFunctionCall.Module,
1110 exp: `
1111 signatures:
1112 sig1: i64i64i32i32_i32
1113
1114 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
1115 Store module_ctx, exec_ctx, 0x8
1116 v3:i64 = Load module_ctx, 0x8
1117 v4:i64 = Load module_ctx, 0x10
1118 v5:i32 = CallIndirect v3:sig1, exec_ctx, v4, v2, v2
1119 Jump blk_ret, v5
1120 `,
1121 },
1122 {
1123 name: "memory_loads", m: testcases.MemoryLoads.Module,
1124 exp: `
1125 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
1126 v3:i64 = Iconst_64 0x4
1127 v4:i64 = UExtend v2, 32->64
1128 v5:i64 = Uload32 module_ctx, 0x10
1129 v6:i64 = Iadd v4, v3
1130 v7:i32 = Icmp lt_u, v5, v6
1131 ExitIfTrue v7, exec_ctx, memory_out_of_bounds
1132 v8:i64 = Load module_ctx, 0x8
1133 v9:i64 = Iadd v8, v4
1134 v10:i32 = Load v9, 0x0
1135 v11:i64 = Iconst_64 0x8
1136 v12:i64 = UExtend v2, 32->64
1137 v13:i64 = Iadd v12, v11
1138 v14:i32 = Icmp lt_u, v5, v13
1139 ExitIfTrue v14, exec_ctx, memory_out_of_bounds
1140 v15:i64 = Load v9, 0x0
1141 v16:f32 = Load v9, 0x0
1142 v17:f64 = Load v9, 0x0
1143 v18:i64 = Iconst_64 0x13
1144 v19:i64 = UExtend v2, 32->64
1145 v20:i64 = Iadd v19, v18
1146 v21:i32 = Icmp lt_u, v5, v20
1147 ExitIfTrue v21, exec_ctx, memory_out_of_bounds
1148 v22:i32 = Load v9, 0xf
1149 v23:i64 = Iconst_64 0x17
1150 v24:i64 = UExtend v2, 32->64
1151 v25:i64 = Iadd v24, v23
1152 v26:i32 = Icmp lt_u, v5, v25
1153 ExitIfTrue v26, exec_ctx, memory_out_of_bounds
1154 v27:i64 = Load v9, 0xf
1155 v28:f32 = Load v9, 0xf
1156 v29:f64 = Load v9, 0xf
1157 v30:i32 = Sload8 v9, 0x0
1158 v31:i32 = Sload8 v9, 0xf
1159 v32:i32 = Uload8 v9, 0x0
1160 v33:i32 = Uload8 v9, 0xf
1161 v34:i32 = Sload16 v9, 0x0
1162 v35:i32 = Sload16 v9, 0xf
1163 v36:i32 = Uload16 v9, 0x0
1164 v37:i32 = Uload16 v9, 0xf
1165 v38:i64 = Sload8 v9, 0x0
1166 v39:i64 = Sload8 v9, 0xf
1167 v40:i64 = Uload8 v9, 0x0
1168 v41:i64 = Uload8 v9, 0xf
1169 v42:i64 = Sload16 v9, 0x0
1170 v43:i64 = Sload16 v9, 0xf
1171 v44:i64 = Uload16 v9, 0x0
1172 v45:i64 = Uload16 v9, 0xf
1173 v46:i64 = Sload32 v9, 0x0
1174 v47:i64 = Sload32 v9, 0xf
1175 v48:i64 = Uload32 v9, 0x0
1176 v49:i64 = Uload32 v9, 0xf
1177 Jump blk_ret, v10, v15, v16, v17, v22, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49
1178 `,
1179 },
1180 {
1181 name: "globals_get",
1182 m: testcases.GlobalsGet.Module,
1183 exp: `
1184 blk0: (exec_ctx:i64, module_ctx:i64)
1185 v2:i32 = Load module_ctx, 0x10
1186 v3:i64 = Load module_ctx, 0x20
1187 v4:f32 = Load module_ctx, 0x30
1188 v5:f64 = Load module_ctx, 0x40
1189 v6:v128 = Load module_ctx, 0x50
1190 Jump blk_ret, v2, v3, v4, v5, v6
1191 `,
1192 },
1193 {
1194 name: "globals_set",
1195 m: testcases.GlobalsSet.Module,
1196 exp: `
1197 blk0: (exec_ctx:i64, module_ctx:i64)
1198 v2:i32 = Iconst_32 0x1
1199 Store v2, module_ctx, 0x10
1200 v3:i64 = Iconst_64 0x2
1201 Store v3, module_ctx, 0x20
1202 v4:f32 = F32const 3.000000
1203 Store v4, module_ctx, 0x30
1204 v5:f64 = F64const 4.000000
1205 Store v5, module_ctx, 0x40
1206 v6:v128 = Vconst 000000000000000a 0000000000000014
1207 Store v6, module_ctx, 0x50
1208 Jump blk_ret, v2, v3, v4, v5, v6
1209 `,
1210 },
1211 {
1212 name: "globals_mutable",
1213 m: testcases.GlobalsMutable.Module,
1214 exp: `
1215 signatures:
1216 sig1: i64i64_v
1217
1218 blk0: (exec_ctx:i64, module_ctx:i64)
1219 v2:i32 = Load module_ctx, 0x10
1220 v3:i64 = Load module_ctx, 0x20
1221 v4:f32 = Load module_ctx, 0x30
1222 v5:f64 = Load module_ctx, 0x40
1223 Call f1:sig1, exec_ctx, module_ctx
1224 v6:i32 = Load module_ctx, 0x10
1225 v7:i64 = Load module_ctx, 0x20
1226 v8:f32 = Load module_ctx, 0x30
1227 v9:f64 = Load module_ctx, 0x40
1228 Jump blk_ret, v2, v3, v4, v5, v6, v7, v8, v9
1229 `,
1230 expAfterPasses: `
1231 signatures:
1232 sig1: i64i64_v
1233
1234 blk0: (exec_ctx:i64, module_ctx:i64)
1235 v2:i32 = Load module_ctx, 0x10
1236 v3:i64 = Load module_ctx, 0x20
1237 v4:f32 = Load module_ctx, 0x30
1238 v5:f64 = Load module_ctx, 0x40
1239 Call f1:sig1, exec_ctx, module_ctx
1240 v6:i32 = Load module_ctx, 0x10
1241 v7:i64 = Load module_ctx, 0x20
1242 v8:f32 = Load module_ctx, 0x30
1243 v9:f64 = Load module_ctx, 0x40
1244 Jump blk_ret, v2, v3, v4, v5, v6, v7, v8, v9
1245 `,
1246 },
1247 {
1248 name: "imported_memory_grow",
1249 m: testcases.ImportedMemoryGrow.Module,
1250 exp: `
1251 signatures:
1252 sig0: i64i64_i32
1253 sig2: i64i32_i32
1254
1255 blk0: (exec_ctx:i64, module_ctx:i64)
1256 Store module_ctx, exec_ctx, 0x8
1257 v2:i64 = Load module_ctx, 0x18
1258 v3:i64 = Load module_ctx, 0x20
1259 v4:i32 = CallIndirect v2:sig0, exec_ctx, v3
1260 v5:i64 = Load module_ctx, 0x8
1261 v6:i64 = Load v5, 0x0
1262 v7:i64 = Load module_ctx, 0x8
1263 v8:i64 = Load v7, 0x8
1264 v9:i64 = Load module_ctx, 0x8
1265 v10:i32 = Load v9, 0x8
1266 v11:i32 = Iconst_32 0x10
1267 v12:i32 = Ushr v10, v11
1268 v13:i32 = Iconst_32 0xa
1269 Store module_ctx, exec_ctx, 0x8
1270 v14:i64 = Load exec_ctx, 0x48
1271 v15:i32 = CallIndirect v14:sig2, exec_ctx, v13
1272 v16:i64 = Load module_ctx, 0x8
1273 v17:i64 = Load v16, 0x0
1274 v18:i64 = Load module_ctx, 0x8
1275 v19:i64 = Load v18, 0x8
1276 Store module_ctx, exec_ctx, 0x8
1277 v20:i64 = Load module_ctx, 0x18
1278 v21:i64 = Load module_ctx, 0x20
1279 v22:i32 = CallIndirect v20:sig0, exec_ctx, v21
1280 v23:i64 = Load module_ctx, 0x8
1281 v24:i64 = Load v23, 0x0
1282 v25:i64 = Load module_ctx, 0x8
1283 v26:i64 = Load v25, 0x8
1284 v27:i64 = Load module_ctx, 0x8
1285 v28:i32 = Load v27, 0x8
1286 v29:i32 = Iconst_32 0x10
1287 v30:i32 = Ushr v28, v29
1288 Jump blk_ret, v4, v12, v22, v30
1289 `,
1290 expAfterPasses: `
1291 signatures:
1292 sig0: i64i64_i32
1293 sig2: i64i32_i32
1294
1295 blk0: (exec_ctx:i64, module_ctx:i64)
1296 Store module_ctx, exec_ctx, 0x8
1297 v2:i64 = Load module_ctx, 0x18
1298 v3:i64 = Load module_ctx, 0x20
1299 v4:i32 = CallIndirect v2:sig0, exec_ctx, v3
1300 v9:i64 = Load module_ctx, 0x8
1301 v10:i32 = Load v9, 0x8
1302 v11:i32 = Iconst_32 0x10
1303 v12:i32 = Ushr v10, v11
1304 v13:i32 = Iconst_32 0xa
1305 Store module_ctx, exec_ctx, 0x8
1306 v14:i64 = Load exec_ctx, 0x48
1307 v15:i32 = CallIndirect v14:sig2, exec_ctx, v13
1308 Store module_ctx, exec_ctx, 0x8
1309 v20:i64 = Load module_ctx, 0x18
1310 v21:i64 = Load module_ctx, 0x20
1311 v22:i32 = CallIndirect v20:sig0, exec_ctx, v21
1312 v27:i64 = Load module_ctx, 0x8
1313 v28:i32 = Load v27, 0x8
1314 v29:i32 = Iconst_32 0x10
1315 v30:i32 = Ushr v28, v29
1316 Jump blk_ret, v4, v12, v22, v30
1317 `,
1318 },
1319 {
1320 name: "memory_size_grow",
1321 m: testcases.MemorySizeGrow.Module,
1322 exp: `
1323 signatures:
1324 sig1: i64i32_i32
1325
1326 blk0: (exec_ctx:i64, module_ctx:i64)
1327 v2:i32 = Iconst_32 0x1
1328 Store module_ctx, exec_ctx, 0x8
1329 v3:i64 = Load exec_ctx, 0x48
1330 v4:i32 = CallIndirect v3:sig1, exec_ctx, v2
1331 v5:i64 = Load module_ctx, 0x8
1332 v6:i64 = Uload32 module_ctx, 0x10
1333 v7:i32 = Load module_ctx, 0x10
1334 v8:i32 = Iconst_32 0x10
1335 v9:i32 = Ushr v7, v8
1336 v10:i32 = Iconst_32 0x1
1337 Store module_ctx, exec_ctx, 0x8
1338 v11:i64 = Load exec_ctx, 0x48
1339 v12:i32 = CallIndirect v11:sig1, exec_ctx, v10
1340 v13:i64 = Load module_ctx, 0x8
1341 v14:i64 = Uload32 module_ctx, 0x10
1342 Jump blk_ret, v4, v9, v12
1343 `,
1344 expAfterPasses: `
1345 signatures:
1346 sig1: i64i32_i32
1347
1348 blk0: (exec_ctx:i64, module_ctx:i64)
1349 v2:i32 = Iconst_32 0x1
1350 Store module_ctx, exec_ctx, 0x8
1351 v3:i64 = Load exec_ctx, 0x48
1352 v4:i32 = CallIndirect v3:sig1, exec_ctx, v2
1353 v7:i32 = Load module_ctx, 0x10
1354 v8:i32 = Iconst_32 0x10
1355 v9:i32 = Ushr v7, v8
1356 v10:i32 = Iconst_32 0x1
1357 Store module_ctx, exec_ctx, 0x8
1358 v11:i64 = Load exec_ctx, 0x48
1359 v12:i32 = CallIndirect v11:sig1, exec_ctx, v10
1360 Jump blk_ret, v4, v9, v12
1361 `,
1362 },
1363 {
1364 name: "call_indirect", m: testcases.CallIndirect.Module,
1365 exp: `
1366 signatures:
1367 sig2: i64i64_i32
1368
1369 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
1370 v3:i64 = Load module_ctx, 0x10
1371 v4:i32 = Load v3, 0x8
1372 v5:i32 = Icmp ge_u, v2, v4
1373 ExitIfTrue v5, exec_ctx, table_out_of_bounds
1374 v6:i64 = Load v3, 0x0
1375 v7:i64 = Iconst_64 0x3
1376 v8:i32 = Ishl v2, v7
1377 v9:i64 = Iadd v6, v8
1378 v10:i64 = Load v9, 0x0
1379 v11:i64 = Iconst_64 0x0
1380 v12:i32 = Icmp eq, v10, v11
1381 ExitIfTrue v12, exec_ctx, indirect_call_null_pointer
1382 v13:i32 = Load v10, 0x10
1383 v14:i64 = Load module_ctx, 0x8
1384 v15:i32 = Load v14, 0x8
1385 v16:i32 = Icmp neq, v13, v15
1386 ExitIfTrue v16, exec_ctx, indirect_call_type_mismatch
1387 v17:i64 = Load v10, 0x0
1388 v18:i64 = Load v10, 0x8
1389 Store module_ctx, exec_ctx, 0x8
1390 v19:i32 = CallIndirect v17:sig2, exec_ctx, v18
1391 Jump blk_ret, v19
1392 `,
1393 },
1394 {
1395 name: "br_table", m: testcases.BrTable.Module,
1396 exp: `
1397 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
1398 BrTable v2, [blk7, blk8, blk9, blk10, blk11, blk12, blk13]
1399
1400 blk1: () <-- (blk12)
1401 v8:i32 = Iconst_32 0x10
1402 Return v8
1403
1404 blk2: () <-- (blk11)
1405 v7:i32 = Iconst_32 0xf
1406 Return v7
1407
1408 blk3: () <-- (blk10)
1409 v6:i32 = Iconst_32 0xe
1410 Return v6
1411
1412 blk4: () <-- (blk9)
1413 v5:i32 = Iconst_32 0xd
1414 Return v5
1415
1416 blk5: () <-- (blk8)
1417 v4:i32 = Iconst_32 0xc
1418 Return v4
1419
1420 blk6: () <-- (blk7,blk13)
1421 v3:i32 = Iconst_32 0xb
1422 Return v3
1423
1424 blk7: () <-- (blk0)
1425 Jump blk6
1426
1427 blk8: () <-- (blk0)
1428 Jump blk5
1429
1430 blk9: () <-- (blk0)
1431 Jump blk4
1432
1433 blk10: () <-- (blk0)
1434 Jump blk3
1435
1436 blk11: () <-- (blk0)
1437 Jump blk2
1438
1439 blk12: () <-- (blk0)
1440 Jump blk1
1441
1442 blk13: () <-- (blk0)
1443 Jump blk6
1444 `,
1445 },
1446 {
1447 name: "br_table_with_arg", m: testcases.BrTableWithArg.Module,
1448 exp: `
1449 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
1450 BrTable v2, [blk7, blk8, blk9, blk10, blk11, blk12, blk13]
1451
1452 blk1: (v4:i32) <-- (blk12)
1453 v20:i32 = Iconst_32 0x10
1454 v21:i32 = Iadd v4, v20
1455 Return v21
1456
1457 blk2: (v5:i32) <-- (blk11)
1458 v18:i32 = Iconst_32 0xf
1459 v19:i32 = Iadd v5, v18
1460 Return v19
1461
1462 blk3: (v6:i32) <-- (blk10)
1463 v16:i32 = Iconst_32 0xe
1464 v17:i32 = Iadd v6, v16
1465 Return v17
1466
1467 blk4: (v7:i32) <-- (blk9)
1468 v14:i32 = Iconst_32 0xd
1469 v15:i32 = Iadd v7, v14
1470 Return v15
1471
1472 blk5: (v8:i32) <-- (blk8)
1473 v12:i32 = Iconst_32 0xc
1474 v13:i32 = Iadd v8, v12
1475 Return v13
1476
1477 blk6: (v9:i32) <-- (blk7,blk13)
1478 v10:i32 = Iconst_32 0xb
1479 v11:i32 = Iadd v9, v10
1480 Return v11
1481
1482 blk7: () <-- (blk0)
1483 Jump blk6, v3
1484
1485 blk8: () <-- (blk0)
1486 Jump blk5, v3
1487
1488 blk9: () <-- (blk0)
1489 Jump blk4, v3
1490
1491 blk10: () <-- (blk0)
1492 Jump blk3, v3
1493
1494 blk11: () <-- (blk0)
1495 Jump blk2, v3
1496
1497 blk12: () <-- (blk0)
1498 Jump blk1, v3
1499
1500 blk13: () <-- (blk0)
1501 Jump blk6, v3
1502 `,
1503
1504 expAfterPasses: `
1505 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
1506 BrTable v2, [blk7, blk8, blk9, blk10, blk11, blk12, blk13]
1507
1508 blk7: () <-- (blk0)
1509 Jump blk6
1510
1511 blk8: () <-- (blk0)
1512 Jump fallthrough
1513
1514 blk5: () <-- (blk8)
1515 v12:i32 = Iconst_32 0xc
1516 v13:i32 = Iadd v3, v12
1517 Return v13
1518
1519 blk9: () <-- (blk0)
1520 Jump fallthrough
1521
1522 blk4: () <-- (blk9)
1523 v14:i32 = Iconst_32 0xd
1524 v15:i32 = Iadd v3, v14
1525 Return v15
1526
1527 blk10: () <-- (blk0)
1528 Jump fallthrough
1529
1530 blk3: () <-- (blk10)
1531 v16:i32 = Iconst_32 0xe
1532 v17:i32 = Iadd v3, v16
1533 Return v17
1534
1535 blk11: () <-- (blk0)
1536 Jump fallthrough
1537
1538 blk2: () <-- (blk11)
1539 v18:i32 = Iconst_32 0xf
1540 v19:i32 = Iadd v3, v18
1541 Return v19
1542
1543 blk12: () <-- (blk0)
1544 Jump fallthrough
1545
1546 blk1: () <-- (blk12)
1547 v20:i32 = Iconst_32 0x10
1548 v21:i32 = Iadd v3, v20
1549 Return v21
1550
1551 blk13: () <-- (blk0)
1552 Jump fallthrough
1553
1554 blk6: () <-- (blk7,blk13)
1555 v10:i32 = Iconst_32 0xb
1556 v11:i32 = Iadd v3, v10
1557 Return v11
1558 `,
1559 },
1560 {
1561 name: "if_then_end_nesting_unreachable_if_then_else_end", m: testcases.IfThenEndNestingUnreachableIfThenElseEnd.Module,
1562 exp: `
1563 blk0: (exec_ctx:i64, module_ctx:i64, v2:f64, v3:f64, v4:f64)
1564 v6:i32 = Load module_ctx, 0x10
1565 v7:i32 = Iconst_32 0x10
1566 v8:i32 = Ushr v6, v7
1567 Brz v8, blk3
1568 Jump blk2
1569
1570 blk1: (v5:i64) <-- (blk4)
1571 Jump blk_ret
1572
1573 blk2: () <-- (blk0)
1574 v9:i32 = Load module_ctx, 0x10
1575 v10:i32 = Iconst_32 0x10
1576 v11:i32 = Ushr v9, v10
1577 Jump blk4
1578
1579 blk3: () <-- (blk0)
1580 Jump blk4
1581
1582 blk4: () <-- (blk2,blk3)
1583 v12:i64 = Iconst_64 0x0
1584 Jump blk1, v12
1585 `,
1586 expAfterPasses: `
1587 blk0: (exec_ctx:i64, module_ctx:i64, v2:f64, v3:f64, v4:f64)
1588 v6:i32 = Load module_ctx, 0x10
1589 v7:i32 = Iconst_32 0x10
1590 v8:i32 = Ushr v6, v7
1591 Brz v8, blk3
1592 Jump fallthrough
1593
1594 blk2: () <-- (blk0)
1595 Jump blk4
1596
1597 blk3: () <-- (blk0)
1598 Jump fallthrough
1599
1600 blk4: () <-- (blk2,blk3)
1601 Jump fallthrough
1602
1603 blk1: () <-- (blk4)
1604 Jump blk_ret
1605 `,
1606 },
1607 {
1608 name: "VecShuffle",
1609 m: testcases.VecShuffle.Module,
1610 exp: `
1611 blk0: (exec_ctx:i64, module_ctx:i64, v2:v128, v3:v128)
1612 v4:v128 = Shuffle.[0 1 2 3 4 5 6 7 24 25 26 27 28 29 30 31] v2, v3
1613 Jump blk_ret, v4
1614 `,
1615 },
1616 {
1617 name: "MemoryWait32",
1618 m: testcases.MemoryWait32.Module,
1619 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
1620 exp: `
1621 signatures:
1622 sig6: i64i64i32i64_i32
1623
1624 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i64)
1625 Store module_ctx, exec_ctx, 0x8
1626 v5:i64 = Iconst_64 0xc
1627 v6:i64 = UExtend v2, 32->64
1628 v7:i64 = Iconst_64 0x10
1629 v8:i64 = Iadd module_ctx, v7
1630 v9:i64 = AtomicLoad_64, v8
1631 v10:i64 = Iadd v6, v5
1632 v11:i32 = Icmp lt_u, v9, v10
1633 ExitIfTrue v11, exec_ctx, memory_out_of_bounds
1634 v12:i64 = Load module_ctx, 0x8
1635 v13:i64 = Iadd v12, v6
1636 v14:i64 = Iconst_64 0x8
1637 v15:i64 = Iadd v13, v14
1638 v16:i64 = Iconst_64 0x3
1639 v17:i64 = Band v15, v16
1640 v18:i64 = Iconst_64 0x0
1641 v19:i32 = Icmp neq, v17, v18
1642 ExitIfTrue v19, exec_ctx, unaligned_atomic
1643 v20:i64 = Load exec_ctx, 0x488
1644 v21:i32 = CallIndirect v20:sig6, exec_ctx, v4, v3, v15
1645 Jump blk_ret, v21
1646 `,
1647 },
1648 {
1649 name: "MemoryWait64",
1650 m: testcases.MemoryWait64.Module,
1651 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
1652 exp: `
1653 signatures:
1654 sig7: i64i64i64i64_i32
1655
1656 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i64, v4:i64)
1657 Store module_ctx, exec_ctx, 0x8
1658 v5:i64 = Iconst_64 0x10
1659 v6:i64 = UExtend v2, 32->64
1660 v7:i64 = Iconst_64 0x10
1661 v8:i64 = Iadd module_ctx, v7
1662 v9:i64 = AtomicLoad_64, v8
1663 v10:i64 = Iadd v6, v5
1664 v11:i32 = Icmp lt_u, v9, v10
1665 ExitIfTrue v11, exec_ctx, memory_out_of_bounds
1666 v12:i64 = Load module_ctx, 0x8
1667 v13:i64 = Iadd v12, v6
1668 v14:i64 = Iconst_64 0x8
1669 v15:i64 = Iadd v13, v14
1670 v16:i64 = Iconst_64 0x7
1671 v17:i64 = Band v15, v16
1672 v18:i64 = Iconst_64 0x0
1673 v19:i32 = Icmp neq, v17, v18
1674 ExitIfTrue v19, exec_ctx, unaligned_atomic
1675 v20:i64 = Load exec_ctx, 0x490
1676 v21:i32 = CallIndirect v20:sig7, exec_ctx, v4, v3, v15
1677 Jump blk_ret, v21
1678 `,
1679 },
1680 {
1681 name: "MemoryNotify",
1682 m: testcases.MemoryNotify.Module,
1683 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
1684 exp: `
1685 signatures:
1686 sig8: i64i32i64_i32
1687
1688 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32)
1689 Store module_ctx, exec_ctx, 0x8
1690 v4:i64 = Iconst_64 0xc
1691 v5:i64 = UExtend v2, 32->64
1692 v6:i64 = Iconst_64 0x10
1693 v7:i64 = Iadd module_ctx, v6
1694 v8:i64 = AtomicLoad_64, v7
1695 v9:i64 = Iadd v5, v4
1696 v10:i32 = Icmp lt_u, v8, v9
1697 ExitIfTrue v10, exec_ctx, memory_out_of_bounds
1698 v11:i64 = Load module_ctx, 0x8
1699 v12:i64 = Iadd v11, v5
1700 v13:i64 = Iconst_64 0x8
1701 v14:i64 = Iadd v12, v13
1702 v15:i64 = Iconst_64 0x3
1703 v16:i64 = Band v14, v15
1704 v17:i64 = Iconst_64 0x0
1705 v18:i32 = Icmp neq, v16, v17
1706 ExitIfTrue v18, exec_ctx, unaligned_atomic
1707 v19:i64 = Load exec_ctx, 0x498
1708 v20:i32 = CallIndirect v19:sig8, exec_ctx, v3, v14
1709 Jump blk_ret, v20
1710 `,
1711 },
1712 {
1713 name: "AtomicRMWAdd",
1714 m: testcases.AtomicRmwAdd.Module,
1715 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
1716 exp: `
1717 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i64, v6:i64, v7:i64, v8:i64)
1718 v9:i32 = Iconst_32 0x0
1719 v10:i64 = Iconst_64 0x1
1720 v11:i64 = UExtend v9, 32->64
1721 v12:i64 = Iconst_64 0x10
1722 v13:i64 = Iadd module_ctx, v12
1723 v14:i64 = AtomicLoad_64, v13
1724 v15:i64 = Iadd v11, v10
1725 v16:i32 = Icmp lt_u, v14, v15
1726 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
1727 v17:i64 = Load module_ctx, 0x8
1728 v18:i64 = Iadd v17, v11
1729 v19:i32 = AtomicRmw add_8, v18, v2
1730 v20:i32 = Iconst_32 0x8
1731 v21:i64 = Iconst_64 0x2
1732 v22:i64 = UExtend v20, 32->64
1733 v23:i64 = Iconst_64 0x10
1734 v24:i64 = Iadd module_ctx, v23
1735 v25:i64 = AtomicLoad_64, v24
1736 v26:i64 = Iadd v22, v21
1737 v27:i32 = Icmp lt_u, v25, v26
1738 ExitIfTrue v27, exec_ctx, memory_out_of_bounds
1739 v28:i64 = Iadd v17, v22
1740 v29:i64 = Iconst_64 0x1
1741 v30:i64 = Band v28, v29
1742 v31:i64 = Iconst_64 0x0
1743 v32:i32 = Icmp neq, v30, v31
1744 ExitIfTrue v32, exec_ctx, unaligned_atomic
1745 v33:i32 = AtomicRmw add_16, v28, v3
1746 v34:i32 = Iconst_32 0x10
1747 v35:i64 = Iconst_64 0x4
1748 v36:i64 = UExtend v34, 32->64
1749 v37:i64 = Iconst_64 0x10
1750 v38:i64 = Iadd module_ctx, v37
1751 v39:i64 = AtomicLoad_64, v38
1752 v40:i64 = Iadd v36, v35
1753 v41:i32 = Icmp lt_u, v39, v40
1754 ExitIfTrue v41, exec_ctx, memory_out_of_bounds
1755 v42:i64 = Iadd v17, v36
1756 v43:i64 = Iconst_64 0x3
1757 v44:i64 = Band v42, v43
1758 v45:i64 = Iconst_64 0x0
1759 v46:i32 = Icmp neq, v44, v45
1760 ExitIfTrue v46, exec_ctx, unaligned_atomic
1761 v47:i32 = AtomicRmw add_32, v42, v4
1762 v48:i32 = Iconst_32 0x18
1763 v49:i64 = Iconst_64 0x1
1764 v50:i64 = UExtend v48, 32->64
1765 v51:i64 = Iconst_64 0x10
1766 v52:i64 = Iadd module_ctx, v51
1767 v53:i64 = AtomicLoad_64, v52
1768 v54:i64 = Iadd v50, v49
1769 v55:i32 = Icmp lt_u, v53, v54
1770 ExitIfTrue v55, exec_ctx, memory_out_of_bounds
1771 v56:i64 = Iadd v17, v50
1772 v57:i64 = AtomicRmw add_8, v56, v5
1773 v58:i32 = Iconst_32 0x20
1774 v59:i64 = Iconst_64 0x2
1775 v60:i64 = UExtend v58, 32->64
1776 v61:i64 = Iconst_64 0x10
1777 v62:i64 = Iadd module_ctx, v61
1778 v63:i64 = AtomicLoad_64, v62
1779 v64:i64 = Iadd v60, v59
1780 v65:i32 = Icmp lt_u, v63, v64
1781 ExitIfTrue v65, exec_ctx, memory_out_of_bounds
1782 v66:i64 = Iadd v17, v60
1783 v67:i64 = Iconst_64 0x1
1784 v68:i64 = Band v66, v67
1785 v69:i64 = Iconst_64 0x0
1786 v70:i32 = Icmp neq, v68, v69
1787 ExitIfTrue v70, exec_ctx, unaligned_atomic
1788 v71:i64 = AtomicRmw add_16, v66, v6
1789 v72:i32 = Iconst_32 0x28
1790 v73:i64 = Iconst_64 0x4
1791 v74:i64 = UExtend v72, 32->64
1792 v75:i64 = Iconst_64 0x10
1793 v76:i64 = Iadd module_ctx, v75
1794 v77:i64 = AtomicLoad_64, v76
1795 v78:i64 = Iadd v74, v73
1796 v79:i32 = Icmp lt_u, v77, v78
1797 ExitIfTrue v79, exec_ctx, memory_out_of_bounds
1798 v80:i64 = Iadd v17, v74
1799 v81:i64 = Iconst_64 0x3
1800 v82:i64 = Band v80, v81
1801 v83:i64 = Iconst_64 0x0
1802 v84:i32 = Icmp neq, v82, v83
1803 ExitIfTrue v84, exec_ctx, unaligned_atomic
1804 v85:i64 = AtomicRmw add_32, v80, v7
1805 v86:i32 = Iconst_32 0x30
1806 v87:i64 = Iconst_64 0x8
1807 v88:i64 = UExtend v86, 32->64
1808 v89:i64 = Iconst_64 0x10
1809 v90:i64 = Iadd module_ctx, v89
1810 v91:i64 = AtomicLoad_64, v90
1811 v92:i64 = Iadd v88, v87
1812 v93:i32 = Icmp lt_u, v91, v92
1813 ExitIfTrue v93, exec_ctx, memory_out_of_bounds
1814 v94:i64 = Iadd v17, v88
1815 v95:i64 = Iconst_64 0x7
1816 v96:i64 = Band v94, v95
1817 v97:i64 = Iconst_64 0x0
1818 v98:i32 = Icmp neq, v96, v97
1819 ExitIfTrue v98, exec_ctx, unaligned_atomic
1820 v99:i64 = AtomicRmw add_64, v94, v8
1821 Jump blk_ret, v19, v33, v47, v57, v71, v85, v99
1822 `,
1823 },
1824 {
1825 name: "AtomicRMWSub",
1826 m: testcases.AtomicRmwSub.Module,
1827 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
1828 exp: `
1829 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i64, v6:i64, v7:i64, v8:i64)
1830 v9:i32 = Iconst_32 0x0
1831 v10:i64 = Iconst_64 0x1
1832 v11:i64 = UExtend v9, 32->64
1833 v12:i64 = Iconst_64 0x10
1834 v13:i64 = Iadd module_ctx, v12
1835 v14:i64 = AtomicLoad_64, v13
1836 v15:i64 = Iadd v11, v10
1837 v16:i32 = Icmp lt_u, v14, v15
1838 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
1839 v17:i64 = Load module_ctx, 0x8
1840 v18:i64 = Iadd v17, v11
1841 v19:i32 = AtomicRmw sub_8, v18, v2
1842 v20:i32 = Iconst_32 0x8
1843 v21:i64 = Iconst_64 0x2
1844 v22:i64 = UExtend v20, 32->64
1845 v23:i64 = Iconst_64 0x10
1846 v24:i64 = Iadd module_ctx, v23
1847 v25:i64 = AtomicLoad_64, v24
1848 v26:i64 = Iadd v22, v21
1849 v27:i32 = Icmp lt_u, v25, v26
1850 ExitIfTrue v27, exec_ctx, memory_out_of_bounds
1851 v28:i64 = Iadd v17, v22
1852 v29:i64 = Iconst_64 0x1
1853 v30:i64 = Band v28, v29
1854 v31:i64 = Iconst_64 0x0
1855 v32:i32 = Icmp neq, v30, v31
1856 ExitIfTrue v32, exec_ctx, unaligned_atomic
1857 v33:i32 = AtomicRmw sub_16, v28, v3
1858 v34:i32 = Iconst_32 0x10
1859 v35:i64 = Iconst_64 0x4
1860 v36:i64 = UExtend v34, 32->64
1861 v37:i64 = Iconst_64 0x10
1862 v38:i64 = Iadd module_ctx, v37
1863 v39:i64 = AtomicLoad_64, v38
1864 v40:i64 = Iadd v36, v35
1865 v41:i32 = Icmp lt_u, v39, v40
1866 ExitIfTrue v41, exec_ctx, memory_out_of_bounds
1867 v42:i64 = Iadd v17, v36
1868 v43:i64 = Iconst_64 0x3
1869 v44:i64 = Band v42, v43
1870 v45:i64 = Iconst_64 0x0
1871 v46:i32 = Icmp neq, v44, v45
1872 ExitIfTrue v46, exec_ctx, unaligned_atomic
1873 v47:i32 = AtomicRmw sub_32, v42, v4
1874 v48:i32 = Iconst_32 0x18
1875 v49:i64 = Iconst_64 0x1
1876 v50:i64 = UExtend v48, 32->64
1877 v51:i64 = Iconst_64 0x10
1878 v52:i64 = Iadd module_ctx, v51
1879 v53:i64 = AtomicLoad_64, v52
1880 v54:i64 = Iadd v50, v49
1881 v55:i32 = Icmp lt_u, v53, v54
1882 ExitIfTrue v55, exec_ctx, memory_out_of_bounds
1883 v56:i64 = Iadd v17, v50
1884 v57:i64 = AtomicRmw sub_8, v56, v5
1885 v58:i32 = Iconst_32 0x20
1886 v59:i64 = Iconst_64 0x2
1887 v60:i64 = UExtend v58, 32->64
1888 v61:i64 = Iconst_64 0x10
1889 v62:i64 = Iadd module_ctx, v61
1890 v63:i64 = AtomicLoad_64, v62
1891 v64:i64 = Iadd v60, v59
1892 v65:i32 = Icmp lt_u, v63, v64
1893 ExitIfTrue v65, exec_ctx, memory_out_of_bounds
1894 v66:i64 = Iadd v17, v60
1895 v67:i64 = Iconst_64 0x1
1896 v68:i64 = Band v66, v67
1897 v69:i64 = Iconst_64 0x0
1898 v70:i32 = Icmp neq, v68, v69
1899 ExitIfTrue v70, exec_ctx, unaligned_atomic
1900 v71:i64 = AtomicRmw sub_16, v66, v6
1901 v72:i32 = Iconst_32 0x28
1902 v73:i64 = Iconst_64 0x4
1903 v74:i64 = UExtend v72, 32->64
1904 v75:i64 = Iconst_64 0x10
1905 v76:i64 = Iadd module_ctx, v75
1906 v77:i64 = AtomicLoad_64, v76
1907 v78:i64 = Iadd v74, v73
1908 v79:i32 = Icmp lt_u, v77, v78
1909 ExitIfTrue v79, exec_ctx, memory_out_of_bounds
1910 v80:i64 = Iadd v17, v74
1911 v81:i64 = Iconst_64 0x3
1912 v82:i64 = Band v80, v81
1913 v83:i64 = Iconst_64 0x0
1914 v84:i32 = Icmp neq, v82, v83
1915 ExitIfTrue v84, exec_ctx, unaligned_atomic
1916 v85:i64 = AtomicRmw sub_32, v80, v7
1917 v86:i32 = Iconst_32 0x30
1918 v87:i64 = Iconst_64 0x8
1919 v88:i64 = UExtend v86, 32->64
1920 v89:i64 = Iconst_64 0x10
1921 v90:i64 = Iadd module_ctx, v89
1922 v91:i64 = AtomicLoad_64, v90
1923 v92:i64 = Iadd v88, v87
1924 v93:i32 = Icmp lt_u, v91, v92
1925 ExitIfTrue v93, exec_ctx, memory_out_of_bounds
1926 v94:i64 = Iadd v17, v88
1927 v95:i64 = Iconst_64 0x7
1928 v96:i64 = Band v94, v95
1929 v97:i64 = Iconst_64 0x0
1930 v98:i32 = Icmp neq, v96, v97
1931 ExitIfTrue v98, exec_ctx, unaligned_atomic
1932 v99:i64 = AtomicRmw sub_64, v94, v8
1933 Jump blk_ret, v19, v33, v47, v57, v71, v85, v99
1934 `,
1935 },
1936 {
1937 name: "AtomicRMWAnd",
1938 m: testcases.AtomicRmwAnd.Module,
1939 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
1940 exp: `
1941 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i64, v6:i64, v7:i64, v8:i64)
1942 v9:i32 = Iconst_32 0x0
1943 v10:i64 = Iconst_64 0x1
1944 v11:i64 = UExtend v9, 32->64
1945 v12:i64 = Iconst_64 0x10
1946 v13:i64 = Iadd module_ctx, v12
1947 v14:i64 = AtomicLoad_64, v13
1948 v15:i64 = Iadd v11, v10
1949 v16:i32 = Icmp lt_u, v14, v15
1950 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
1951 v17:i64 = Load module_ctx, 0x8
1952 v18:i64 = Iadd v17, v11
1953 v19:i32 = AtomicRmw and_8, v18, v2
1954 v20:i32 = Iconst_32 0x0
1955 v21:i64 = Iconst_64 0xa
1956 v22:i64 = UExtend v20, 32->64
1957 v23:i64 = Iconst_64 0x10
1958 v24:i64 = Iadd module_ctx, v23
1959 v25:i64 = AtomicLoad_64, v24
1960 v26:i64 = Iadd v22, v21
1961 v27:i32 = Icmp lt_u, v25, v26
1962 ExitIfTrue v27, exec_ctx, memory_out_of_bounds
1963 v28:i64 = Iadd v17, v22
1964 v29:i64 = Iconst_64 0x8
1965 v30:i64 = Iadd v28, v29
1966 v31:i64 = Iconst_64 0x1
1967 v32:i64 = Band v30, v31
1968 v33:i64 = Iconst_64 0x0
1969 v34:i32 = Icmp neq, v32, v33
1970 ExitIfTrue v34, exec_ctx, unaligned_atomic
1971 v35:i32 = AtomicRmw and_16, v30, v3
1972 v36:i32 = Iconst_32 0x0
1973 v37:i64 = Iconst_64 0x14
1974 v38:i64 = UExtend v36, 32->64
1975 v39:i64 = Iconst_64 0x10
1976 v40:i64 = Iadd module_ctx, v39
1977 v41:i64 = AtomicLoad_64, v40
1978 v42:i64 = Iadd v38, v37
1979 v43:i32 = Icmp lt_u, v41, v42
1980 ExitIfTrue v43, exec_ctx, memory_out_of_bounds
1981 v44:i64 = Iadd v17, v38
1982 v45:i64 = Iconst_64 0x10
1983 v46:i64 = Iadd v44, v45
1984 v47:i64 = Iconst_64 0x3
1985 v48:i64 = Band v46, v47
1986 v49:i64 = Iconst_64 0x0
1987 v50:i32 = Icmp neq, v48, v49
1988 ExitIfTrue v50, exec_ctx, unaligned_atomic
1989 v51:i32 = AtomicRmw and_32, v46, v4
1990 v52:i32 = Iconst_32 0x0
1991 v53:i64 = Iconst_64 0x19
1992 v54:i64 = UExtend v52, 32->64
1993 v55:i64 = Iconst_64 0x10
1994 v56:i64 = Iadd module_ctx, v55
1995 v57:i64 = AtomicLoad_64, v56
1996 v58:i64 = Iadd v54, v53
1997 v59:i32 = Icmp lt_u, v57, v58
1998 ExitIfTrue v59, exec_ctx, memory_out_of_bounds
1999 v60:i64 = Iadd v17, v54
2000 v61:i64 = Iconst_64 0x18
2001 v62:i64 = Iadd v60, v61
2002 v63:i64 = AtomicRmw and_8, v62, v5
2003 v64:i32 = Iconst_32 0x0
2004 v65:i64 = Iconst_64 0x22
2005 v66:i64 = UExtend v64, 32->64
2006 v67:i64 = Iconst_64 0x10
2007 v68:i64 = Iadd module_ctx, v67
2008 v69:i64 = AtomicLoad_64, v68
2009 v70:i64 = Iadd v66, v65
2010 v71:i32 = Icmp lt_u, v69, v70
2011 ExitIfTrue v71, exec_ctx, memory_out_of_bounds
2012 v72:i64 = Iadd v17, v66
2013 v73:i64 = Iconst_64 0x20
2014 v74:i64 = Iadd v72, v73
2015 v75:i64 = Iconst_64 0x1
2016 v76:i64 = Band v74, v75
2017 v77:i64 = Iconst_64 0x0
2018 v78:i32 = Icmp neq, v76, v77
2019 ExitIfTrue v78, exec_ctx, unaligned_atomic
2020 v79:i64 = AtomicRmw and_16, v74, v6
2021 v80:i32 = Iconst_32 0x0
2022 v81:i64 = Iconst_64 0x2c
2023 v82:i64 = UExtend v80, 32->64
2024 v83:i64 = Iconst_64 0x10
2025 v84:i64 = Iadd module_ctx, v83
2026 v85:i64 = AtomicLoad_64, v84
2027 v86:i64 = Iadd v82, v81
2028 v87:i32 = Icmp lt_u, v85, v86
2029 ExitIfTrue v87, exec_ctx, memory_out_of_bounds
2030 v88:i64 = Iadd v17, v82
2031 v89:i64 = Iconst_64 0x28
2032 v90:i64 = Iadd v88, v89
2033 v91:i64 = Iconst_64 0x3
2034 v92:i64 = Band v90, v91
2035 v93:i64 = Iconst_64 0x0
2036 v94:i32 = Icmp neq, v92, v93
2037 ExitIfTrue v94, exec_ctx, unaligned_atomic
2038 v95:i64 = AtomicRmw and_32, v90, v7
2039 v96:i32 = Iconst_32 0x0
2040 v97:i64 = Iconst_64 0x38
2041 v98:i64 = UExtend v96, 32->64
2042 v99:i64 = Iconst_64 0x10
2043 v100:i64 = Iadd module_ctx, v99
2044 v101:i64 = AtomicLoad_64, v100
2045 v102:i64 = Iadd v98, v97
2046 v103:i32 = Icmp lt_u, v101, v102
2047 ExitIfTrue v103, exec_ctx, memory_out_of_bounds
2048 v104:i64 = Iadd v17, v98
2049 v105:i64 = Iconst_64 0x30
2050 v106:i64 = Iadd v104, v105
2051 v107:i64 = Iconst_64 0x7
2052 v108:i64 = Band v106, v107
2053 v109:i64 = Iconst_64 0x0
2054 v110:i32 = Icmp neq, v108, v109
2055 ExitIfTrue v110, exec_ctx, unaligned_atomic
2056 v111:i64 = AtomicRmw and_64, v106, v8
2057 Jump blk_ret, v19, v35, v51, v63, v79, v95, v111
2058 `,
2059 },
2060 {
2061 name: "AtomicRMWOr",
2062 m: testcases.AtomicRmwOr.Module,
2063 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
2064 exp: `
2065 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i64, v6:i64, v7:i64, v8:i64)
2066 v9:i32 = Iconst_32 0x0
2067 v10:i64 = Iconst_64 0x1
2068 v11:i64 = UExtend v9, 32->64
2069 v12:i64 = Iconst_64 0x10
2070 v13:i64 = Iadd module_ctx, v12
2071 v14:i64 = AtomicLoad_64, v13
2072 v15:i64 = Iadd v11, v10
2073 v16:i32 = Icmp lt_u, v14, v15
2074 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
2075 v17:i64 = Load module_ctx, 0x8
2076 v18:i64 = Iadd v17, v11
2077 v19:i32 = AtomicRmw or_8, v18, v2
2078 v20:i32 = Iconst_32 0x0
2079 v21:i64 = Iconst_64 0xa
2080 v22:i64 = UExtend v20, 32->64
2081 v23:i64 = Iconst_64 0x10
2082 v24:i64 = Iadd module_ctx, v23
2083 v25:i64 = AtomicLoad_64, v24
2084 v26:i64 = Iadd v22, v21
2085 v27:i32 = Icmp lt_u, v25, v26
2086 ExitIfTrue v27, exec_ctx, memory_out_of_bounds
2087 v28:i64 = Iadd v17, v22
2088 v29:i64 = Iconst_64 0x8
2089 v30:i64 = Iadd v28, v29
2090 v31:i64 = Iconst_64 0x1
2091 v32:i64 = Band v30, v31
2092 v33:i64 = Iconst_64 0x0
2093 v34:i32 = Icmp neq, v32, v33
2094 ExitIfTrue v34, exec_ctx, unaligned_atomic
2095 v35:i32 = AtomicRmw or_16, v30, v3
2096 v36:i32 = Iconst_32 0x0
2097 v37:i64 = Iconst_64 0x14
2098 v38:i64 = UExtend v36, 32->64
2099 v39:i64 = Iconst_64 0x10
2100 v40:i64 = Iadd module_ctx, v39
2101 v41:i64 = AtomicLoad_64, v40
2102 v42:i64 = Iadd v38, v37
2103 v43:i32 = Icmp lt_u, v41, v42
2104 ExitIfTrue v43, exec_ctx, memory_out_of_bounds
2105 v44:i64 = Iadd v17, v38
2106 v45:i64 = Iconst_64 0x10
2107 v46:i64 = Iadd v44, v45
2108 v47:i64 = Iconst_64 0x3
2109 v48:i64 = Band v46, v47
2110 v49:i64 = Iconst_64 0x0
2111 v50:i32 = Icmp neq, v48, v49
2112 ExitIfTrue v50, exec_ctx, unaligned_atomic
2113 v51:i32 = AtomicRmw or_32, v46, v4
2114 v52:i32 = Iconst_32 0x0
2115 v53:i64 = Iconst_64 0x19
2116 v54:i64 = UExtend v52, 32->64
2117 v55:i64 = Iconst_64 0x10
2118 v56:i64 = Iadd module_ctx, v55
2119 v57:i64 = AtomicLoad_64, v56
2120 v58:i64 = Iadd v54, v53
2121 v59:i32 = Icmp lt_u, v57, v58
2122 ExitIfTrue v59, exec_ctx, memory_out_of_bounds
2123 v60:i64 = Iadd v17, v54
2124 v61:i64 = Iconst_64 0x18
2125 v62:i64 = Iadd v60, v61
2126 v63:i64 = AtomicRmw or_8, v62, v5
2127 v64:i32 = Iconst_32 0x0
2128 v65:i64 = Iconst_64 0x22
2129 v66:i64 = UExtend v64, 32->64
2130 v67:i64 = Iconst_64 0x10
2131 v68:i64 = Iadd module_ctx, v67
2132 v69:i64 = AtomicLoad_64, v68
2133 v70:i64 = Iadd v66, v65
2134 v71:i32 = Icmp lt_u, v69, v70
2135 ExitIfTrue v71, exec_ctx, memory_out_of_bounds
2136 v72:i64 = Iadd v17, v66
2137 v73:i64 = Iconst_64 0x20
2138 v74:i64 = Iadd v72, v73
2139 v75:i64 = Iconst_64 0x1
2140 v76:i64 = Band v74, v75
2141 v77:i64 = Iconst_64 0x0
2142 v78:i32 = Icmp neq, v76, v77
2143 ExitIfTrue v78, exec_ctx, unaligned_atomic
2144 v79:i64 = AtomicRmw or_16, v74, v6
2145 v80:i32 = Iconst_32 0x0
2146 v81:i64 = Iconst_64 0x2c
2147 v82:i64 = UExtend v80, 32->64
2148 v83:i64 = Iconst_64 0x10
2149 v84:i64 = Iadd module_ctx, v83
2150 v85:i64 = AtomicLoad_64, v84
2151 v86:i64 = Iadd v82, v81
2152 v87:i32 = Icmp lt_u, v85, v86
2153 ExitIfTrue v87, exec_ctx, memory_out_of_bounds
2154 v88:i64 = Iadd v17, v82
2155 v89:i64 = Iconst_64 0x28
2156 v90:i64 = Iadd v88, v89
2157 v91:i64 = Iconst_64 0x3
2158 v92:i64 = Band v90, v91
2159 v93:i64 = Iconst_64 0x0
2160 v94:i32 = Icmp neq, v92, v93
2161 ExitIfTrue v94, exec_ctx, unaligned_atomic
2162 v95:i64 = AtomicRmw or_32, v90, v7
2163 v96:i32 = Iconst_32 0x0
2164 v97:i64 = Iconst_64 0x38
2165 v98:i64 = UExtend v96, 32->64
2166 v99:i64 = Iconst_64 0x10
2167 v100:i64 = Iadd module_ctx, v99
2168 v101:i64 = AtomicLoad_64, v100
2169 v102:i64 = Iadd v98, v97
2170 v103:i32 = Icmp lt_u, v101, v102
2171 ExitIfTrue v103, exec_ctx, memory_out_of_bounds
2172 v104:i64 = Iadd v17, v98
2173 v105:i64 = Iconst_64 0x30
2174 v106:i64 = Iadd v104, v105
2175 v107:i64 = Iconst_64 0x7
2176 v108:i64 = Band v106, v107
2177 v109:i64 = Iconst_64 0x0
2178 v110:i32 = Icmp neq, v108, v109
2179 ExitIfTrue v110, exec_ctx, unaligned_atomic
2180 v111:i64 = AtomicRmw or_64, v106, v8
2181 Jump blk_ret, v19, v35, v51, v63, v79, v95, v111
2182 `,
2183 },
2184 {
2185 name: "AtomicRMWXor",
2186 m: testcases.AtomicRmwXor.Module,
2187 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
2188 exp: `
2189 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i64, v6:i64, v7:i64, v8:i64)
2190 v9:i32 = Iconst_32 0x0
2191 v10:i64 = Iconst_64 0x1
2192 v11:i64 = UExtend v9, 32->64
2193 v12:i64 = Iconst_64 0x10
2194 v13:i64 = Iadd module_ctx, v12
2195 v14:i64 = AtomicLoad_64, v13
2196 v15:i64 = Iadd v11, v10
2197 v16:i32 = Icmp lt_u, v14, v15
2198 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
2199 v17:i64 = Load module_ctx, 0x8
2200 v18:i64 = Iadd v17, v11
2201 v19:i32 = AtomicRmw xor_8, v18, v2
2202 v20:i32 = Iconst_32 0x0
2203 v21:i64 = Iconst_64 0xa
2204 v22:i64 = UExtend v20, 32->64
2205 v23:i64 = Iconst_64 0x10
2206 v24:i64 = Iadd module_ctx, v23
2207 v25:i64 = AtomicLoad_64, v24
2208 v26:i64 = Iadd v22, v21
2209 v27:i32 = Icmp lt_u, v25, v26
2210 ExitIfTrue v27, exec_ctx, memory_out_of_bounds
2211 v28:i64 = Iadd v17, v22
2212 v29:i64 = Iconst_64 0x8
2213 v30:i64 = Iadd v28, v29
2214 v31:i64 = Iconst_64 0x1
2215 v32:i64 = Band v30, v31
2216 v33:i64 = Iconst_64 0x0
2217 v34:i32 = Icmp neq, v32, v33
2218 ExitIfTrue v34, exec_ctx, unaligned_atomic
2219 v35:i32 = AtomicRmw xor_16, v30, v3
2220 v36:i32 = Iconst_32 0x0
2221 v37:i64 = Iconst_64 0x14
2222 v38:i64 = UExtend v36, 32->64
2223 v39:i64 = Iconst_64 0x10
2224 v40:i64 = Iadd module_ctx, v39
2225 v41:i64 = AtomicLoad_64, v40
2226 v42:i64 = Iadd v38, v37
2227 v43:i32 = Icmp lt_u, v41, v42
2228 ExitIfTrue v43, exec_ctx, memory_out_of_bounds
2229 v44:i64 = Iadd v17, v38
2230 v45:i64 = Iconst_64 0x10
2231 v46:i64 = Iadd v44, v45
2232 v47:i64 = Iconst_64 0x3
2233 v48:i64 = Band v46, v47
2234 v49:i64 = Iconst_64 0x0
2235 v50:i32 = Icmp neq, v48, v49
2236 ExitIfTrue v50, exec_ctx, unaligned_atomic
2237 v51:i32 = AtomicRmw xor_32, v46, v4
2238 v52:i32 = Iconst_32 0x0
2239 v53:i64 = Iconst_64 0x19
2240 v54:i64 = UExtend v52, 32->64
2241 v55:i64 = Iconst_64 0x10
2242 v56:i64 = Iadd module_ctx, v55
2243 v57:i64 = AtomicLoad_64, v56
2244 v58:i64 = Iadd v54, v53
2245 v59:i32 = Icmp lt_u, v57, v58
2246 ExitIfTrue v59, exec_ctx, memory_out_of_bounds
2247 v60:i64 = Iadd v17, v54
2248 v61:i64 = Iconst_64 0x18
2249 v62:i64 = Iadd v60, v61
2250 v63:i64 = AtomicRmw xor_8, v62, v5
2251 v64:i32 = Iconst_32 0x0
2252 v65:i64 = Iconst_64 0x22
2253 v66:i64 = UExtend v64, 32->64
2254 v67:i64 = Iconst_64 0x10
2255 v68:i64 = Iadd module_ctx, v67
2256 v69:i64 = AtomicLoad_64, v68
2257 v70:i64 = Iadd v66, v65
2258 v71:i32 = Icmp lt_u, v69, v70
2259 ExitIfTrue v71, exec_ctx, memory_out_of_bounds
2260 v72:i64 = Iadd v17, v66
2261 v73:i64 = Iconst_64 0x20
2262 v74:i64 = Iadd v72, v73
2263 v75:i64 = Iconst_64 0x1
2264 v76:i64 = Band v74, v75
2265 v77:i64 = Iconst_64 0x0
2266 v78:i32 = Icmp neq, v76, v77
2267 ExitIfTrue v78, exec_ctx, unaligned_atomic
2268 v79:i64 = AtomicRmw xor_16, v74, v6
2269 v80:i32 = Iconst_32 0x0
2270 v81:i64 = Iconst_64 0x2c
2271 v82:i64 = UExtend v80, 32->64
2272 v83:i64 = Iconst_64 0x10
2273 v84:i64 = Iadd module_ctx, v83
2274 v85:i64 = AtomicLoad_64, v84
2275 v86:i64 = Iadd v82, v81
2276 v87:i32 = Icmp lt_u, v85, v86
2277 ExitIfTrue v87, exec_ctx, memory_out_of_bounds
2278 v88:i64 = Iadd v17, v82
2279 v89:i64 = Iconst_64 0x28
2280 v90:i64 = Iadd v88, v89
2281 v91:i64 = Iconst_64 0x3
2282 v92:i64 = Band v90, v91
2283 v93:i64 = Iconst_64 0x0
2284 v94:i32 = Icmp neq, v92, v93
2285 ExitIfTrue v94, exec_ctx, unaligned_atomic
2286 v95:i64 = AtomicRmw xor_32, v90, v7
2287 v96:i32 = Iconst_32 0x0
2288 v97:i64 = Iconst_64 0x38
2289 v98:i64 = UExtend v96, 32->64
2290 v99:i64 = Iconst_64 0x10
2291 v100:i64 = Iadd module_ctx, v99
2292 v101:i64 = AtomicLoad_64, v100
2293 v102:i64 = Iadd v98, v97
2294 v103:i32 = Icmp lt_u, v101, v102
2295 ExitIfTrue v103, exec_ctx, memory_out_of_bounds
2296 v104:i64 = Iadd v17, v98
2297 v105:i64 = Iconst_64 0x30
2298 v106:i64 = Iadd v104, v105
2299 v107:i64 = Iconst_64 0x7
2300 v108:i64 = Band v106, v107
2301 v109:i64 = Iconst_64 0x0
2302 v110:i32 = Icmp neq, v108, v109
2303 ExitIfTrue v110, exec_ctx, unaligned_atomic
2304 v111:i64 = AtomicRmw xor_64, v106, v8
2305 Jump blk_ret, v19, v35, v51, v63, v79, v95, v111
2306 `,
2307 },
2308 {
2309 name: "AtomicRMWXchg",
2310 m: testcases.AtomicRmwXchg.Module,
2311 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
2312 exp: `
2313 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i64, v6:i64, v7:i64, v8:i64)
2314 v9:i32 = Iconst_32 0x0
2315 v10:i64 = Iconst_64 0x1
2316 v11:i64 = UExtend v9, 32->64
2317 v12:i64 = Iconst_64 0x10
2318 v13:i64 = Iadd module_ctx, v12
2319 v14:i64 = AtomicLoad_64, v13
2320 v15:i64 = Iadd v11, v10
2321 v16:i32 = Icmp lt_u, v14, v15
2322 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
2323 v17:i64 = Load module_ctx, 0x8
2324 v18:i64 = Iadd v17, v11
2325 v19:i32 = AtomicRmw xchg_8, v18, v2
2326 v20:i32 = Iconst_32 0x0
2327 v21:i64 = Iconst_64 0xa
2328 v22:i64 = UExtend v20, 32->64
2329 v23:i64 = Iconst_64 0x10
2330 v24:i64 = Iadd module_ctx, v23
2331 v25:i64 = AtomicLoad_64, v24
2332 v26:i64 = Iadd v22, v21
2333 v27:i32 = Icmp lt_u, v25, v26
2334 ExitIfTrue v27, exec_ctx, memory_out_of_bounds
2335 v28:i64 = Iadd v17, v22
2336 v29:i64 = Iconst_64 0x8
2337 v30:i64 = Iadd v28, v29
2338 v31:i64 = Iconst_64 0x1
2339 v32:i64 = Band v30, v31
2340 v33:i64 = Iconst_64 0x0
2341 v34:i32 = Icmp neq, v32, v33
2342 ExitIfTrue v34, exec_ctx, unaligned_atomic
2343 v35:i32 = AtomicRmw xchg_16, v30, v3
2344 v36:i32 = Iconst_32 0x0
2345 v37:i64 = Iconst_64 0x14
2346 v38:i64 = UExtend v36, 32->64
2347 v39:i64 = Iconst_64 0x10
2348 v40:i64 = Iadd module_ctx, v39
2349 v41:i64 = AtomicLoad_64, v40
2350 v42:i64 = Iadd v38, v37
2351 v43:i32 = Icmp lt_u, v41, v42
2352 ExitIfTrue v43, exec_ctx, memory_out_of_bounds
2353 v44:i64 = Iadd v17, v38
2354 v45:i64 = Iconst_64 0x10
2355 v46:i64 = Iadd v44, v45
2356 v47:i64 = Iconst_64 0x3
2357 v48:i64 = Band v46, v47
2358 v49:i64 = Iconst_64 0x0
2359 v50:i32 = Icmp neq, v48, v49
2360 ExitIfTrue v50, exec_ctx, unaligned_atomic
2361 v51:i32 = AtomicRmw xchg_32, v46, v4
2362 v52:i32 = Iconst_32 0x0
2363 v53:i64 = Iconst_64 0x19
2364 v54:i64 = UExtend v52, 32->64
2365 v55:i64 = Iconst_64 0x10
2366 v56:i64 = Iadd module_ctx, v55
2367 v57:i64 = AtomicLoad_64, v56
2368 v58:i64 = Iadd v54, v53
2369 v59:i32 = Icmp lt_u, v57, v58
2370 ExitIfTrue v59, exec_ctx, memory_out_of_bounds
2371 v60:i64 = Iadd v17, v54
2372 v61:i64 = Iconst_64 0x18
2373 v62:i64 = Iadd v60, v61
2374 v63:i64 = AtomicRmw xchg_8, v62, v5
2375 v64:i32 = Iconst_32 0x0
2376 v65:i64 = Iconst_64 0x22
2377 v66:i64 = UExtend v64, 32->64
2378 v67:i64 = Iconst_64 0x10
2379 v68:i64 = Iadd module_ctx, v67
2380 v69:i64 = AtomicLoad_64, v68
2381 v70:i64 = Iadd v66, v65
2382 v71:i32 = Icmp lt_u, v69, v70
2383 ExitIfTrue v71, exec_ctx, memory_out_of_bounds
2384 v72:i64 = Iadd v17, v66
2385 v73:i64 = Iconst_64 0x20
2386 v74:i64 = Iadd v72, v73
2387 v75:i64 = Iconst_64 0x1
2388 v76:i64 = Band v74, v75
2389 v77:i64 = Iconst_64 0x0
2390 v78:i32 = Icmp neq, v76, v77
2391 ExitIfTrue v78, exec_ctx, unaligned_atomic
2392 v79:i64 = AtomicRmw xchg_16, v74, v6
2393 v80:i32 = Iconst_32 0x0
2394 v81:i64 = Iconst_64 0x2c
2395 v82:i64 = UExtend v80, 32->64
2396 v83:i64 = Iconst_64 0x10
2397 v84:i64 = Iadd module_ctx, v83
2398 v85:i64 = AtomicLoad_64, v84
2399 v86:i64 = Iadd v82, v81
2400 v87:i32 = Icmp lt_u, v85, v86
2401 ExitIfTrue v87, exec_ctx, memory_out_of_bounds
2402 v88:i64 = Iadd v17, v82
2403 v89:i64 = Iconst_64 0x28
2404 v90:i64 = Iadd v88, v89
2405 v91:i64 = Iconst_64 0x3
2406 v92:i64 = Band v90, v91
2407 v93:i64 = Iconst_64 0x0
2408 v94:i32 = Icmp neq, v92, v93
2409 ExitIfTrue v94, exec_ctx, unaligned_atomic
2410 v95:i64 = AtomicRmw xchg_32, v90, v7
2411 v96:i32 = Iconst_32 0x0
2412 v97:i64 = Iconst_64 0x38
2413 v98:i64 = UExtend v96, 32->64
2414 v99:i64 = Iconst_64 0x10
2415 v100:i64 = Iadd module_ctx, v99
2416 v101:i64 = AtomicLoad_64, v100
2417 v102:i64 = Iadd v98, v97
2418 v103:i32 = Icmp lt_u, v101, v102
2419 ExitIfTrue v103, exec_ctx, memory_out_of_bounds
2420 v104:i64 = Iadd v17, v98
2421 v105:i64 = Iconst_64 0x30
2422 v106:i64 = Iadd v104, v105
2423 v107:i64 = Iconst_64 0x7
2424 v108:i64 = Band v106, v107
2425 v109:i64 = Iconst_64 0x0
2426 v110:i32 = Icmp neq, v108, v109
2427 ExitIfTrue v110, exec_ctx, unaligned_atomic
2428 v111:i64 = AtomicRmw xchg_64, v106, v8
2429 Jump blk_ret, v19, v35, v51, v63, v79, v95, v111
2430 `,
2431 },
2432 {
2433 name: "AtomicStoreLoad",
2434 m: testcases.AtomicStoreLoad.Module,
2435 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
2436 exp: `
2437 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i64, v6:i64, v7:i64, v8:i64)
2438 v9:i32 = Iconst_32 0x0
2439 v10:i64 = Iconst_64 0x1
2440 v11:i64 = UExtend v9, 32->64
2441 v12:i64 = Iconst_64 0x10
2442 v13:i64 = Iadd module_ctx, v12
2443 v14:i64 = AtomicLoad_64, v13
2444 v15:i64 = Iadd v11, v10
2445 v16:i32 = Icmp lt_u, v14, v15
2446 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
2447 v17:i64 = Load module_ctx, 0x8
2448 v18:i64 = Iadd v17, v11
2449 AtomicStore_8, v18, v2
2450 v19:i32 = Iconst_32 0x0
2451 v20:i64 = Iconst_64 0x1
2452 v21:i64 = UExtend v19, 32->64
2453 v22:i64 = Iconst_64 0x10
2454 v23:i64 = Iadd module_ctx, v22
2455 v24:i64 = AtomicLoad_64, v23
2456 v25:i64 = Iadd v21, v20
2457 v26:i32 = Icmp lt_u, v24, v25
2458 ExitIfTrue v26, exec_ctx, memory_out_of_bounds
2459 v27:i64 = Iadd v17, v21
2460 v28:i32 = AtomicLoad_8, v27
2461 v29:i32 = Iconst_32 0x0
2462 v30:i64 = Iconst_64 0xa
2463 v31:i64 = UExtend v29, 32->64
2464 v32:i64 = Iconst_64 0x10
2465 v33:i64 = Iadd module_ctx, v32
2466 v34:i64 = AtomicLoad_64, v33
2467 v35:i64 = Iadd v31, v30
2468 v36:i32 = Icmp lt_u, v34, v35
2469 ExitIfTrue v36, exec_ctx, memory_out_of_bounds
2470 v37:i64 = Iadd v17, v31
2471 v38:i64 = Iconst_64 0x8
2472 v39:i64 = Iadd v37, v38
2473 v40:i64 = Iconst_64 0x1
2474 v41:i64 = Band v39, v40
2475 v42:i64 = Iconst_64 0x0
2476 v43:i32 = Icmp neq, v41, v42
2477 ExitIfTrue v43, exec_ctx, unaligned_atomic
2478 AtomicStore_16, v39, v3
2479 v44:i32 = Iconst_32 0x0
2480 v45:i64 = Iconst_64 0xa
2481 v46:i64 = UExtend v44, 32->64
2482 v47:i64 = Iconst_64 0x10
2483 v48:i64 = Iadd module_ctx, v47
2484 v49:i64 = AtomicLoad_64, v48
2485 v50:i64 = Iadd v46, v45
2486 v51:i32 = Icmp lt_u, v49, v50
2487 ExitIfTrue v51, exec_ctx, memory_out_of_bounds
2488 v52:i64 = Iadd v17, v46
2489 v53:i64 = Iconst_64 0x8
2490 v54:i64 = Iadd v52, v53
2491 v55:i64 = Iconst_64 0x1
2492 v56:i64 = Band v54, v55
2493 v57:i64 = Iconst_64 0x0
2494 v58:i32 = Icmp neq, v56, v57
2495 ExitIfTrue v58, exec_ctx, unaligned_atomic
2496 v59:i32 = AtomicLoad_16, v54
2497 v60:i32 = Iconst_32 0x0
2498 v61:i64 = Iconst_64 0x14
2499 v62:i64 = UExtend v60, 32->64
2500 v63:i64 = Iconst_64 0x10
2501 v64:i64 = Iadd module_ctx, v63
2502 v65:i64 = AtomicLoad_64, v64
2503 v66:i64 = Iadd v62, v61
2504 v67:i32 = Icmp lt_u, v65, v66
2505 ExitIfTrue v67, exec_ctx, memory_out_of_bounds
2506 v68:i64 = Iadd v17, v62
2507 v69:i64 = Iconst_64 0x10
2508 v70:i64 = Iadd v68, v69
2509 v71:i64 = Iconst_64 0x3
2510 v72:i64 = Band v70, v71
2511 v73:i64 = Iconst_64 0x0
2512 v74:i32 = Icmp neq, v72, v73
2513 ExitIfTrue v74, exec_ctx, unaligned_atomic
2514 AtomicStore_32, v70, v4
2515 v75:i32 = Iconst_32 0x0
2516 v76:i64 = Iconst_64 0x14
2517 v77:i64 = UExtend v75, 32->64
2518 v78:i64 = Iconst_64 0x10
2519 v79:i64 = Iadd module_ctx, v78
2520 v80:i64 = AtomicLoad_64, v79
2521 v81:i64 = Iadd v77, v76
2522 v82:i32 = Icmp lt_u, v80, v81
2523 ExitIfTrue v82, exec_ctx, memory_out_of_bounds
2524 v83:i64 = Iadd v17, v77
2525 v84:i64 = Iconst_64 0x10
2526 v85:i64 = Iadd v83, v84
2527 v86:i64 = Iconst_64 0x3
2528 v87:i64 = Band v85, v86
2529 v88:i64 = Iconst_64 0x0
2530 v89:i32 = Icmp neq, v87, v88
2531 ExitIfTrue v89, exec_ctx, unaligned_atomic
2532 v90:i32 = AtomicLoad_32, v85
2533 v91:i32 = Iconst_32 0x0
2534 v92:i64 = Iconst_64 0x19
2535 v93:i64 = UExtend v91, 32->64
2536 v94:i64 = Iconst_64 0x10
2537 v95:i64 = Iadd module_ctx, v94
2538 v96:i64 = AtomicLoad_64, v95
2539 v97:i64 = Iadd v93, v92
2540 v98:i32 = Icmp lt_u, v96, v97
2541 ExitIfTrue v98, exec_ctx, memory_out_of_bounds
2542 v99:i64 = Iadd v17, v93
2543 v100:i64 = Iconst_64 0x18
2544 v101:i64 = Iadd v99, v100
2545 AtomicStore_8, v101, v5
2546 v102:i32 = Iconst_32 0x0
2547 v103:i64 = Iconst_64 0x19
2548 v104:i64 = UExtend v102, 32->64
2549 v105:i64 = Iconst_64 0x10
2550 v106:i64 = Iadd module_ctx, v105
2551 v107:i64 = AtomicLoad_64, v106
2552 v108:i64 = Iadd v104, v103
2553 v109:i32 = Icmp lt_u, v107, v108
2554 ExitIfTrue v109, exec_ctx, memory_out_of_bounds
2555 v110:i64 = Iadd v17, v104
2556 v111:i64 = Iconst_64 0x18
2557 v112:i64 = Iadd v110, v111
2558 v113:i64 = AtomicLoad_8, v112
2559 v114:i32 = Iconst_32 0x0
2560 v115:i64 = Iconst_64 0x22
2561 v116:i64 = UExtend v114, 32->64
2562 v117:i64 = Iconst_64 0x10
2563 v118:i64 = Iadd module_ctx, v117
2564 v119:i64 = AtomicLoad_64, v118
2565 v120:i64 = Iadd v116, v115
2566 v121:i32 = Icmp lt_u, v119, v120
2567 ExitIfTrue v121, exec_ctx, memory_out_of_bounds
2568 v122:i64 = Iadd v17, v116
2569 v123:i64 = Iconst_64 0x20
2570 v124:i64 = Iadd v122, v123
2571 v125:i64 = Iconst_64 0x1
2572 v126:i64 = Band v124, v125
2573 v127:i64 = Iconst_64 0x0
2574 v128:i32 = Icmp neq, v126, v127
2575 ExitIfTrue v128, exec_ctx, unaligned_atomic
2576 AtomicStore_16, v124, v6
2577 v129:i32 = Iconst_32 0x0
2578 v130:i64 = Iconst_64 0x22
2579 v131:i64 = UExtend v129, 32->64
2580 v132:i64 = Iconst_64 0x10
2581 v133:i64 = Iadd module_ctx, v132
2582 v134:i64 = AtomicLoad_64, v133
2583 v135:i64 = Iadd v131, v130
2584 v136:i32 = Icmp lt_u, v134, v135
2585 ExitIfTrue v136, exec_ctx, memory_out_of_bounds
2586 v137:i64 = Iadd v17, v131
2587 v138:i64 = Iconst_64 0x20
2588 v139:i64 = Iadd v137, v138
2589 v140:i64 = Iconst_64 0x1
2590 v141:i64 = Band v139, v140
2591 v142:i64 = Iconst_64 0x0
2592 v143:i32 = Icmp neq, v141, v142
2593 ExitIfTrue v143, exec_ctx, unaligned_atomic
2594 v144:i64 = AtomicLoad_16, v139
2595 v145:i32 = Iconst_32 0x0
2596 v146:i64 = Iconst_64 0x2c
2597 v147:i64 = UExtend v145, 32->64
2598 v148:i64 = Iconst_64 0x10
2599 v149:i64 = Iadd module_ctx, v148
2600 v150:i64 = AtomicLoad_64, v149
2601 v151:i64 = Iadd v147, v146
2602 v152:i32 = Icmp lt_u, v150, v151
2603 ExitIfTrue v152, exec_ctx, memory_out_of_bounds
2604 v153:i64 = Iadd v17, v147
2605 v154:i64 = Iconst_64 0x28
2606 v155:i64 = Iadd v153, v154
2607 v156:i64 = Iconst_64 0x3
2608 v157:i64 = Band v155, v156
2609 v158:i64 = Iconst_64 0x0
2610 v159:i32 = Icmp neq, v157, v158
2611 ExitIfTrue v159, exec_ctx, unaligned_atomic
2612 AtomicStore_32, v155, v7
2613 v160:i32 = Iconst_32 0x0
2614 v161:i64 = Iconst_64 0x2c
2615 v162:i64 = UExtend v160, 32->64
2616 v163:i64 = Iconst_64 0x10
2617 v164:i64 = Iadd module_ctx, v163
2618 v165:i64 = AtomicLoad_64, v164
2619 v166:i64 = Iadd v162, v161
2620 v167:i32 = Icmp lt_u, v165, v166
2621 ExitIfTrue v167, exec_ctx, memory_out_of_bounds
2622 v168:i64 = Iadd v17, v162
2623 v169:i64 = Iconst_64 0x28
2624 v170:i64 = Iadd v168, v169
2625 v171:i64 = Iconst_64 0x3
2626 v172:i64 = Band v170, v171
2627 v173:i64 = Iconst_64 0x0
2628 v174:i32 = Icmp neq, v172, v173
2629 ExitIfTrue v174, exec_ctx, unaligned_atomic
2630 v175:i64 = AtomicLoad_32, v170
2631 v176:i32 = Iconst_32 0x0
2632 v177:i64 = Iconst_64 0x38
2633 v178:i64 = UExtend v176, 32->64
2634 v179:i64 = Iconst_64 0x10
2635 v180:i64 = Iadd module_ctx, v179
2636 v181:i64 = AtomicLoad_64, v180
2637 v182:i64 = Iadd v178, v177
2638 v183:i32 = Icmp lt_u, v181, v182
2639 ExitIfTrue v183, exec_ctx, memory_out_of_bounds
2640 v184:i64 = Iadd v17, v178
2641 v185:i64 = Iconst_64 0x30
2642 v186:i64 = Iadd v184, v185
2643 v187:i64 = Iconst_64 0x7
2644 v188:i64 = Band v186, v187
2645 v189:i64 = Iconst_64 0x0
2646 v190:i32 = Icmp neq, v188, v189
2647 ExitIfTrue v190, exec_ctx, unaligned_atomic
2648 AtomicStore_64, v186, v8
2649 v191:i32 = Iconst_32 0x0
2650 v192:i64 = Iconst_64 0x38
2651 v193:i64 = UExtend v191, 32->64
2652 v194:i64 = Iconst_64 0x10
2653 v195:i64 = Iadd module_ctx, v194
2654 v196:i64 = AtomicLoad_64, v195
2655 v197:i64 = Iadd v193, v192
2656 v198:i32 = Icmp lt_u, v196, v197
2657 ExitIfTrue v198, exec_ctx, memory_out_of_bounds
2658 v199:i64 = Iadd v17, v193
2659 v200:i64 = Iconst_64 0x30
2660 v201:i64 = Iadd v199, v200
2661 v202:i64 = Iconst_64 0x7
2662 v203:i64 = Band v201, v202
2663 v204:i64 = Iconst_64 0x0
2664 v205:i32 = Icmp neq, v203, v204
2665 ExitIfTrue v205, exec_ctx, unaligned_atomic
2666 v206:i64 = AtomicLoad_64, v201
2667 Jump blk_ret, v28, v59, v90, v113, v144, v175, v206
2668 `,
2669 },
2670 {
2671 name: "AtomicCas",
2672 m: testcases.AtomicCas.Module,
2673 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
2674 exp: `
2675 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32, v3:i32, v4:i32, v5:i32, v6:i32, v7:i32, v8:i64, v9:i64, v10:i64, v11:i64, v12:i64, v13:i64, v14:i64, v15:i64)
2676 v16:i32 = Iconst_32 0x0
2677 v17:i64 = Iconst_64 0x1
2678 v18:i64 = UExtend v16, 32->64
2679 v19:i64 = Iconst_64 0x10
2680 v20:i64 = Iadd module_ctx, v19
2681 v21:i64 = AtomicLoad_64, v20
2682 v22:i64 = Iadd v18, v17
2683 v23:i32 = Icmp lt_u, v21, v22
2684 ExitIfTrue v23, exec_ctx, memory_out_of_bounds
2685 v24:i64 = Load module_ctx, 0x8
2686 v25:i64 = Iadd v24, v18
2687 v26:i32 = AtomicCas_8, v25, v2, v3
2688 v27:i32 = Iconst_32 0x0
2689 v28:i64 = Iconst_64 0xa
2690 v29:i64 = UExtend v27, 32->64
2691 v30:i64 = Iconst_64 0x10
2692 v31:i64 = Iadd module_ctx, v30
2693 v32:i64 = AtomicLoad_64, v31
2694 v33:i64 = Iadd v29, v28
2695 v34:i32 = Icmp lt_u, v32, v33
2696 ExitIfTrue v34, exec_ctx, memory_out_of_bounds
2697 v35:i64 = Iadd v24, v29
2698 v36:i64 = Iconst_64 0x8
2699 v37:i64 = Iadd v35, v36
2700 v38:i64 = Iconst_64 0x1
2701 v39:i64 = Band v37, v38
2702 v40:i64 = Iconst_64 0x0
2703 v41:i32 = Icmp neq, v39, v40
2704 ExitIfTrue v41, exec_ctx, unaligned_atomic
2705 v42:i32 = AtomicCas_16, v37, v4, v5
2706 v43:i32 = Iconst_32 0x0
2707 v44:i64 = Iconst_64 0x14
2708 v45:i64 = UExtend v43, 32->64
2709 v46:i64 = Iconst_64 0x10
2710 v47:i64 = Iadd module_ctx, v46
2711 v48:i64 = AtomicLoad_64, v47
2712 v49:i64 = Iadd v45, v44
2713 v50:i32 = Icmp lt_u, v48, v49
2714 ExitIfTrue v50, exec_ctx, memory_out_of_bounds
2715 v51:i64 = Iadd v24, v45
2716 v52:i64 = Iconst_64 0x10
2717 v53:i64 = Iadd v51, v52
2718 v54:i64 = Iconst_64 0x3
2719 v55:i64 = Band v53, v54
2720 v56:i64 = Iconst_64 0x0
2721 v57:i32 = Icmp neq, v55, v56
2722 ExitIfTrue v57, exec_ctx, unaligned_atomic
2723 v58:i32 = AtomicCas_32, v53, v6, v7
2724 v59:i32 = Iconst_32 0x0
2725 v60:i64 = Iconst_64 0x19
2726 v61:i64 = UExtend v59, 32->64
2727 v62:i64 = Iconst_64 0x10
2728 v63:i64 = Iadd module_ctx, v62
2729 v64:i64 = AtomicLoad_64, v63
2730 v65:i64 = Iadd v61, v60
2731 v66:i32 = Icmp lt_u, v64, v65
2732 ExitIfTrue v66, exec_ctx, memory_out_of_bounds
2733 v67:i64 = Iadd v24, v61
2734 v68:i64 = Iconst_64 0x18
2735 v69:i64 = Iadd v67, v68
2736 v70:i64 = AtomicCas_8, v69, v8, v9
2737 v71:i32 = Iconst_32 0x0
2738 v72:i64 = Iconst_64 0x22
2739 v73:i64 = UExtend v71, 32->64
2740 v74:i64 = Iconst_64 0x10
2741 v75:i64 = Iadd module_ctx, v74
2742 v76:i64 = AtomicLoad_64, v75
2743 v77:i64 = Iadd v73, v72
2744 v78:i32 = Icmp lt_u, v76, v77
2745 ExitIfTrue v78, exec_ctx, memory_out_of_bounds
2746 v79:i64 = Iadd v24, v73
2747 v80:i64 = Iconst_64 0x20
2748 v81:i64 = Iadd v79, v80
2749 v82:i64 = Iconst_64 0x1
2750 v83:i64 = Band v81, v82
2751 v84:i64 = Iconst_64 0x0
2752 v85:i32 = Icmp neq, v83, v84
2753 ExitIfTrue v85, exec_ctx, unaligned_atomic
2754 v86:i64 = AtomicCas_16, v81, v10, v11
2755 v87:i32 = Iconst_32 0x0
2756 v88:i64 = Iconst_64 0x2c
2757 v89:i64 = UExtend v87, 32->64
2758 v90:i64 = Iconst_64 0x10
2759 v91:i64 = Iadd module_ctx, v90
2760 v92:i64 = AtomicLoad_64, v91
2761 v93:i64 = Iadd v89, v88
2762 v94:i32 = Icmp lt_u, v92, v93
2763 ExitIfTrue v94, exec_ctx, memory_out_of_bounds
2764 v95:i64 = Iadd v24, v89
2765 v96:i64 = Iconst_64 0x28
2766 v97:i64 = Iadd v95, v96
2767 v98:i64 = Iconst_64 0x3
2768 v99:i64 = Band v97, v98
2769 v100:i64 = Iconst_64 0x0
2770 v101:i32 = Icmp neq, v99, v100
2771 ExitIfTrue v101, exec_ctx, unaligned_atomic
2772 v102:i64 = AtomicCas_32, v97, v12, v13
2773 v103:i32 = Iconst_32 0x0
2774 v104:i64 = Iconst_64 0x38
2775 v105:i64 = UExtend v103, 32->64
2776 v106:i64 = Iconst_64 0x10
2777 v107:i64 = Iadd module_ctx, v106
2778 v108:i64 = AtomicLoad_64, v107
2779 v109:i64 = Iadd v105, v104
2780 v110:i32 = Icmp lt_u, v108, v109
2781 ExitIfTrue v110, exec_ctx, memory_out_of_bounds
2782 v111:i64 = Iadd v24, v105
2783 v112:i64 = Iconst_64 0x30
2784 v113:i64 = Iadd v111, v112
2785 v114:i64 = Iconst_64 0x7
2786 v115:i64 = Band v113, v114
2787 v116:i64 = Iconst_64 0x0
2788 v117:i32 = Icmp neq, v115, v116
2789 ExitIfTrue v117, exec_ctx, unaligned_atomic
2790 v118:i64 = AtomicCas_64, v113, v14, v15
2791 Jump blk_ret, v26, v42, v58, v70, v86, v102, v118
2792 `,
2793 },
2794 {
2795 name: "AtomicFence",
2796 m: testcases.AtomicFence.Module,
2797 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
2798 exp: `
2799 blk0: (exec_ctx:i64, module_ctx:i64)
2800 Fence 0
2801 Jump blk_ret
2802 `,
2803 },
2804 {
2805 name: "AtomicFenceNoMemory",
2806 m: testcases.AtomicFenceNoMemory.Module,
2807 features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
2808 exp: `
2809 blk0: (exec_ctx:i64, module_ctx:i64)
2810 Jump blk_ret
2811 `,
2812 },
2813 {
2814 name: "bounds check in if-else",
2815 m: &wasm.Module{
2816 TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{wasm.ValueTypeI32}}},
2817 FunctionSection: []wasm.Index{0},
2818 CodeSection: []wasm.Code{{
2819 Body: []byte{
2820 wasm.OpcodeLocalGet, 0,
2821 wasm.OpcodeI32Load, 0x2, 0x20, // alignment=2 (natural alignment) staticOffset=0x20
2822 wasm.OpcodeDrop,
2823
2824 wasm.OpcodeLocalGet, 0,
2825 wasm.OpcodeIf, 0x40, // blockSignature:vv.
2826 /* */ wasm.OpcodeLocalGet, 0,
2827 /* */ // This bound check should be removed since it's known to be in bounds.
2828 /* */ wasm.OpcodeI32Load, 0x2, 0x10, // alignment=2 (natural alignment) staticOffset=0x20
2829 /* */ wasm.OpcodeDrop,
2830 wasm.OpcodeElse,
2831 /* */ wasm.OpcodeLocalGet, 0,
2832 /* */ // This bound check should be removed since it's known to be in bounds.
2833 /* */ wasm.OpcodeI32Load, 0x2, 0x10, // alignment=2 (natural alignment) staticOffset=0x20
2834 /* */ wasm.OpcodeDrop,
2835 /* */ // This shouldn't be removed since it's not known to be in bounds.
2836 /* */ wasm.OpcodeLocalGet, 0,
2837 /* */ wasm.OpcodeI32Load, 0x2, 0x30, // alignment=2 (natural alignment) staticOffset=0x20
2838 /* */ wasm.OpcodeDrop,
2839 /* */ // But this is known to be in bounds.
2840 /* */ wasm.OpcodeLocalGet, 0,
2841 /* */ wasm.OpcodeI32Load, 0x2, 0x25, // alignment=2 (natural alignment) staticOffset=0x20
2842 /* */ wasm.OpcodeDrop,
2843 wasm.OpcodeEnd,
2844
2845 // At this point, the known bound 0x20 should be retained.
2846 wasm.OpcodeLocalGet, 0,
2847 wasm.OpcodeI32Load, 0x2, 0x15, // alignment=2 (natural alignment) staticOffset=0x20
2848 wasm.OpcodeDrop,
2849
2850 wasm.OpcodeEnd,
2851 },
2852 }},
2853 MemorySection: &wasm.Memory{Min: 1},
2854 },
2855 features: api.CoreFeaturesV2,
2856 exp: `
2857 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
2858 v3:i64 = Iconst_64 0x24
2859 v4:i64 = UExtend v2, 32->64
2860 v5:i64 = Uload32 module_ctx, 0x10
2861 v6:i64 = Iadd v4, v3
2862 v7:i32 = Icmp lt_u, v5, v6
2863 ExitIfTrue v7, exec_ctx, memory_out_of_bounds
2864 v8:i64 = Load module_ctx, 0x8
2865 v9:i64 = Iadd v8, v4
2866 v10:i32 = Load v9, 0x20
2867 Brz v2, blk2
2868 Jump blk1
2869
2870 blk1: () <-- (blk0)
2871 v11:i32 = Load v9, 0x10
2872 Jump blk3
2873
2874 blk2: () <-- (blk0)
2875 v12:i32 = Load v9, 0x10
2876 v13:i64 = Iconst_64 0x34
2877 v14:i64 = UExtend v2, 32->64
2878 v15:i64 = Iadd v14, v13
2879 v16:i32 = Icmp lt_u, v5, v15
2880 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
2881 v17:i32 = Load v9, 0x30
2882 v18:i32 = Load v9, 0x25
2883 Jump blk3
2884
2885 blk3: () <-- (blk1,blk2)
2886 v20:i64 = Load module_ctx, 0x8
2887 v21:i64 = UExtend v2, 32->64
2888 v22:i64 = Iadd v20, v21
2889 v23:i32 = Load v22, 0x15
2890 Jump blk_ret
2891 `,
2892 },
2893 {
2894 name: "bounds check in loop with if-else",
2895 m: &wasm.Module{
2896 TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{wasm.ValueTypeI32}}},
2897 FunctionSection: []wasm.Index{0},
2898 CodeSection: []wasm.Code{{
2899 Body: []byte{
2900 wasm.OpcodeLocalGet, 0,
2901 wasm.OpcodeI32Load, 0x2, 0x10, // staticOffset=0x20
2902 wasm.OpcodeDrop,
2903
2904 wasm.OpcodeLoop, 0x40, // blockSignature:vv.
2905
2906 /* */ wasm.OpcodeLocalGet, 0,
2907 // This address must be always recomputed:
2908 // v9 in `Load v9, 0x20` won't propagate from blk0 to blk1,
2909 /* */ wasm.OpcodeI32Load, 0x2, 0x20, // staticOffset=0x30
2910
2911 /* */ wasm.OpcodeIf, 0x40, // blockSignature:vv.
2912 /* */ /* */ wasm.OpcodeLoop, 0x40, // blockSignature:vv.
2913 /* */ /* */ /* */ wasm.OpcodeLocalGet, 0,
2914 /* */ /* */ /* */ wasm.OpcodeI32Load, 0x2, 0x50, // staticOffset=0x50
2915 /* */ /* */ /* */ wasm.OpcodeBrIf, 2, // quit to the inner loop
2916 /* */ /* */ wasm.OpcodeEnd,
2917 /* */ wasm.OpcodeElse,
2918 /* */ /* */ wasm.OpcodeLocalGet, 0,
2919 /* */ /* */ wasm.OpcodeBrIf, 2, // quit to the outer loop
2920 /* */ wasm.OpcodeEnd,
2921 /* */ wasm.OpcodeBr, 1, // quit to the loop
2922
2923 wasm.OpcodeEnd, // end loop
2924
2925 wasm.OpcodeEnd,
2926 },
2927 }},
2928 MemorySection: &wasm.Memory{Min: 1},
2929 },
2930 features: api.CoreFeaturesV2,
2931 exp: `
2932 blk0: (exec_ctx:i64, module_ctx:i64, v2:i32)
2933 v3:i64 = Iconst_64 0x14
2934 v4:i64 = UExtend v2, 32->64
2935 v5:i64 = Uload32 module_ctx, 0x10
2936 v6:i64 = Iadd v4, v3
2937 v7:i32 = Icmp lt_u, v5, v6
2938 ExitIfTrue v7, exec_ctx, memory_out_of_bounds
2939 v8:i64 = Load module_ctx, 0x8
2940 v9:i64 = Iadd v8, v4
2941 v10:i32 = Load v9, 0x10
2942 Jump blk1, v2
2943
2944 blk1: (v11:i32) <-- (blk0,blk6)
2945 v12:i64 = Iconst_64 0x24
2946 v13:i64 = UExtend v11, 32->64
2947 v14:i64 = Uload32 module_ctx, 0x10
2948 v15:i64 = Iadd v13, v12
2949 v16:i32 = Icmp lt_u, v14, v15
2950 ExitIfTrue v16, exec_ctx, memory_out_of_bounds
2951 v17:i64 = Load module_ctx, 0x8
2952 v18:i64 = Iadd v17, v13
2953 v19:i32 = Load v18, 0x20
2954 Brz v19, blk4
2955 Jump blk3
2956
2957 blk2: ()
2958
2959 blk3: () <-- (blk1)
2960 Jump blk6, v11
2961
2962 blk4: () <-- (blk1)
2963 Brnz v11, blk_ret
2964 Jump blk9
2965
2966 blk5: () <-- (blk7,blk9)
2967 Jump blk_ret
2968
2969 blk6: (v20:i32) <-- (blk3)
2970 v21:i64 = Iconst_64 0x54
2971 v22:i64 = UExtend v20, 32->64
2972 v23:i64 = Uload32 module_ctx, 0x10
2973 v24:i64 = Iadd v22, v21
2974 v25:i32 = Icmp lt_u, v23, v24
2975 ExitIfTrue v25, exec_ctx, memory_out_of_bounds
2976 v26:i64 = Load module_ctx, 0x8
2977 v27:i64 = Iadd v26, v22
2978 v28:i32 = Load v27, 0x50
2979 Brnz v28, blk1, v20
2980 Jump blk8
2981
2982 blk7: () <-- (blk8)
2983 Jump blk5
2984
2985 blk8: () <-- (blk6)
2986 Jump blk7
2987
2988 blk9: () <-- (blk4)
2989 Jump blk5
2990 `,
2991 },
2992 } {
2993
2994 tc := tc
2995 t.Run(tc.name, func(t *testing.T) {
2996 // Just in case let's check the test module is valid.
2997 features := tc.features
2998 if features == 0 {
2999 features = api.CoreFeaturesV2
3000 }
3001 err := tc.m.Validate(features)
3002 require.NoError(t, err, "invalid test case module!")
3003
3004 b := ssa.NewBuilder()
3005
3006 offset := wazevoapi.NewModuleContextOffsetData(tc.m, tc.needListener)
3007 fc := NewFrontendCompiler(tc.m, b, &offset, tc.ensureTermination, tc.needListener, false)
3008 typeIndex := tc.m.FunctionSection[tc.targetIndex]
3009 code := &tc.m.CodeSection[tc.targetIndex]
3010 fc.Init(tc.targetIndex, typeIndex, &tc.m.TypeSection[typeIndex], code.LocalTypes, code.Body, tc.needListener, 0)
3011
3012 fc.LowerToSSA()
3013
3014 actual := fc.formatBuilder()
3015 require.Equal(t, tc.exp, actual)
3016
3017 b.RunPasses()
3018 if expAfterOpt := tc.expAfterPasses; expAfterOpt != "" {
3019 actualAfterOpt := fc.formatBuilder()
3020 require.Equal(t, expAfterOpt, actualAfterOpt)
3021 }
3022 })
3023 }
3024 }
3025
3026 func TestSignatureForListener(t *testing.T) {
3027 for _, tc := range []struct {
3028 name string
3029 sig *wasm.FunctionType
3030 before, after *ssa.Signature
3031 }{
3032 {
3033 name: "empty",
3034 sig: &wasm.FunctionType{},
3035 before: &ssa.Signature{Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3036 after: &ssa.Signature{Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3037 },
3038 {
3039 name: "multi",
3040 sig: &wasm.FunctionType{
3041 Params: []wasm.ValueType{wasm.ValueTypeF64, wasm.ValueTypeI32},
3042 Results: []wasm.ValueType{
3043 wasm.ValueTypeI64, wasm.ValueTypeI32, wasm.ValueTypeF32, wasm.ValueTypeF64, wasm.ValueTypeV128,
3044 },
3045 },
3046 before: &ssa.Signature{
3047 Params: []ssa.Type{
3048 ssa.TypeI64, ssa.TypeI32,
3049 ssa.TypeF64, ssa.TypeI32,
3050 },
3051 },
3052 after: &ssa.Signature{
3053 Params: []ssa.Type{
3054 ssa.TypeI64, ssa.TypeI32,
3055 ssa.TypeI64, ssa.TypeI32, ssa.TypeF32, ssa.TypeF64, ssa.TypeV128,
3056 },
3057 },
3058 },
3059 } {
3060 tc := tc
3061 t.Run(tc.name, func(t *testing.T) {
3062 before, after := SignatureForListener(tc.sig)
3063 require.Equal(t, tc.before, before)
3064 require.Equal(t, tc.after, after)
3065 })
3066 }
3067 }
3068
3069 func TestCompiler_declareSignatures(t *testing.T) {
3070 m := &wasm.Module{
3071 TypeSection: []wasm.FunctionType{
3072 {},
3073 {Params: []wasm.ValueType{wasm.ValueTypeI64, wasm.ValueTypeI32}},
3074 {Params: []wasm.ValueType{wasm.ValueTypeF64, wasm.ValueTypeI32}},
3075 {Results: []wasm.ValueType{wasm.ValueTypeI64, wasm.ValueTypeI32}},
3076 },
3077 }
3078
3079 t.Run("listener=false", func(t *testing.T) {
3080 builder := ssa.NewBuilder()
3081 c := &Compiler{m: m, ssaBuilder: builder}
3082 c.declareSignatures(false)
3083
3084 declaredSigs := builder.Signatures()
3085 expected := []*ssa.Signature{
3086 {ID: 0, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}},
3087 {ID: 1, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64, ssa.TypeI32}},
3088 {ID: 2, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeF64, ssa.TypeI32}},
3089 {ID: 3, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3090 {ID: 4, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI32}},
3091 {ID: 5, Params: []ssa.Type{ssa.TypeI64}},
3092 {ID: 6, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3093 {ID: 7, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI64}},
3094 {ID: 8, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64}},
3095 {ID: 9, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3096 {ID: 10, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3097 {ID: 11, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3098 // EH signatures.
3099 {ID: 12, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI64}},
3100 {ID: 13, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}},
3101 {ID: 14, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}},
3102 {ID: 15, Params: []ssa.Type{ssa.TypeI64}},
3103 }
3104
3105 require.Equal(t, len(expected), len(declaredSigs))
3106 for i := 0; i < len(expected); i++ {
3107 require.Equal(t, expected[i].String(), declaredSigs[i].String(), i)
3108 }
3109 })
3110
3111 t.Run("listener=false", func(t *testing.T) {
3112 builder := ssa.NewBuilder()
3113 c := &Compiler{m: m, ssaBuilder: builder}
3114 c.declareSignatures(true)
3115
3116 declaredSigs := builder.Signatures()
3117
3118 expected := []*ssa.Signature{
3119 {ID: 0, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}},
3120 {ID: 1, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64, ssa.TypeI32}},
3121 {ID: 2, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeF64, ssa.TypeI32}},
3122 {ID: 3, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3123 // Before.
3124 {ID: 4, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3125 {ID: 5, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI64, ssa.TypeI32}},
3126 {ID: 6, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeF64, ssa.TypeI32}},
3127 {ID: 7, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3128 // After.
3129 {ID: 8, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3130 {ID: 9, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3131 {ID: 10, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}},
3132 {ID: 11, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI64, ssa.TypeI32}},
3133 // Misc.
3134 {ID: 12, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI32}},
3135 {ID: 13, Params: []ssa.Type{ssa.TypeI64}},
3136 {ID: 14, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3137 {ID: 15, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI64}},
3138 {ID: 16, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64}},
3139 {ID: 17, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3140 {ID: 18, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3141 {ID: 19, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
3142 // EH signatures.
3143 {ID: 20, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI64}},
3144 {ID: 21, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}},
3145 {ID: 22, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64}},
3146 {ID: 23, Params: []ssa.Type{ssa.TypeI64}},
3147 }
3148 require.Equal(t, len(expected), len(declaredSigs))
3149 for i := 0; i < len(declaredSigs); i++ {
3150 require.Equal(t, expected[i].String(), declaredSigs[i].String(), i)
3151 }
3152 })
3153 }
3154
3155 func TestCompiler_recordKnownSafeBound(t *testing.T) {
3156 c := &Compiler{}
3157 c.recordKnownSafeBound(1, 99, 9999)
3158 require.Equal(t, 1, len(c.knownSafeBoundsSet))
3159 require.True(t, c.getKnownSafeBound(1).valid())
3160 require.Equal(t, uint64(99), c.getKnownSafeBound(1).bound)
3161 require.Equal(t, ssa.Value(9999), c.getKnownSafeBound(1).absoluteAddr)
3162
3163 c.recordKnownSafeBound(1, 150, 9999)
3164 require.Equal(t, 1, len(c.knownSafeBoundsSet))
3165 require.Equal(t, uint64(150), c.getKnownSafeBound(1).bound)
3166
3167 c.recordKnownSafeBound(5, 666, 54321)
3168 require.Equal(t, 2, len(c.knownSafeBoundsSet))
3169 require.Equal(t, uint64(666), c.getKnownSafeBound(5).bound)
3170 require.Equal(t, ssa.Value(54321), c.getKnownSafeBound(5).absoluteAddr)
3171 }
3172
3173 func TestCompiler_getKnownSafeBound(t *testing.T) {
3174 c := &Compiler{
3175 knownSafeBounds: []knownSafeBound{
3176 {}, {bound: 2134},
3177 },
3178 }
3179 require.Nil(t, c.getKnownSafeBound(5))
3180 require.Nil(t, c.getKnownSafeBound(12345))
3181 require.False(t, c.getKnownSafeBound(0).valid())
3182 require.True(t, c.getKnownSafeBound(1).valid())
3183 }
3184
3185 func TestCompiler_clearSafeBounds(t *testing.T) {
3186 c := &Compiler{}
3187 c.knownSafeBounds = []knownSafeBound{{bound: 1}, {}, {bound: 2}, {}, {}, {bound: 3}}
3188 c.knownSafeBoundsSet = []ssa.ValueID{0, 2, 5}
3189 c.clearSafeBounds()
3190 require.Equal(t, 0, len(c.knownSafeBoundsSet))
3191 require.Equal(t, []knownSafeBound{{absoluteAddr: ssa.ValueInvalid}, {}, {absoluteAddr: ssa.ValueInvalid}, {}, {}, {absoluteAddr: ssa.ValueInvalid}}, c.knownSafeBounds)
3192 }
3193
3194 func TestCompiler_resetAbsoluteAddressInSafeBounds(t *testing.T) {
3195 c := &Compiler{}
3196 c.knownSafeBounds = []knownSafeBound{
3197 {bound: 1, absoluteAddr: ssa.Value(1)},
3198 {},
3199 {bound: 2, absoluteAddr: ssa.Value(2)},
3200 {},
3201 {},
3202 {bound: 3, absoluteAddr: ssa.Value(3)},
3203 }
3204 c.knownSafeBoundsSet = []ssa.ValueID{0, 2, 5}
3205 c.resetAbsoluteAddressInSafeBounds()
3206 require.Equal(t, 3, len(c.knownSafeBoundsSet))
3207 require.Equal(t, []knownSafeBound{
3208 {bound: 1, absoluteAddr: ssa.ValueInvalid},
3209 {},
3210 {bound: 2, absoluteAddr: ssa.ValueInvalid},
3211 {},
3212 {},
3213 {bound: 3, absoluteAddr: ssa.ValueInvalid},
3214 }, c.knownSafeBounds)
3215 }
3216
3217 func TestKnownSafeBound_valid(t *testing.T) {
3218 k := &knownSafeBound{bound: 10, absoluteAddr: 12345}
3219 require.True(t, k.valid())
3220 k.bound = 0
3221 require.False(t, k.valid())
3222 }
3223
3224 func TestCompiler_finalizeKnownSafeBoundsAtTheEndOoBlock(t *testing.T) {
3225 c := NewFrontendCompiler(&wasm.Module{}, ssa.NewBuilder(), nil, false, false, false)
3226 blk := c.ssaBuilder.AllocateBasicBlock()
3227 require.True(t, len(c.getKnownSafeBoundsAtTheEndOfBlocks(blk.ID()).View()) == 0)
3228 c.ssaBuilder.SetCurrentBlock(blk)
3229 c.knownSafeBoundsSet = []ssa.ValueID{0, 2, 5}
3230 c.knownSafeBounds = []knownSafeBound{
3231 {bound: 1, absoluteAddr: ssa.Value(1)},
3232 {},
3233 {bound: 2, absoluteAddr: ssa.Value(2)},
3234 {},
3235 {},
3236 {bound: 3, absoluteAddr: ssa.Value(3)},
3237 }
3238 c.finalizeKnownSafeBoundsAtTheEndOfBlock(blk.ID())
3239 require.True(t, len(c.knownSafeBoundsSet) == 0)
3240 finalized := c.getKnownSafeBoundsAtTheEndOfBlocks(blk.ID())
3241 require.Equal(t, 3, len(finalized.View()))
3242 }
3243
3244 func TestCompiler_initializeCurrentBlockKnownBounds(t *testing.T) {
3245 t.Run("single (sealed)", func(t *testing.T) {
3246 c := NewFrontendCompiler(&wasm.Module{}, ssa.NewBuilder(), nil, false, false, false)
3247 builder := c.ssaBuilder
3248 child := builder.AllocateBasicBlock()
3249 {
3250 parent := builder.AllocateBasicBlock()
3251 builder.SetCurrentBlock(parent)
3252 c.recordKnownSafeBound(1, 99, 9999)
3253 c.recordKnownSafeBound(2, 150, 9999)
3254 c.recordKnownSafeBound(5, 666, 54321)
3255 builder.AllocateInstruction().AsJump(ssa.ValuesNil, child).Insert(builder)
3256 c.finalizeKnownSafeBoundsAtTheEndOfBlock(parent.ID())
3257 }
3258
3259 // Seal the child: the absolute addresses will be propagated.
3260 builder.Seal(child)
3261 builder.SetCurrentBlock(child)
3262 c.initializeCurrentBlockKnownBounds()
3263 kb := c.getKnownSafeBound(1)
3264 require.True(t, kb.valid())
3265 require.Equal(t, uint64(99), kb.bound)
3266 require.Equal(t, ssa.Value(9999), kb.absoluteAddr)
3267 kb = c.getKnownSafeBound(2)
3268 require.True(t, kb.valid())
3269 require.Equal(t, uint64(150), kb.bound)
3270 require.Equal(t, ssa.Value(9999), kb.absoluteAddr)
3271 kb = c.getKnownSafeBound(5)
3272 require.True(t, kb.valid())
3273 require.Equal(t, uint64(666), kb.bound)
3274 require.Equal(t, ssa.Value(54321), kb.absoluteAddr)
3275 })
3276 t.Run("single (unsealed)", func(t *testing.T) {
3277 c := NewFrontendCompiler(&wasm.Module{}, ssa.NewBuilder(), nil, false, false, false)
3278 builder := c.ssaBuilder
3279 child := builder.AllocateBasicBlock()
3280 {
3281 parent := builder.AllocateBasicBlock()
3282 builder.SetCurrentBlock(parent)
3283 c.recordKnownSafeBound(1, 99, 9999)
3284 c.recordKnownSafeBound(2, 150, 9999)
3285 c.recordKnownSafeBound(5, 666, 54321)
3286 builder.AllocateInstruction().AsJump(ssa.ValuesNil, child).Insert(builder)
3287 c.finalizeKnownSafeBoundsAtTheEndOfBlock(parent.ID())
3288 }
3289
3290 // Do not seal the child: the absolute addresses will be recomputed.
3291 builder.SetCurrentBlock(child)
3292 c.initializeCurrentBlockKnownBounds()
3293 kb := c.getKnownSafeBound(1)
3294 require.True(t, kb.valid())
3295 require.Equal(t, uint64(99), kb.bound)
3296 require.NotEqual(t, ssa.Value(9999), kb.absoluteAddr)
3297 kb = c.getKnownSafeBound(2)
3298 require.True(t, kb.valid())
3299 require.Equal(t, uint64(150), kb.bound)
3300 require.NotEqual(t, ssa.Value(9999), kb.absoluteAddr)
3301 kb = c.getKnownSafeBound(5)
3302 require.True(t, kb.valid())
3303 require.Equal(t, uint64(666), kb.bound)
3304 require.NotEqual(t, ssa.Value(54321), kb.absoluteAddr)
3305 })
3306 t.Run("multiple predecessors", func(t *testing.T) {
3307 c := NewFrontendCompiler(&wasm.Module{}, ssa.NewBuilder(), nil, false, false, false)
3308 builder := c.ssaBuilder
3309 child := builder.AllocateBasicBlock()
3310 {
3311 p1 := builder.AllocateBasicBlock()
3312 builder.SetCurrentBlock(p1)
3313 c.recordKnownSafeBound(1, 99, 9999)
3314 c.recordKnownSafeBound(2, 150, 9999)
3315 c.recordKnownSafeBound(5, 666, 54321)
3316 c.recordKnownSafeBound(592131, 666, 54321)
3317 builder.AllocateInstruction().AsJump(ssa.ValuesNil, child).Insert(builder)
3318 c.finalizeKnownSafeBoundsAtTheEndOfBlock(p1.ID())
3319 }
3320 {
3321 p2 := builder.AllocateBasicBlock()
3322 builder.SetCurrentBlock(p2)
3323 c.recordKnownSafeBound(1, 100, 999419)
3324 c.recordKnownSafeBound(2, 4, 9991239)
3325 c.recordKnownSafeBound(5, 555, 54341221)
3326 c.recordKnownSafeBound(6, 666, 54321)
3327 c.recordKnownSafeBound(7, 666, 54321)
3328 builder.AllocateInstruction().AsJump(ssa.ValuesNil, child).Insert(builder)
3329 c.finalizeKnownSafeBoundsAtTheEndOfBlock(p2.ID())
3330 }
3331 {
3332 p3 := builder.AllocateBasicBlock()
3333 builder.SetCurrentBlock(p3)
3334 c.recordKnownSafeBound(1, 1, 999419)
3335 c.recordKnownSafeBound(2, 11111, 9991239)
3336 c.recordKnownSafeBound(5, 5551231, 54341221)
3337 c.recordKnownSafeBound(7, 666, 54321)
3338 c.recordKnownSafeBound(60, 666, 54321)
3339 builder.AllocateInstruction().AsJump(ssa.ValuesNil, child).Insert(builder)
3340 c.finalizeKnownSafeBoundsAtTheEndOfBlock(p3.ID())
3341 }
3342
3343 builder.SetCurrentBlock(child)
3344 c.initializeCurrentBlockKnownBounds()
3345 for _, tc := range []struct {
3346 id ssa.ValueID
3347 valid bool
3348 bound uint64
3349 }{
3350 {id: 0, valid: false},
3351 {id: 1, valid: true, bound: 1},
3352 {id: 2, valid: true, bound: 4},
3353 {id: 3, valid: false},
3354 {id: 4, valid: false},
3355 {id: 5, valid: true, bound: 555},
3356 {id: 6, valid: false},
3357 {id: 7, valid: false},
3358 {id: 60, valid: false},
3359 {id: 592131, valid: false},
3360 } {
3361 t.Run(fmt.Sprintf("id=%d", tc.id), func(t *testing.T) {
3362 kb := c.getKnownSafeBound(tc.id)
3363 require.Equal(t, tc.valid, kb.valid())
3364 if kb.valid() {
3365 require.Equal(t, tc.bound, kb.bound)
3366 require.Equal(t, ssa.ValueInvalid, kb.absoluteAddr)
3367 }
3368 })
3369 }
3370 })
3371 }