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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
|
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; Similar to reorder-globals, but this runs the "real" version, without
;; "-always". That is, this tests the production code. The downside is we need
;; 128+ globals to see any changes here, so we keep most testing in the other
;; file.
;; RUN: foreach %s %t wasm-opt -all --reorder-globals -S -o - | filecheck %s
;; A situation where the simple greedy sort fails to be optimal. We have 129
;; globals, enough for the LEB size to grow by 1 for the last. One global,
;; |other|, is independent of the rest. The second is in a chain with all the
;; others:
;;
;; global1 <- global2 <- .. <- global128
;;
;; other has a higher count than global1, so if we are greedy we pick it. But
;; global128 has the highest count by far, so it is actually worth emitting the
;; entire chain first, and only then other, which is the original order.
(module
;; CHECK: (global $global1 i32 (i32.const 1))
(global $global1 i32 (i32.const 1))
;; CHECK: (global $global2 i32 (global.get $global1))
(global $global2 i32 (global.get $global1))
;; CHECK: (global $global3 i32 (global.get $global2))
(global $global3 i32 (global.get $global2))
;; CHECK: (global $global4 i32 (global.get $global3))
(global $global4 i32 (global.get $global3))
;; CHECK: (global $global5 i32 (global.get $global4))
(global $global5 i32 (global.get $global4))
;; CHECK: (global $global6 i32 (global.get $global5))
(global $global6 i32 (global.get $global5))
;; CHECK: (global $global7 i32 (global.get $global6))
(global $global7 i32 (global.get $global6))
;; CHECK: (global $global8 i32 (global.get $global7))
(global $global8 i32 (global.get $global7))
;; CHECK: (global $global9 i32 (global.get $global8))
(global $global9 i32 (global.get $global8))
;; CHECK: (global $global10 i32 (global.get $global9))
(global $global10 i32 (global.get $global9))
;; CHECK: (global $global11 i32 (global.get $global10))
(global $global11 i32 (global.get $global10))
;; CHECK: (global $global12 i32 (global.get $global11))
(global $global12 i32 (global.get $global11))
;; CHECK: (global $global13 i32 (global.get $global12))
(global $global13 i32 (global.get $global12))
;; CHECK: (global $global14 i32 (global.get $global13))
(global $global14 i32 (global.get $global13))
;; CHECK: (global $global15 i32 (global.get $global14))
(global $global15 i32 (global.get $global14))
;; CHECK: (global $global16 i32 (global.get $global15))
(global $global16 i32 (global.get $global15))
;; CHECK: (global $global17 i32 (global.get $global16))
(global $global17 i32 (global.get $global16))
;; CHECK: (global $global18 i32 (global.get $global17))
(global $global18 i32 (global.get $global17))
;; CHECK: (global $global19 i32 (global.get $global18))
(global $global19 i32 (global.get $global18))
;; CHECK: (global $global20 i32 (global.get $global19))
(global $global20 i32 (global.get $global19))
;; CHECK: (global $global21 i32 (global.get $global20))
(global $global21 i32 (global.get $global20))
;; CHECK: (global $global22 i32 (global.get $global21))
(global $global22 i32 (global.get $global21))
;; CHECK: (global $global23 i32 (global.get $global22))
(global $global23 i32 (global.get $global22))
;; CHECK: (global $global24 i32 (global.get $global23))
(global $global24 i32 (global.get $global23))
;; CHECK: (global $global25 i32 (global.get $global24))
(global $global25 i32 (global.get $global24))
;; CHECK: (global $global26 i32 (global.get $global25))
(global $global26 i32 (global.get $global25))
;; CHECK: (global $global27 i32 (global.get $global26))
(global $global27 i32 (global.get $global26))
;; CHECK: (global $global28 i32 (global.get $global27))
(global $global28 i32 (global.get $global27))
;; CHECK: (global $global29 i32 (global.get $global28))
(global $global29 i32 (global.get $global28))
;; CHECK: (global $global30 i32 (global.get $global29))
(global $global30 i32 (global.get $global29))
;; CHECK: (global $global31 i32 (global.get $global30))
(global $global31 i32 (global.get $global30))
;; CHECK: (global $global32 i32 (global.get $global31))
(global $global32 i32 (global.get $global31))
;; CHECK: (global $global33 i32 (global.get $global32))
(global $global33 i32 (global.get $global32))
;; CHECK: (global $global34 i32 (global.get $global33))
(global $global34 i32 (global.get $global33))
;; CHECK: (global $global35 i32 (global.get $global34))
(global $global35 i32 (global.get $global34))
;; CHECK: (global $global36 i32 (global.get $global35))
(global $global36 i32 (global.get $global35))
;; CHECK: (global $global37 i32 (global.get $global36))
(global $global37 i32 (global.get $global36))
;; CHECK: (global $global38 i32 (global.get $global37))
(global $global38 i32 (global.get $global37))
;; CHECK: (global $global39 i32 (global.get $global38))
(global $global39 i32 (global.get $global38))
;; CHECK: (global $global40 i32 (global.get $global39))
(global $global40 i32 (global.get $global39))
;; CHECK: (global $global41 i32 (global.get $global40))
(global $global41 i32 (global.get $global40))
;; CHECK: (global $global42 i32 (global.get $global41))
(global $global42 i32 (global.get $global41))
;; CHECK: (global $global43 i32 (global.get $global42))
(global $global43 i32 (global.get $global42))
;; CHECK: (global $global44 i32 (global.get $global43))
(global $global44 i32 (global.get $global43))
;; CHECK: (global $global45 i32 (global.get $global44))
(global $global45 i32 (global.get $global44))
;; CHECK: (global $global46 i32 (global.get $global45))
(global $global46 i32 (global.get $global45))
;; CHECK: (global $global47 i32 (global.get $global46))
(global $global47 i32 (global.get $global46))
;; CHECK: (global $global48 i32 (global.get $global47))
(global $global48 i32 (global.get $global47))
;; CHECK: (global $global49 i32 (global.get $global48))
(global $global49 i32 (global.get $global48))
;; CHECK: (global $global50 i32 (global.get $global49))
(global $global50 i32 (global.get $global49))
;; CHECK: (global $global51 i32 (global.get $global50))
(global $global51 i32 (global.get $global50))
;; CHECK: (global $global52 i32 (global.get $global51))
(global $global52 i32 (global.get $global51))
;; CHECK: (global $global53 i32 (global.get $global52))
(global $global53 i32 (global.get $global52))
;; CHECK: (global $global54 i32 (global.get $global53))
(global $global54 i32 (global.get $global53))
;; CHECK: (global $global55 i32 (global.get $global54))
(global $global55 i32 (global.get $global54))
;; CHECK: (global $global56 i32 (global.get $global55))
(global $global56 i32 (global.get $global55))
;; CHECK: (global $global57 i32 (global.get $global56))
(global $global57 i32 (global.get $global56))
;; CHECK: (global $global58 i32 (global.get $global57))
(global $global58 i32 (global.get $global57))
;; CHECK: (global $global59 i32 (global.get $global58))
(global $global59 i32 (global.get $global58))
;; CHECK: (global $global60 i32 (global.get $global59))
(global $global60 i32 (global.get $global59))
;; CHECK: (global $global61 i32 (global.get $global60))
(global $global61 i32 (global.get $global60))
;; CHECK: (global $global62 i32 (global.get $global61))
(global $global62 i32 (global.get $global61))
;; CHECK: (global $global63 i32 (global.get $global62))
(global $global63 i32 (global.get $global62))
;; CHECK: (global $global64 i32 (global.get $global63))
(global $global64 i32 (global.get $global63))
;; CHECK: (global $global65 i32 (global.get $global64))
(global $global65 i32 (global.get $global64))
;; CHECK: (global $global66 i32 (global.get $global65))
(global $global66 i32 (global.get $global65))
;; CHECK: (global $global67 i32 (global.get $global66))
(global $global67 i32 (global.get $global66))
;; CHECK: (global $global68 i32 (global.get $global67))
(global $global68 i32 (global.get $global67))
;; CHECK: (global $global69 i32 (global.get $global68))
(global $global69 i32 (global.get $global68))
;; CHECK: (global $global70 i32 (global.get $global69))
(global $global70 i32 (global.get $global69))
;; CHECK: (global $global71 i32 (global.get $global70))
(global $global71 i32 (global.get $global70))
;; CHECK: (global $global72 i32 (global.get $global71))
(global $global72 i32 (global.get $global71))
;; CHECK: (global $global73 i32 (global.get $global72))
(global $global73 i32 (global.get $global72))
;; CHECK: (global $global74 i32 (global.get $global73))
(global $global74 i32 (global.get $global73))
;; CHECK: (global $global75 i32 (global.get $global74))
(global $global75 i32 (global.get $global74))
;; CHECK: (global $global76 i32 (global.get $global75))
(global $global76 i32 (global.get $global75))
;; CHECK: (global $global77 i32 (global.get $global76))
(global $global77 i32 (global.get $global76))
;; CHECK: (global $global78 i32 (global.get $global77))
(global $global78 i32 (global.get $global77))
;; CHECK: (global $global79 i32 (global.get $global78))
(global $global79 i32 (global.get $global78))
;; CHECK: (global $global80 i32 (global.get $global79))
(global $global80 i32 (global.get $global79))
;; CHECK: (global $global81 i32 (global.get $global80))
(global $global81 i32 (global.get $global80))
;; CHECK: (global $global82 i32 (global.get $global81))
(global $global82 i32 (global.get $global81))
;; CHECK: (global $global83 i32 (global.get $global82))
(global $global83 i32 (global.get $global82))
;; CHECK: (global $global84 i32 (global.get $global83))
(global $global84 i32 (global.get $global83))
;; CHECK: (global $global85 i32 (global.get $global84))
(global $global85 i32 (global.get $global84))
;; CHECK: (global $global86 i32 (global.get $global85))
(global $global86 i32 (global.get $global85))
;; CHECK: (global $global87 i32 (global.get $global86))
(global $global87 i32 (global.get $global86))
;; CHECK: (global $global88 i32 (global.get $global87))
(global $global88 i32 (global.get $global87))
;; CHECK: (global $global89 i32 (global.get $global88))
(global $global89 i32 (global.get $global88))
;; CHECK: (global $global90 i32 (global.get $global89))
(global $global90 i32 (global.get $global89))
;; CHECK: (global $global91 i32 (global.get $global90))
(global $global91 i32 (global.get $global90))
;; CHECK: (global $global92 i32 (global.get $global91))
(global $global92 i32 (global.get $global91))
;; CHECK: (global $global93 i32 (global.get $global92))
(global $global93 i32 (global.get $global92))
;; CHECK: (global $global94 i32 (global.get $global93))
(global $global94 i32 (global.get $global93))
;; CHECK: (global $global95 i32 (global.get $global94))
(global $global95 i32 (global.get $global94))
;; CHECK: (global $global96 i32 (global.get $global95))
(global $global96 i32 (global.get $global95))
;; CHECK: (global $global97 i32 (global.get $global96))
(global $global97 i32 (global.get $global96))
;; CHECK: (global $global98 i32 (global.get $global97))
(global $global98 i32 (global.get $global97))
;; CHECK: (global $global99 i32 (global.get $global98))
(global $global99 i32 (global.get $global98))
;; CHECK: (global $global100 i32 (global.get $global99))
(global $global100 i32 (global.get $global99))
;; CHECK: (global $global101 i32 (global.get $global100))
(global $global101 i32 (global.get $global100))
;; CHECK: (global $global102 i32 (global.get $global101))
(global $global102 i32 (global.get $global101))
;; CHECK: (global $global103 i32 (global.get $global102))
(global $global103 i32 (global.get $global102))
;; CHECK: (global $global104 i32 (global.get $global103))
(global $global104 i32 (global.get $global103))
;; CHECK: (global $global105 i32 (global.get $global104))
(global $global105 i32 (global.get $global104))
;; CHECK: (global $global106 i32 (global.get $global105))
(global $global106 i32 (global.get $global105))
;; CHECK: (global $global107 i32 (global.get $global106))
(global $global107 i32 (global.get $global106))
;; CHECK: (global $global108 i32 (global.get $global107))
(global $global108 i32 (global.get $global107))
;; CHECK: (global $global109 i32 (global.get $global108))
(global $global109 i32 (global.get $global108))
;; CHECK: (global $global110 i32 (global.get $global109))
(global $global110 i32 (global.get $global109))
;; CHECK: (global $global111 i32 (global.get $global110))
(global $global111 i32 (global.get $global110))
;; CHECK: (global $global112 i32 (global.get $global111))
(global $global112 i32 (global.get $global111))
;; CHECK: (global $global113 i32 (global.get $global112))
(global $global113 i32 (global.get $global112))
;; CHECK: (global $global114 i32 (global.get $global113))
(global $global114 i32 (global.get $global113))
;; CHECK: (global $global115 i32 (global.get $global114))
(global $global115 i32 (global.get $global114))
;; CHECK: (global $global116 i32 (global.get $global115))
(global $global116 i32 (global.get $global115))
;; CHECK: (global $global117 i32 (global.get $global116))
(global $global117 i32 (global.get $global116))
;; CHECK: (global $global118 i32 (global.get $global117))
(global $global118 i32 (global.get $global117))
;; CHECK: (global $global119 i32 (global.get $global118))
(global $global119 i32 (global.get $global118))
;; CHECK: (global $global120 i32 (global.get $global119))
(global $global120 i32 (global.get $global119))
;; CHECK: (global $global121 i32 (global.get $global120))
(global $global121 i32 (global.get $global120))
;; CHECK: (global $global122 i32 (global.get $global121))
(global $global122 i32 (global.get $global121))
;; CHECK: (global $global123 i32 (global.get $global122))
(global $global123 i32 (global.get $global122))
;; CHECK: (global $global124 i32 (global.get $global123))
(global $global124 i32 (global.get $global123))
;; CHECK: (global $global125 i32 (global.get $global124))
(global $global125 i32 (global.get $global124))
;; CHECK: (global $global126 i32 (global.get $global125))
(global $global126 i32 (global.get $global125))
;; CHECK: (global $global127 i32 (global.get $global126))
(global $global127 i32 (global.get $global126))
;; CHECK: (global $global128 i32 (global.get $global127))
(global $global128 i32 (global.get $global127))
;; CHECK: (global $other i32 (i32.const 0))
(global $other i32 (i32.const 0))
;; CHECK: (func $uses (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $other)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $other)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global128)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $uses
;; Aside from the uses in the globals themselves (which means one use for
;; each of global1..global127), we add two uses of other, to make it
;; have a higher count than global1, and 10 uses of global128, to make it
;; have the highest count by far.
(drop (global.get $other))
(drop (global.get $other))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
(drop (global.get $global128))
)
)
;; As above, but now the greedy sort is optimal. We remove all uses of
;; $global128, so $other has the highest count and there is no other factor that
;; matters here, so emitting $other first is best.
(module
;; CHECK: (global $other i32 (i32.const 0))
;; CHECK: (global $global1 i32 (i32.const 1))
(global $global1 i32 (i32.const 1))
;; CHECK: (global $global2 i32 (global.get $global1))
(global $global2 i32 (global.get $global1))
;; CHECK: (global $global3 i32 (global.get $global2))
(global $global3 i32 (global.get $global2))
;; CHECK: (global $global4 i32 (global.get $global3))
(global $global4 i32 (global.get $global3))
;; CHECK: (global $global5 i32 (global.get $global4))
(global $global5 i32 (global.get $global4))
;; CHECK: (global $global6 i32 (global.get $global5))
(global $global6 i32 (global.get $global5))
;; CHECK: (global $global7 i32 (global.get $global6))
(global $global7 i32 (global.get $global6))
;; CHECK: (global $global8 i32 (global.get $global7))
(global $global8 i32 (global.get $global7))
;; CHECK: (global $global9 i32 (global.get $global8))
(global $global9 i32 (global.get $global8))
;; CHECK: (global $global10 i32 (global.get $global9))
(global $global10 i32 (global.get $global9))
;; CHECK: (global $global11 i32 (global.get $global10))
(global $global11 i32 (global.get $global10))
;; CHECK: (global $global12 i32 (global.get $global11))
(global $global12 i32 (global.get $global11))
;; CHECK: (global $global13 i32 (global.get $global12))
(global $global13 i32 (global.get $global12))
;; CHECK: (global $global14 i32 (global.get $global13))
(global $global14 i32 (global.get $global13))
;; CHECK: (global $global15 i32 (global.get $global14))
(global $global15 i32 (global.get $global14))
;; CHECK: (global $global16 i32 (global.get $global15))
(global $global16 i32 (global.get $global15))
;; CHECK: (global $global17 i32 (global.get $global16))
(global $global17 i32 (global.get $global16))
;; CHECK: (global $global18 i32 (global.get $global17))
(global $global18 i32 (global.get $global17))
;; CHECK: (global $global19 i32 (global.get $global18))
(global $global19 i32 (global.get $global18))
;; CHECK: (global $global20 i32 (global.get $global19))
(global $global20 i32 (global.get $global19))
;; CHECK: (global $global21 i32 (global.get $global20))
(global $global21 i32 (global.get $global20))
;; CHECK: (global $global22 i32 (global.get $global21))
(global $global22 i32 (global.get $global21))
;; CHECK: (global $global23 i32 (global.get $global22))
(global $global23 i32 (global.get $global22))
;; CHECK: (global $global24 i32 (global.get $global23))
(global $global24 i32 (global.get $global23))
;; CHECK: (global $global25 i32 (global.get $global24))
(global $global25 i32 (global.get $global24))
;; CHECK: (global $global26 i32 (global.get $global25))
(global $global26 i32 (global.get $global25))
;; CHECK: (global $global27 i32 (global.get $global26))
(global $global27 i32 (global.get $global26))
;; CHECK: (global $global28 i32 (global.get $global27))
(global $global28 i32 (global.get $global27))
;; CHECK: (global $global29 i32 (global.get $global28))
(global $global29 i32 (global.get $global28))
;; CHECK: (global $global30 i32 (global.get $global29))
(global $global30 i32 (global.get $global29))
;; CHECK: (global $global31 i32 (global.get $global30))
(global $global31 i32 (global.get $global30))
;; CHECK: (global $global32 i32 (global.get $global31))
(global $global32 i32 (global.get $global31))
;; CHECK: (global $global33 i32 (global.get $global32))
(global $global33 i32 (global.get $global32))
;; CHECK: (global $global34 i32 (global.get $global33))
(global $global34 i32 (global.get $global33))
;; CHECK: (global $global35 i32 (global.get $global34))
(global $global35 i32 (global.get $global34))
;; CHECK: (global $global36 i32 (global.get $global35))
(global $global36 i32 (global.get $global35))
;; CHECK: (global $global37 i32 (global.get $global36))
(global $global37 i32 (global.get $global36))
;; CHECK: (global $global38 i32 (global.get $global37))
(global $global38 i32 (global.get $global37))
;; CHECK: (global $global39 i32 (global.get $global38))
(global $global39 i32 (global.get $global38))
;; CHECK: (global $global40 i32 (global.get $global39))
(global $global40 i32 (global.get $global39))
;; CHECK: (global $global41 i32 (global.get $global40))
(global $global41 i32 (global.get $global40))
;; CHECK: (global $global42 i32 (global.get $global41))
(global $global42 i32 (global.get $global41))
;; CHECK: (global $global43 i32 (global.get $global42))
(global $global43 i32 (global.get $global42))
;; CHECK: (global $global44 i32 (global.get $global43))
(global $global44 i32 (global.get $global43))
;; CHECK: (global $global45 i32 (global.get $global44))
(global $global45 i32 (global.get $global44))
;; CHECK: (global $global46 i32 (global.get $global45))
(global $global46 i32 (global.get $global45))
;; CHECK: (global $global47 i32 (global.get $global46))
(global $global47 i32 (global.get $global46))
;; CHECK: (global $global48 i32 (global.get $global47))
(global $global48 i32 (global.get $global47))
;; CHECK: (global $global49 i32 (global.get $global48))
(global $global49 i32 (global.get $global48))
;; CHECK: (global $global50 i32 (global.get $global49))
(global $global50 i32 (global.get $global49))
;; CHECK: (global $global51 i32 (global.get $global50))
(global $global51 i32 (global.get $global50))
;; CHECK: (global $global52 i32 (global.get $global51))
(global $global52 i32 (global.get $global51))
;; CHECK: (global $global53 i32 (global.get $global52))
(global $global53 i32 (global.get $global52))
;; CHECK: (global $global54 i32 (global.get $global53))
(global $global54 i32 (global.get $global53))
;; CHECK: (global $global55 i32 (global.get $global54))
(global $global55 i32 (global.get $global54))
;; CHECK: (global $global56 i32 (global.get $global55))
(global $global56 i32 (global.get $global55))
;; CHECK: (global $global57 i32 (global.get $global56))
(global $global57 i32 (global.get $global56))
;; CHECK: (global $global58 i32 (global.get $global57))
(global $global58 i32 (global.get $global57))
;; CHECK: (global $global59 i32 (global.get $global58))
(global $global59 i32 (global.get $global58))
;; CHECK: (global $global60 i32 (global.get $global59))
(global $global60 i32 (global.get $global59))
;; CHECK: (global $global61 i32 (global.get $global60))
(global $global61 i32 (global.get $global60))
;; CHECK: (global $global62 i32 (global.get $global61))
(global $global62 i32 (global.get $global61))
;; CHECK: (global $global63 i32 (global.get $global62))
(global $global63 i32 (global.get $global62))
;; CHECK: (global $global64 i32 (global.get $global63))
(global $global64 i32 (global.get $global63))
;; CHECK: (global $global65 i32 (global.get $global64))
(global $global65 i32 (global.get $global64))
;; CHECK: (global $global66 i32 (global.get $global65))
(global $global66 i32 (global.get $global65))
;; CHECK: (global $global67 i32 (global.get $global66))
(global $global67 i32 (global.get $global66))
;; CHECK: (global $global68 i32 (global.get $global67))
(global $global68 i32 (global.get $global67))
;; CHECK: (global $global69 i32 (global.get $global68))
(global $global69 i32 (global.get $global68))
;; CHECK: (global $global70 i32 (global.get $global69))
(global $global70 i32 (global.get $global69))
;; CHECK: (global $global71 i32 (global.get $global70))
(global $global71 i32 (global.get $global70))
;; CHECK: (global $global72 i32 (global.get $global71))
(global $global72 i32 (global.get $global71))
;; CHECK: (global $global73 i32 (global.get $global72))
(global $global73 i32 (global.get $global72))
;; CHECK: (global $global74 i32 (global.get $global73))
(global $global74 i32 (global.get $global73))
;; CHECK: (global $global75 i32 (global.get $global74))
(global $global75 i32 (global.get $global74))
;; CHECK: (global $global76 i32 (global.get $global75))
(global $global76 i32 (global.get $global75))
;; CHECK: (global $global77 i32 (global.get $global76))
(global $global77 i32 (global.get $global76))
;; CHECK: (global $global78 i32 (global.get $global77))
(global $global78 i32 (global.get $global77))
;; CHECK: (global $global79 i32 (global.get $global78))
(global $global79 i32 (global.get $global78))
;; CHECK: (global $global80 i32 (global.get $global79))
(global $global80 i32 (global.get $global79))
;; CHECK: (global $global81 i32 (global.get $global80))
(global $global81 i32 (global.get $global80))
;; CHECK: (global $global82 i32 (global.get $global81))
(global $global82 i32 (global.get $global81))
;; CHECK: (global $global83 i32 (global.get $global82))
(global $global83 i32 (global.get $global82))
;; CHECK: (global $global84 i32 (global.get $global83))
(global $global84 i32 (global.get $global83))
;; CHECK: (global $global85 i32 (global.get $global84))
(global $global85 i32 (global.get $global84))
;; CHECK: (global $global86 i32 (global.get $global85))
(global $global86 i32 (global.get $global85))
;; CHECK: (global $global87 i32 (global.get $global86))
(global $global87 i32 (global.get $global86))
;; CHECK: (global $global88 i32 (global.get $global87))
(global $global88 i32 (global.get $global87))
;; CHECK: (global $global89 i32 (global.get $global88))
(global $global89 i32 (global.get $global88))
;; CHECK: (global $global90 i32 (global.get $global89))
(global $global90 i32 (global.get $global89))
;; CHECK: (global $global91 i32 (global.get $global90))
(global $global91 i32 (global.get $global90))
;; CHECK: (global $global92 i32 (global.get $global91))
(global $global92 i32 (global.get $global91))
;; CHECK: (global $global93 i32 (global.get $global92))
(global $global93 i32 (global.get $global92))
;; CHECK: (global $global94 i32 (global.get $global93))
(global $global94 i32 (global.get $global93))
;; CHECK: (global $global95 i32 (global.get $global94))
(global $global95 i32 (global.get $global94))
;; CHECK: (global $global96 i32 (global.get $global95))
(global $global96 i32 (global.get $global95))
;; CHECK: (global $global97 i32 (global.get $global96))
(global $global97 i32 (global.get $global96))
;; CHECK: (global $global98 i32 (global.get $global97))
(global $global98 i32 (global.get $global97))
;; CHECK: (global $global99 i32 (global.get $global98))
(global $global99 i32 (global.get $global98))
;; CHECK: (global $global100 i32 (global.get $global99))
(global $global100 i32 (global.get $global99))
;; CHECK: (global $global101 i32 (global.get $global100))
(global $global101 i32 (global.get $global100))
;; CHECK: (global $global102 i32 (global.get $global101))
(global $global102 i32 (global.get $global101))
;; CHECK: (global $global103 i32 (global.get $global102))
(global $global103 i32 (global.get $global102))
;; CHECK: (global $global104 i32 (global.get $global103))
(global $global104 i32 (global.get $global103))
;; CHECK: (global $global105 i32 (global.get $global104))
(global $global105 i32 (global.get $global104))
;; CHECK: (global $global106 i32 (global.get $global105))
(global $global106 i32 (global.get $global105))
;; CHECK: (global $global107 i32 (global.get $global106))
(global $global107 i32 (global.get $global106))
;; CHECK: (global $global108 i32 (global.get $global107))
(global $global108 i32 (global.get $global107))
;; CHECK: (global $global109 i32 (global.get $global108))
(global $global109 i32 (global.get $global108))
;; CHECK: (global $global110 i32 (global.get $global109))
(global $global110 i32 (global.get $global109))
;; CHECK: (global $global111 i32 (global.get $global110))
(global $global111 i32 (global.get $global110))
;; CHECK: (global $global112 i32 (global.get $global111))
(global $global112 i32 (global.get $global111))
;; CHECK: (global $global113 i32 (global.get $global112))
(global $global113 i32 (global.get $global112))
;; CHECK: (global $global114 i32 (global.get $global113))
(global $global114 i32 (global.get $global113))
;; CHECK: (global $global115 i32 (global.get $global114))
(global $global115 i32 (global.get $global114))
;; CHECK: (global $global116 i32 (global.get $global115))
(global $global116 i32 (global.get $global115))
;; CHECK: (global $global117 i32 (global.get $global116))
(global $global117 i32 (global.get $global116))
;; CHECK: (global $global118 i32 (global.get $global117))
(global $global118 i32 (global.get $global117))
;; CHECK: (global $global119 i32 (global.get $global118))
(global $global119 i32 (global.get $global118))
;; CHECK: (global $global120 i32 (global.get $global119))
(global $global120 i32 (global.get $global119))
;; CHECK: (global $global121 i32 (global.get $global120))
(global $global121 i32 (global.get $global120))
;; CHECK: (global $global122 i32 (global.get $global121))
(global $global122 i32 (global.get $global121))
;; CHECK: (global $global123 i32 (global.get $global122))
(global $global123 i32 (global.get $global122))
;; CHECK: (global $global124 i32 (global.get $global123))
(global $global124 i32 (global.get $global123))
;; CHECK: (global $global125 i32 (global.get $global124))
(global $global125 i32 (global.get $global124))
;; CHECK: (global $global126 i32 (global.get $global125))
(global $global126 i32 (global.get $global125))
;; CHECK: (global $global127 i32 (global.get $global126))
(global $global127 i32 (global.get $global126))
;; CHECK: (global $global128 i32 (global.get $global127))
(global $global128 i32 (global.get $global127))
(global $other i32 (i32.const 0))
;; CHECK: (func $uses (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $other)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $other)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $uses
(drop (global.get $other))
(drop (global.get $other))
)
)
;; As the last testcase, but one global fewer. As a result we only need a single
;; LEB byte for them all, and we do not bother changing the sort here.
(module
;; CHECK: (global $global1 i32 (i32.const 1))
(global $global1 i32 (i32.const 1))
;; CHECK: (global $global2 i32 (global.get $global1))
(global $global2 i32 (global.get $global1))
;; CHECK: (global $global3 i32 (global.get $global2))
(global $global3 i32 (global.get $global2))
;; CHECK: (global $global4 i32 (global.get $global3))
(global $global4 i32 (global.get $global3))
;; CHECK: (global $global5 i32 (global.get $global4))
(global $global5 i32 (global.get $global4))
;; CHECK: (global $global6 i32 (global.get $global5))
(global $global6 i32 (global.get $global5))
;; CHECK: (global $global7 i32 (global.get $global6))
(global $global7 i32 (global.get $global6))
;; CHECK: (global $global8 i32 (global.get $global7))
(global $global8 i32 (global.get $global7))
;; CHECK: (global $global9 i32 (global.get $global8))
(global $global9 i32 (global.get $global8))
;; CHECK: (global $global10 i32 (global.get $global9))
(global $global10 i32 (global.get $global9))
;; CHECK: (global $global11 i32 (global.get $global10))
(global $global11 i32 (global.get $global10))
;; CHECK: (global $global12 i32 (global.get $global11))
(global $global12 i32 (global.get $global11))
;; CHECK: (global $global13 i32 (global.get $global12))
(global $global13 i32 (global.get $global12))
;; CHECK: (global $global14 i32 (global.get $global13))
(global $global14 i32 (global.get $global13))
;; CHECK: (global $global15 i32 (global.get $global14))
(global $global15 i32 (global.get $global14))
;; CHECK: (global $global16 i32 (global.get $global15))
(global $global16 i32 (global.get $global15))
;; CHECK: (global $global17 i32 (global.get $global16))
(global $global17 i32 (global.get $global16))
;; CHECK: (global $global18 i32 (global.get $global17))
(global $global18 i32 (global.get $global17))
;; CHECK: (global $global19 i32 (global.get $global18))
(global $global19 i32 (global.get $global18))
;; CHECK: (global $global20 i32 (global.get $global19))
(global $global20 i32 (global.get $global19))
;; CHECK: (global $global21 i32 (global.get $global20))
(global $global21 i32 (global.get $global20))
;; CHECK: (global $global22 i32 (global.get $global21))
(global $global22 i32 (global.get $global21))
;; CHECK: (global $global23 i32 (global.get $global22))
(global $global23 i32 (global.get $global22))
;; CHECK: (global $global24 i32 (global.get $global23))
(global $global24 i32 (global.get $global23))
;; CHECK: (global $global25 i32 (global.get $global24))
(global $global25 i32 (global.get $global24))
;; CHECK: (global $global26 i32 (global.get $global25))
(global $global26 i32 (global.get $global25))
;; CHECK: (global $global27 i32 (global.get $global26))
(global $global27 i32 (global.get $global26))
;; CHECK: (global $global28 i32 (global.get $global27))
(global $global28 i32 (global.get $global27))
;; CHECK: (global $global29 i32 (global.get $global28))
(global $global29 i32 (global.get $global28))
;; CHECK: (global $global30 i32 (global.get $global29))
(global $global30 i32 (global.get $global29))
;; CHECK: (global $global31 i32 (global.get $global30))
(global $global31 i32 (global.get $global30))
;; CHECK: (global $global32 i32 (global.get $global31))
(global $global32 i32 (global.get $global31))
;; CHECK: (global $global33 i32 (global.get $global32))
(global $global33 i32 (global.get $global32))
;; CHECK: (global $global34 i32 (global.get $global33))
(global $global34 i32 (global.get $global33))
;; CHECK: (global $global35 i32 (global.get $global34))
(global $global35 i32 (global.get $global34))
;; CHECK: (global $global36 i32 (global.get $global35))
(global $global36 i32 (global.get $global35))
;; CHECK: (global $global37 i32 (global.get $global36))
(global $global37 i32 (global.get $global36))
;; CHECK: (global $global38 i32 (global.get $global37))
(global $global38 i32 (global.get $global37))
;; CHECK: (global $global39 i32 (global.get $global38))
(global $global39 i32 (global.get $global38))
;; CHECK: (global $global40 i32 (global.get $global39))
(global $global40 i32 (global.get $global39))
;; CHECK: (global $global41 i32 (global.get $global40))
(global $global41 i32 (global.get $global40))
;; CHECK: (global $global42 i32 (global.get $global41))
(global $global42 i32 (global.get $global41))
;; CHECK: (global $global43 i32 (global.get $global42))
(global $global43 i32 (global.get $global42))
;; CHECK: (global $global44 i32 (global.get $global43))
(global $global44 i32 (global.get $global43))
;; CHECK: (global $global45 i32 (global.get $global44))
(global $global45 i32 (global.get $global44))
;; CHECK: (global $global46 i32 (global.get $global45))
(global $global46 i32 (global.get $global45))
;; CHECK: (global $global47 i32 (global.get $global46))
(global $global47 i32 (global.get $global46))
;; CHECK: (global $global48 i32 (global.get $global47))
(global $global48 i32 (global.get $global47))
;; CHECK: (global $global49 i32 (global.get $global48))
(global $global49 i32 (global.get $global48))
;; CHECK: (global $global50 i32 (global.get $global49))
(global $global50 i32 (global.get $global49))
;; CHECK: (global $global51 i32 (global.get $global50))
(global $global51 i32 (global.get $global50))
;; CHECK: (global $global52 i32 (global.get $global51))
(global $global52 i32 (global.get $global51))
;; CHECK: (global $global53 i32 (global.get $global52))
(global $global53 i32 (global.get $global52))
;; CHECK: (global $global54 i32 (global.get $global53))
(global $global54 i32 (global.get $global53))
;; CHECK: (global $global55 i32 (global.get $global54))
(global $global55 i32 (global.get $global54))
;; CHECK: (global $global56 i32 (global.get $global55))
(global $global56 i32 (global.get $global55))
;; CHECK: (global $global57 i32 (global.get $global56))
(global $global57 i32 (global.get $global56))
;; CHECK: (global $global58 i32 (global.get $global57))
(global $global58 i32 (global.get $global57))
;; CHECK: (global $global59 i32 (global.get $global58))
(global $global59 i32 (global.get $global58))
;; CHECK: (global $global60 i32 (global.get $global59))
(global $global60 i32 (global.get $global59))
;; CHECK: (global $global61 i32 (global.get $global60))
(global $global61 i32 (global.get $global60))
;; CHECK: (global $global62 i32 (global.get $global61))
(global $global62 i32 (global.get $global61))
;; CHECK: (global $global63 i32 (global.get $global62))
(global $global63 i32 (global.get $global62))
;; CHECK: (global $global64 i32 (global.get $global63))
(global $global64 i32 (global.get $global63))
;; CHECK: (global $global65 i32 (global.get $global64))
(global $global65 i32 (global.get $global64))
;; CHECK: (global $global66 i32 (global.get $global65))
(global $global66 i32 (global.get $global65))
;; CHECK: (global $global67 i32 (global.get $global66))
(global $global67 i32 (global.get $global66))
;; CHECK: (global $global68 i32 (global.get $global67))
(global $global68 i32 (global.get $global67))
;; CHECK: (global $global69 i32 (global.get $global68))
(global $global69 i32 (global.get $global68))
;; CHECK: (global $global70 i32 (global.get $global69))
(global $global70 i32 (global.get $global69))
;; CHECK: (global $global71 i32 (global.get $global70))
(global $global71 i32 (global.get $global70))
;; CHECK: (global $global72 i32 (global.get $global71))
(global $global72 i32 (global.get $global71))
;; CHECK: (global $global73 i32 (global.get $global72))
(global $global73 i32 (global.get $global72))
;; CHECK: (global $global74 i32 (global.get $global73))
(global $global74 i32 (global.get $global73))
;; CHECK: (global $global75 i32 (global.get $global74))
(global $global75 i32 (global.get $global74))
;; CHECK: (global $global76 i32 (global.get $global75))
(global $global76 i32 (global.get $global75))
;; CHECK: (global $global77 i32 (global.get $global76))
(global $global77 i32 (global.get $global76))
;; CHECK: (global $global78 i32 (global.get $global77))
(global $global78 i32 (global.get $global77))
;; CHECK: (global $global79 i32 (global.get $global78))
(global $global79 i32 (global.get $global78))
;; CHECK: (global $global80 i32 (global.get $global79))
(global $global80 i32 (global.get $global79))
;; CHECK: (global $global81 i32 (global.get $global80))
(global $global81 i32 (global.get $global80))
;; CHECK: (global $global82 i32 (global.get $global81))
(global $global82 i32 (global.get $global81))
;; CHECK: (global $global83 i32 (global.get $global82))
(global $global83 i32 (global.get $global82))
;; CHECK: (global $global84 i32 (global.get $global83))
(global $global84 i32 (global.get $global83))
;; CHECK: (global $global85 i32 (global.get $global84))
(global $global85 i32 (global.get $global84))
;; CHECK: (global $global86 i32 (global.get $global85))
(global $global86 i32 (global.get $global85))
;; CHECK: (global $global87 i32 (global.get $global86))
(global $global87 i32 (global.get $global86))
;; CHECK: (global $global88 i32 (global.get $global87))
(global $global88 i32 (global.get $global87))
;; CHECK: (global $global89 i32 (global.get $global88))
(global $global89 i32 (global.get $global88))
;; CHECK: (global $global90 i32 (global.get $global89))
(global $global90 i32 (global.get $global89))
;; CHECK: (global $global91 i32 (global.get $global90))
(global $global91 i32 (global.get $global90))
;; CHECK: (global $global92 i32 (global.get $global91))
(global $global92 i32 (global.get $global91))
;; CHECK: (global $global93 i32 (global.get $global92))
(global $global93 i32 (global.get $global92))
;; CHECK: (global $global94 i32 (global.get $global93))
(global $global94 i32 (global.get $global93))
;; CHECK: (global $global95 i32 (global.get $global94))
(global $global95 i32 (global.get $global94))
;; CHECK: (global $global96 i32 (global.get $global95))
(global $global96 i32 (global.get $global95))
;; CHECK: (global $global97 i32 (global.get $global96))
(global $global97 i32 (global.get $global96))
;; CHECK: (global $global98 i32 (global.get $global97))
(global $global98 i32 (global.get $global97))
;; CHECK: (global $global99 i32 (global.get $global98))
(global $global99 i32 (global.get $global98))
;; CHECK: (global $global100 i32 (global.get $global99))
(global $global100 i32 (global.get $global99))
;; CHECK: (global $global101 i32 (global.get $global100))
(global $global101 i32 (global.get $global100))
;; CHECK: (global $global102 i32 (global.get $global101))
(global $global102 i32 (global.get $global101))
;; CHECK: (global $global103 i32 (global.get $global102))
(global $global103 i32 (global.get $global102))
;; CHECK: (global $global104 i32 (global.get $global103))
(global $global104 i32 (global.get $global103))
;; CHECK: (global $global105 i32 (global.get $global104))
(global $global105 i32 (global.get $global104))
;; CHECK: (global $global106 i32 (global.get $global105))
(global $global106 i32 (global.get $global105))
;; CHECK: (global $global107 i32 (global.get $global106))
(global $global107 i32 (global.get $global106))
;; CHECK: (global $global108 i32 (global.get $global107))
(global $global108 i32 (global.get $global107))
;; CHECK: (global $global109 i32 (global.get $global108))
(global $global109 i32 (global.get $global108))
;; CHECK: (global $global110 i32 (global.get $global109))
(global $global110 i32 (global.get $global109))
;; CHECK: (global $global111 i32 (global.get $global110))
(global $global111 i32 (global.get $global110))
;; CHECK: (global $global112 i32 (global.get $global111))
(global $global112 i32 (global.get $global111))
;; CHECK: (global $global113 i32 (global.get $global112))
(global $global113 i32 (global.get $global112))
;; CHECK: (global $global114 i32 (global.get $global113))
(global $global114 i32 (global.get $global113))
;; CHECK: (global $global115 i32 (global.get $global114))
(global $global115 i32 (global.get $global114))
;; CHECK: (global $global116 i32 (global.get $global115))
(global $global116 i32 (global.get $global115))
;; CHECK: (global $global117 i32 (global.get $global116))
(global $global117 i32 (global.get $global116))
;; CHECK: (global $global118 i32 (global.get $global117))
(global $global118 i32 (global.get $global117))
;; CHECK: (global $global119 i32 (global.get $global118))
(global $global119 i32 (global.get $global118))
;; CHECK: (global $global120 i32 (global.get $global119))
(global $global120 i32 (global.get $global119))
;; CHECK: (global $global121 i32 (global.get $global120))
(global $global121 i32 (global.get $global120))
;; CHECK: (global $global122 i32 (global.get $global121))
(global $global122 i32 (global.get $global121))
;; CHECK: (global $global123 i32 (global.get $global122))
(global $global123 i32 (global.get $global122))
;; CHECK: (global $global124 i32 (global.get $global123))
(global $global124 i32 (global.get $global123))
;; CHECK: (global $global125 i32 (global.get $global124))
(global $global125 i32 (global.get $global124))
;; CHECK: (global $global126 i32 (global.get $global125))
(global $global126 i32 (global.get $global125))
;; CHECK: (global $global127 i32 (global.get $global126))
(global $global127 i32 (global.get $global126))
;; $global128 was removed
;; CHECK: (global $other i32 (i32.const 0))
(global $other i32 (i32.const 0))
;; CHECK: (func $uses (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $other)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $other)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $uses
(drop (global.get $other))
(drop (global.get $other))
)
)
|