summaryrefslogtreecommitdiff
path: root/test/lit/passes/monomorphize-consts.wast
blob: 1d18f6dab521f9d18a7a0b3657ead6176d3ac26e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; As in monomorphize-types.wast, test in both "always" mode, which always
;; monomorphizes, and in "careful" mode which does it only when it appears to
;; actually help, and use a minimum benefit of 0 to make it easy to write
;; small testcases.

;; RUN: foreach %s %t wasm-opt --monomorphize-always                                -all -S -o - | filecheck %s --check-prefix ALWAYS
;; RUN: foreach %s %t wasm-opt --monomorphize --pass-arg=monomorphize-min-benefit@0 -all -S -o - | filecheck %s --check-prefix CAREFUL

(module
  ;; Test that constants are monomorphized.

  ;; ALWAYS:      (type $0 (func (param i32)))

  ;; ALWAYS:      (type $1 (func (param i32 i32 funcref stringref)))

  ;; ALWAYS:      (type $2 (func (param i32) (result i32)))

  ;; ALWAYS:      (type $3 (func (result i32)))

  ;; ALWAYS:      (type $4 (func (param i32 i32)))

  ;; ALWAYS:      (import "a" "b" (func $import (type $0) (param i32)))
  ;; CAREFUL:      (type $0 (func (param i32)))

  ;; CAREFUL:      (type $1 (func (param i32 i32 funcref stringref)))

  ;; CAREFUL:      (type $2 (func (param i32) (result i32)))

  ;; CAREFUL:      (type $3 (func (result i32)))

  ;; CAREFUL:      (type $4 (func (param i32 i32)))

  ;; CAREFUL:      (import "a" "b" (func $import (type $0) (param i32)))
  (import "a" "b" (func $import (param i32)))

  ;; ALWAYS:      (elem declare func $calls)

  ;; ALWAYS:      (func $calls (type $4) (param $x i32) (param $y i32)
  ;; ALWAYS-NEXT:  (call $target_9
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (call $target_9
  ;; ALWAYS-NEXT:   (local.get $y)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (call $target_10
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (elem declare func $calls)

  ;; CAREFUL:      (func $calls (type $4) (param $x i32) (param $y i32)
  ;; CAREFUL-NEXT:  (call $target_9
  ;; CAREFUL-NEXT:   (local.get $x)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT:  (call $target_9
  ;; CAREFUL-NEXT:   (local.get $y)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT:  (call $target_10
  ;; CAREFUL-NEXT:   (local.get $x)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT: )
  (func $calls (param $x i32) (param $y i32)
    ;; All but the local.get are constants that can be handled.
    (call $target
      (i32.const 1)
      (local.get $x)
      (ref.func $calls)
      (string.const "foo")
    )

    ;; This has the same effective call context, as the constants are identical,
    ;; and the non-constant is different, which we keep as a variable anyhow.
    ;; This will call the same refined function as the previous call.
    (call $target
      (i32.const 1)
      (local.get $y) ;; this changed
      (ref.func $calls)
      (string.const "foo")
    )

    ;; This has a different call context: one constant is different, so we'll
    ;; call a different refined function.
    (call $target
      (i32.const 3)  ;; this changed
      (local.get $x)
      (ref.func $calls)
      (string.const "foo")
    )
  )

  ;; ALWAYS:      (func $more-calls (type $0) (param $x i32)
  ;; ALWAYS-NEXT:  (call $target_9
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (call $other-target_11
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (call $work_12
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (func $more-calls (type $0) (param $x i32)
  ;; CAREFUL-NEXT:  (call $target_9
  ;; CAREFUL-NEXT:   (local.get $x)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT:  (call $other-target_11
  ;; CAREFUL-NEXT:   (local.get $x)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT:  (call $work_12
  ;; CAREFUL-NEXT:   (local.get $x)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT: )
  (func $more-calls (param $x i32)
    ;; Identical to the first call in the previous function (except for the non-
    ;; constant second param, which is ok to be different). We should call the
    ;; same refined function before, even though we are in a different
    ;; function here.
    (call $target
      (i32.const 1)
      (local.get $x)
      (ref.func $calls)
      (string.const "foo")
    )

    ;; Call a different function but with the exact same params. This tests that
    ;; we handle identical contexts but with different functions. This will call
    ;; a different refined function than before
    (call $other-target
      (i32.const 1)
      (local.get $x)
      (ref.func $calls)
      (string.const "foo")
    )

    ;; Call yet another different function with the same context, this time the
    ;; function is worth optimizing even in CAREFUL mode, as the constants
    ;; unlock actual work.
    (call $work
      (i32.const 3)
      (local.get $x)
      (ref.func $calls)
      (string.const "foo")
    )
  )

  ;; ALWAYS:      (func $fail (type $0) (param $x i32)
  ;; ALWAYS-NEXT:  (call $target
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:   (block (result funcref)
  ;; ALWAYS-NEXT:    (ref.func $calls)
  ;; ALWAYS-NEXT:   )
  ;; ALWAYS-NEXT:   (block (result stringref)
  ;; ALWAYS-NEXT:    (string.const "foo")
  ;; ALWAYS-NEXT:   )
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (func $fail (type $0) (param $x i32)
  ;; CAREFUL-NEXT:  (call $target
  ;; CAREFUL-NEXT:   (local.get $x)
  ;; CAREFUL-NEXT:   (local.get $x)
  ;; CAREFUL-NEXT:   (block (result funcref)
  ;; CAREFUL-NEXT:    (ref.func $calls)
  ;; CAREFUL-NEXT:   )
  ;; CAREFUL-NEXT:   (block (result stringref)
  ;; CAREFUL-NEXT:    (string.const "foo")
  ;; CAREFUL-NEXT:   )
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT: )
  (func $fail (param $x i32)
    ;; No operand is a constant here, so we do nothing.
    (call $target
      (local.get $x)
      (local.get $x)
      (block (result funcref)
        (ref.func $calls)
      )
      (block (result stringref)
        (string.const "foo")
      )
    )
  )

  ;; ALWAYS:      (func $mutual-recursion-a (type $2) (param $x i32) (result i32)
  ;; ALWAYS-NEXT:  (if (result i32)
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:   (then
  ;; ALWAYS-NEXT:    (i32.add
  ;; ALWAYS-NEXT:     (call $mutual-recursion-b
  ;; ALWAYS-NEXT:      (local.get $x)
  ;; ALWAYS-NEXT:     )
  ;; ALWAYS-NEXT:     (call $mutual-recursion-b_13)
  ;; ALWAYS-NEXT:    )
  ;; ALWAYS-NEXT:   )
  ;; ALWAYS-NEXT:   (else
  ;; ALWAYS-NEXT:    (i32.const 42)
  ;; ALWAYS-NEXT:   )
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (func $mutual-recursion-a (type $2) (param $0 i32) (result i32)
  ;; CAREFUL-NEXT:  (if (result i32)
  ;; CAREFUL-NEXT:   (local.get $0)
  ;; CAREFUL-NEXT:   (then
  ;; CAREFUL-NEXT:    (i32.add
  ;; CAREFUL-NEXT:     (call $mutual-recursion-b
  ;; CAREFUL-NEXT:      (local.get $0)
  ;; CAREFUL-NEXT:     )
  ;; CAREFUL-NEXT:     (call $mutual-recursion-b_13)
  ;; CAREFUL-NEXT:    )
  ;; CAREFUL-NEXT:   )
  ;; CAREFUL-NEXT:   (else
  ;; CAREFUL-NEXT:    (i32.const 42)
  ;; CAREFUL-NEXT:   )
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT: )
  (func $mutual-recursion-a (param $x i32) (result i32)
    ;; We ignore direct recursion (see test in other monomorphize-types) but we
    ;; do handle mutual recursion normally. This also tests another function
    ;; that can be optimized, with a different signature than before.
    (if (result i32)
      (local.get $x)
      (then
        (i32.add
          ;; This call cannot be monomorphized.
          (call $mutual-recursion-b
            (local.get $x)
          )
          ;; The constant here allows us to monomorphize (in ALWAYS; to see the
          ;; benefit in CAREFUL, we need additional cycles, which we do not do
          ;; yet).
          (call $mutual-recursion-b
            (i32.const 0)
          )
        )
      )
      (else
        (i32.const 42)
      )
    )
  )

  ;; ALWAYS:      (func $mutual-recursion-b (type $2) (param $x i32) (result i32)
  ;; ALWAYS-NEXT:  (i32.add
  ;; ALWAYS-NEXT:   (call $mutual-recursion-a_14)
  ;; ALWAYS-NEXT:   (i32.const 1337)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (func $mutual-recursion-b (type $2) (param $0 i32) (result i32)
  ;; CAREFUL-NEXT:  (i32.add
  ;; CAREFUL-NEXT:   (call $mutual-recursion-a_14)
  ;; CAREFUL-NEXT:   (i32.const 1337)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT: )
  (func $mutual-recursion-b (param $x i32) (result i32)
    (i32.add
      ;; This can be optimized (as the constant 0 allows work to happen).
      (call $mutual-recursion-a
        (i32.const 0)
      )
      (i32.const 1337)
    )
  )

  ;; ALWAYS:      (func $target (type $1) (param $x i32) (param $y i32) (param $func funcref) (param $str stringref)
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $y)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $func)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $str)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (func $target (type $1) (param $0 i32) (param $1 i32) (param $2 funcref) (param $3 stringref)
  ;; CAREFUL-NEXT:  (nop)
  ;; CAREFUL-NEXT: )
  (func $target (param $x i32) (param $y i32) (param $func funcref) (param $str stringref)
    (drop
      (local.get $x)
    )
    (drop
      (local.get $y)
    )
    (drop
      (local.get $func)
    )
    (drop
      (local.get $str)
    )
  )

  ;; ALWAYS:      (func $other-target (type $1) (param $x i32) (param $y i32) (param $func funcref) (param $str stringref)
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $func)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $str)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $x)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (drop
  ;; ALWAYS-NEXT:   (local.get $y)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (func $other-target (type $1) (param $0 i32) (param $1 i32) (param $2 funcref) (param $3 stringref)
  ;; CAREFUL-NEXT:  (nop)
  ;; CAREFUL-NEXT: )
  (func $other-target (param $x i32) (param $y i32) (param $func funcref) (param $str stringref)
    ;; Similar to $target, but the inside is a little reordered.
    (drop
      (local.get $func)
    )
    (drop
      (local.get $str)
    )
    (drop
      (local.get $x)
    )
    (drop
      (local.get $y)
    )
  )

  ;; ALWAYS:      (func $work (type $1) (param $x i32) (param $y i32) (param $func funcref) (param $str stringref)
  ;; ALWAYS-NEXT:  (call $import
  ;; ALWAYS-NEXT:   (i32.add
  ;; ALWAYS-NEXT:    (local.get $x)
  ;; ALWAYS-NEXT:    (i32.add
  ;; ALWAYS-NEXT:     (ref.is_null
  ;; ALWAYS-NEXT:      (local.get $func)
  ;; ALWAYS-NEXT:     )
  ;; ALWAYS-NEXT:     (ref.is_null
  ;; ALWAYS-NEXT:      (local.get $str)
  ;; ALWAYS-NEXT:     )
  ;; ALWAYS-NEXT:    )
  ;; ALWAYS-NEXT:   )
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT:  (call $import
  ;; ALWAYS-NEXT:   (local.get $y)
  ;; ALWAYS-NEXT:  )
  ;; ALWAYS-NEXT: )
  ;; CAREFUL:      (func $work (type $1) (param $0 i32) (param $1 i32) (param $2 funcref) (param $3 stringref)
  ;; CAREFUL-NEXT:  (call $import
  ;; CAREFUL-NEXT:   (i32.add
  ;; CAREFUL-NEXT:    (local.get $0)
  ;; CAREFUL-NEXT:    (i32.add
  ;; CAREFUL-NEXT:     (ref.is_null
  ;; CAREFUL-NEXT:      (local.get $2)
  ;; CAREFUL-NEXT:     )
  ;; CAREFUL-NEXT:     (ref.is_null
  ;; CAREFUL-NEXT:      (local.get $3)
  ;; CAREFUL-NEXT:     )
  ;; CAREFUL-NEXT:    )
  ;; CAREFUL-NEXT:   )
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT:  (call $import
  ;; CAREFUL-NEXT:   (local.get $1)
  ;; CAREFUL-NEXT:  )
  ;; CAREFUL-NEXT: )
  (func $work (param $x i32) (param $y i32) (param $func funcref) (param $str stringref)
    ;; Similar to $target, but the inside has actual work that can be optimized
    ;; away if we have constants here. Specifically the refs are not null and
    ;; $x is 3, so we sent 3 to the import here.
    (call $import
      (i32.add
        (local.get $x)
        (i32.add
          (ref.is_null
            (local.get $func)
          )
          (ref.is_null
            (local.get $str)
          )
        )
      )
    )
    ;; This parameter is unknown, so we can't do any optimization in this part.
    (call $import
      (local.get $y)
    )
  )
)
;; ALWAYS:      (func $target_9 (type $0) (param $0 i32)
;; ALWAYS-NEXT:  (local $x i32)
;; ALWAYS-NEXT:  (local $y i32)
;; ALWAYS-NEXT:  (local $func funcref)
;; ALWAYS-NEXT:  (local $str stringref)
;; ALWAYS-NEXT:  (local.set $x
;; ALWAYS-NEXT:   (i32.const 1)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $y
;; ALWAYS-NEXT:   (local.get $0)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $func
;; ALWAYS-NEXT:   (ref.func $calls)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $str
;; ALWAYS-NEXT:   (string.const "foo")
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (block
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $x)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $y)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $func)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $str)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT: )

;; ALWAYS:      (func $target_10 (type $0) (param $0 i32)
;; ALWAYS-NEXT:  (local $x i32)
;; ALWAYS-NEXT:  (local $y i32)
;; ALWAYS-NEXT:  (local $func funcref)
;; ALWAYS-NEXT:  (local $str stringref)
;; ALWAYS-NEXT:  (local.set $x
;; ALWAYS-NEXT:   (i32.const 3)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $y
;; ALWAYS-NEXT:   (local.get $0)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $func
;; ALWAYS-NEXT:   (ref.func $calls)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $str
;; ALWAYS-NEXT:   (string.const "foo")
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (block
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $x)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $y)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $func)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $str)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT: )

;; ALWAYS:      (func $other-target_11 (type $0) (param $0 i32)
;; ALWAYS-NEXT:  (local $x i32)
;; ALWAYS-NEXT:  (local $y i32)
;; ALWAYS-NEXT:  (local $func funcref)
;; ALWAYS-NEXT:  (local $str stringref)
;; ALWAYS-NEXT:  (local.set $x
;; ALWAYS-NEXT:   (i32.const 1)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $y
;; ALWAYS-NEXT:   (local.get $0)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $func
;; ALWAYS-NEXT:   (ref.func $calls)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $str
;; ALWAYS-NEXT:   (string.const "foo")
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (block
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $func)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $str)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $x)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (drop
;; ALWAYS-NEXT:    (local.get $y)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT: )

;; ALWAYS:      (func $work_12 (type $0) (param $0 i32)
;; ALWAYS-NEXT:  (local $x i32)
;; ALWAYS-NEXT:  (local $y i32)
;; ALWAYS-NEXT:  (local $func funcref)
;; ALWAYS-NEXT:  (local $str stringref)
;; ALWAYS-NEXT:  (local.set $x
;; ALWAYS-NEXT:   (i32.const 3)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $y
;; ALWAYS-NEXT:   (local.get $0)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $func
;; ALWAYS-NEXT:   (ref.func $calls)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (local.set $str
;; ALWAYS-NEXT:   (string.const "foo")
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (block
;; ALWAYS-NEXT:   (call $import
;; ALWAYS-NEXT:    (i32.add
;; ALWAYS-NEXT:     (local.get $x)
;; ALWAYS-NEXT:     (i32.add
;; ALWAYS-NEXT:      (ref.is_null
;; ALWAYS-NEXT:       (local.get $func)
;; ALWAYS-NEXT:      )
;; ALWAYS-NEXT:      (ref.is_null
;; ALWAYS-NEXT:       (local.get $str)
;; ALWAYS-NEXT:      )
;; ALWAYS-NEXT:     )
;; ALWAYS-NEXT:    )
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (call $import
;; ALWAYS-NEXT:    (local.get $y)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT: )

;; ALWAYS:      (func $mutual-recursion-b_13 (type $3) (result i32)
;; ALWAYS-NEXT:  (local $x i32)
;; ALWAYS-NEXT:  (local.set $x
;; ALWAYS-NEXT:   (i32.const 0)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (i32.add
;; ALWAYS-NEXT:   (call $mutual-recursion-a
;; ALWAYS-NEXT:    (i32.const 0)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (i32.const 1337)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT: )

;; ALWAYS:      (func $mutual-recursion-a_14 (type $3) (result i32)
;; ALWAYS-NEXT:  (local $x i32)
;; ALWAYS-NEXT:  (local.set $x
;; ALWAYS-NEXT:   (i32.const 0)
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT:  (if (result i32)
;; ALWAYS-NEXT:   (local.get $x)
;; ALWAYS-NEXT:   (then
;; ALWAYS-NEXT:    (i32.add
;; ALWAYS-NEXT:     (call $mutual-recursion-b
;; ALWAYS-NEXT:      (local.get $x)
;; ALWAYS-NEXT:     )
;; ALWAYS-NEXT:     (call $mutual-recursion-b_13)
;; ALWAYS-NEXT:    )
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:   (else
;; ALWAYS-NEXT:    (i32.const 42)
;; ALWAYS-NEXT:   )
;; ALWAYS-NEXT:  )
;; ALWAYS-NEXT: )

;; CAREFUL:      (func $target_9 (type $0) (param $0 i32)
;; CAREFUL-NEXT:  (nop)
;; CAREFUL-NEXT: )

;; CAREFUL:      (func $target_10 (type $0) (param $0 i32)
;; CAREFUL-NEXT:  (nop)
;; CAREFUL-NEXT: )

;; CAREFUL:      (func $other-target_11 (type $0) (param $0 i32)
;; CAREFUL-NEXT:  (nop)
;; CAREFUL-NEXT: )

;; CAREFUL:      (func $work_12 (type $0) (param $0 i32)
;; CAREFUL-NEXT:  (call $import
;; CAREFUL-NEXT:   (i32.const 3)
;; CAREFUL-NEXT:  )
;; CAREFUL-NEXT:  (call $import
;; CAREFUL-NEXT:   (local.get $0)
;; CAREFUL-NEXT:  )
;; CAREFUL-NEXT: )

;; CAREFUL:      (func $mutual-recursion-b_13 (type $3) (result i32)
;; CAREFUL-NEXT:  (i32.add
;; CAREFUL-NEXT:   (call $mutual-recursion-a
;; CAREFUL-NEXT:    (i32.const 0)
;; CAREFUL-NEXT:   )
;; CAREFUL-NEXT:   (i32.const 1337)
;; CAREFUL-NEXT:  )
;; CAREFUL-NEXT: )

;; CAREFUL:      (func $mutual-recursion-a_14 (type $3) (result i32)
;; CAREFUL-NEXT:  (i32.const 42)
;; CAREFUL-NEXT: )