updating to the latest module.
[mono.git] / mono / mini / iltests.il
1 .assembly iltests {}
2 .assembly extern TestDriver {}
3 .assembly extern mscorlib {}
4
5 .class public auto ansi sealed beforefieldinit Tests {
6
7         .method static public int32 Main(string[] args) il managed {
8                 .entrypoint
9                 
10                 ldtoken Tests
11                 call       class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
12                 ldarg.0
13                 call       int32 [TestDriver]TestDriver::RunTests(class [mscorlib]System.Type, string[])
14                 ret
15         }
16
17         // make sure the register allocator works when the return value of
18         // 'div' is discarded
19         .method static public int32 test_0_div_regalloc () il managed {
20                 .locals init (
21                         int32 i
22                 )
23
24                 ldloc 0
25                 ldc.i4.s 0xa
26                 div
27                 pop
28                 ldc.i4.0
29                 ret
30         }
31         
32         
33         .method static public int32 test_1_ceq_to_i4 () il managed {
34                 .locals init (
35                         int32   foo
36                 )
37                 ldc.i4 500
38                 stloc foo
39                 ldloc foo
40                 ldc.i4 500
41                 ceq
42                 stloc foo
43                 ldloc foo
44                 ret
45         }
46         
47         .method static public int32 test_3_shl_regvars () il managed {
48                 .locals init (
49                         int32   a,
50                         int32   b,
51                         int32   r1,
52                         int32   r2,
53                         int32   r3
54                 )
55                         
56                 ldc.i4.2
57                 stloc      a
58                 ldc.i4.1
59                 stloc      b
60         
61                 ldloc      a
62                 ldloc      b
63                 shl 
64                 stloc      r1
65                 
66                 ldloc      a
67                 ldloc      b
68                 shl 
69                 stloc      r2
70                 
71                 ldloc      a
72                 ldloc      b
73                 shl 
74                 stloc      r3
75                 
76                 ldloc      r1
77                 ldc.i4.4
78                 ceq
79                 
80                 ldloc      r2
81                 ldc.i4.4
82                 ceq
83                 
84                 ldloc      r3
85                 ldc.i4.4
86                 ceq
87                 
88                 add
89                 add
90                 
91                 ret
92         }
93         
94         .method static public int32 test_1_fceq_to_i4 () il managed {
95         
96                 .locals init (
97                         float64 foo,
98                         int32   val
99                 )
100
101                 ldc.r8      2
102                 stloc       foo
103                 
104                 ldloc       foo
105                 ldc.r8      2
106                 ceq
107                 stloc       val
108                 
109                 ldloc       val
110                 ret
111         }
112
113         //
114         // This should be manually checked. Basically under -O=linears,
115         // you should not see tons of register spilling.
116         //
117         .method static public int32 test_1_bytedreg_free () il managed {
118                 .locals init (
119                         int32   foo
120                 )
121                 ldc.i4 500
122                 stloc foo
123                 ldloc foo
124                 ldc.i4 500
125                 ceq
126                 stloc foo
127                 
128                 ldloc foo
129                 ldc.i4 1
130                 ceq
131                 stloc foo
132
133                 ldloc foo
134                 ldc.i4 1
135                 ceq
136                 stloc foo
137
138                 ldloc foo
139                 ldc.i4 1
140                 ceq
141                 stloc foo
142                 
143                 ldloc foo
144                 ldc.i4 1
145                 ceq
146                 stloc foo
147                 
148                 ldloc foo
149                 ret
150         }
151         
152         //
153         // This should be manually checked. Basically under -O=linears,
154         // you should not see tons of register spilling.
155         //
156         .method static public int32 test_0_bytesreg1_free () il managed {
157                 .locals init (
158                         unsigned int8      dest,
159                         int32              src,
160                         unsigned int8&     pdest
161                 )
162
163                 ldloca     dest
164                 stloc      pdest
165                 
166                 ldloc      pdest
167                 ldloc      src
168                 stind.i1
169                 
170                 ldloc      pdest
171                 ldloc      src
172                 stind.i1
173                 
174                 ldloc      pdest
175                 ldloc      src
176                 stind.i1
177                 
178                 ldloc      pdest
179                 ldloc      src
180                 stind.i1
181                 
182                 ldloc      pdest
183                 ldloc      src
184                 stind.i1
185                 
186                 ldloc      pdest
187                 ldloc      src
188                 stind.i1
189                 
190                 ldloc      pdest
191                 ldind.i1
192                 ret
193         }
194         
195         .method static public int32 test_1_shift_regvar () il managed {
196         
197                 .locals init (
198                         int32   v7FFFFFFF,
199                         int32   v1
200                 )
201                 
202                 ldc.i4  0x7FFFFFFF
203                 stloc   v7FFFFFFF
204         
205                 ldc.i4.1
206                 stloc v1
207                 
208                 ldloc   v7FFFFFFF
209                 ldloc   v1
210                 shl
211                 ldc.i4  0xFFFFFFFE
212                 ceq
213                 ret
214         }
215         
216         // this only happens with the managed pointer, not an unmanaged one.
217         .method static public int32 test_0_foo () il managed {
218         
219                 .locals init (
220                         int32&  buf
221                 )
222                 
223                 ldc.i4.5
224                 localloc
225                 
226                 stloc buf
227                 ldloc buf
228                 
229                 ldind.i4
230                 
231                 ret
232         }
233
234         .method static public int32 test_0_localloc () cil managed {
235                 .locals init (native int, native int, native int, native int, int32)
236
237                 ldc.i4 6
238                 localloc
239                 conv.i
240                 stloc.0
241
242                 ldc.i4 6
243                 localloc
244                 conv.i
245                 stloc.1
246
247                 ldc.i4 6
248                 localloc
249                 conv.i
250                 stloc.2
251
252                 // Variable length
253                 ldc.i4 128
254                 stloc.s 4
255                 ldloc.s 4
256                 localloc
257                 conv.i
258                 stloc.3
259
260                 // Check zero initialized
261                 ldloc.0
262                 ldind.i4
263                 ldc.i4.0
264                 beq OK1
265                 ldc.i4.1
266                 br FAIL
267
268 OK1:
269                 ldloc.3
270                 ldind.i4
271                 ldc.i4.0
272                 beq OK2
273                 ldc.i4.2
274                 br FAIL
275
276 OK2:
277                 ldloc.3
278                 ldc.i4.s 124
279                 add
280                 ldind.i4
281                 ldc.i4.0
282                 beq OK3
283                 ldc.i4.3
284                 br FAIL
285
286 OK3:
287                 ldloc.1
288                 ldc.i4 999999
289                 stind.i4
290                 ldloc.1
291                 ldind.i4
292                 ldc.i4 999999
293                 beq OK4
294                 ldc.i4.4
295                 br FAIL
296
297 OK4:
298                 ldloc.0
299                 ldc.i4 999999
300                 stind.i4
301                 ldloc.0
302                 ldind.i4
303                 ldc.i4 999999
304                 beq OK5
305                 ldc.i4.5
306                 br FAIL
307
308 OK5:
309                 // Try allocations bigger than one page
310                 ldc.i4 8196
311                 localloc
312                 conv.i
313                 stloc.3
314                 ldloc.3
315                 ldc.i4 8192
316                 add
317                 ldc.i4 99
318                 stind.i4
319                 ldloc.3
320                 ldc.i4 8192
321                 add
322                 ldind.i4
323                 ldc.i4 99
324                 beq PASS
325                 ldc.i4.6
326                 br FAIL
327
328 FAIL:
329                 ret
330
331 PASS:   ldc.i4.0
332                 ret
333         }
334
335     .method private static void do_localloc () cil managed {
336         .maxstack 3
337         .locals init (
338                 unsigned int8*  V_0)
339         IL_0000:  ldc.i4.1
340         IL_0001:  ldc.i4 131072
341         IL_0006:  mul
342         IL_0007:  localloc
343         IL_0009:  stloc.0
344         IL_000a:  ret
345     }
346
347         // Check that localloc can't be inlined
348         .method static public int32 test_0_localloc_inline () cil managed {
349                 .maxstack 16
350                 .locals init (
351                         int32 i
352                 )
353
354                 ldc.i4.0
355         stloc.0
356         br COND
357
358 START:  call void class Tests::do_localloc()
359         ldloc.0
360         ldc.i4.1
361         add
362         stloc.0
363 COND:   ldloc.0
364         ldc.i4 1000
365         blt START
366
367                 ldc.i4.0
368                 ret
369         }       
370         
371         .method static public int32 test_3_copy_used_bug () il managed {
372
373                 .locals init (
374                         int32 size,
375                         int32 res
376                 )
377
378                 ldc.i4 0
379                 stloc res
380
381                 ldc.i4 1
382                 stloc size
383
384                 ldloc size
385                 ldloc size
386                 ldloc size
387                 add
388                 stloc size
389                 ldloc size
390                 add
391                 stloc res
392
393                 ldloc res
394                 ret
395         }
396
397         // demonstrate that the copy_used_var is not a fix for the above bug
398         .method static public int32 test_3_copy_used_indir_bug () il managed {
399
400                 .locals init (
401                         int32 size,
402                         int32 res
403                 )
404
405                 ldc.i4 0
406                 stloc res
407
408                 ldc.i4 1
409                 stloc size
410
411                 ldloc size
412                 ldloca size
413                 ldloc size
414                 ldloc size
415                 add
416                 stind.i4
417                 ldloc size
418                 add
419                 stloc res
420
421                 ldloc res
422                 ret
423         }
424
425         .method static public void do_nothing (int32 a) il managed {
426                 ret
427         }
428         
429         // demonstrate the block_split failure: needs -O=inline
430         // mini -O=inline --compile Tests:test_0_split_block_bug iltests.exe
431         .method static public int32 test_0_split_block_bug () il managed {
432
433                 .locals init (
434                         int32 i1
435                 )
436
437                 ldc.i4 1
438                 stloc i1
439  test_label:
440                 ldloc i1
441                 call void class Tests::do_nothing (int32)
442                 ldc.i4 0
443                 brtrue test_label
444                 
445                 ldc.i4 0
446                 ret
447         }
448
449         .method public void inline_do_nothing () il managed {
450                 ret
451         }
452         .method static public int32 test_1_checkthis_inlining () il managed {
453                 ldnull
454                 call instance void class Tests::inline_do_nothing ()
455                 ldc.i4 1
456                 ret
457         }
458
459         .class nested private auto ansi sealed beforefieldinit TailCallStruct 
460                 extends [mscorlib]System.ValueType {
461                 .field public int32 a
462                 .field public int32 b
463         }
464
465         .method static valuetype Tests/TailCallStruct tail1 (valuetype Tests/TailCallStruct arg) {
466                 ldarga 0
467                 ldarga 0
468                 ldfld int32 Tests/TailCallStruct::a
469                 ldc.i4.1
470                 add
471                 stfld int32 Tests/TailCallStruct::a
472                 ldarga 0
473                 ldarga 0
474                 ldfld int32 Tests/TailCallStruct::a
475                 ldc.i4.2
476                 add
477                 stfld int32 Tests/TailCallStruct::a
478                 ldarg.0
479                 ret
480         }
481
482         .method static valuetype Tests/TailCallStruct tail2 (valuetype Tests/TailCallStruct arg) {
483                 ldarg.0
484                 tail.
485                 call valuetype Tests/TailCallStruct Tests::tail1 (valuetype Tests/TailCallStruct)
486                 ret
487         }
488
489         .method static public int32 test_0_tail_calls () il managed {
490                 .maxstack 16
491                 .locals init (
492                         valuetype Tests/TailCallStruct arg
493                 )
494                 ldloca 0
495                 ldc.i4.2
496                 stfld int32 Tests/TailCallStruct::a
497                 ldloca 0
498                 ldc.i4.4
499                 stfld int32 Tests/TailCallStruct::b
500                 ldloc.0
501                 call valuetype Tests/TailCallStruct Tests::tail2 (valuetype Tests/TailCallStruct)
502                 stloc.0
503                 ldloca 0
504                 ldfld int32 Tests/TailCallStruct::a
505                 ldloca 0
506                 ldfld int32 Tests/TailCallStruct::b
507                 add
508                 ldc.i4 9
509                 sub
510                 ret
511         }
512
513         .method static public int32 test_11_switch_with_nonempty_stack () il managed {
514                 .maxstack 16
515
516                 ldc.i4.5
517                 ldc.i4.6
518                 ldc.i4.1
519                 switch (L0, L1)
520         L0: 
521                 add
522                 ret
523         L1:
524                 add
525                 ret
526         }
527  
528     .method public static int32 test_5_endfinally_with_nonempty_stack () il managed {
529                 .maxstack 16
530
531         .try {
532           leave IL_0
533         }
534         finally  {
535           ldc.i4.0
536           endfinally
537         }
538         IL_0:  ldc.i4.5
539                 ret
540     }
541
542         .method public static int32 test_0_conv_ovf_i8_neg () il managed {
543                 .maxstack 16
544
545                 ldc.i4.m1
546                 conv.ovf.i8
547                 conv.i4
548                 ldc.i4.m1
549                 beq L_OK
550                 ldc.i4.1
551                 ret
552         L_OK:
553                 ldc.i4.0
554                 ret
555         }               
556
557         .method public static int32 test_0_get_type_from_handle_on_bblock_boundary () cil managed 
558         {
559                 .maxstack 16
560         
561                 ldc.i4.1
562                 brfalse OBJECT
563         
564                 ldtoken [mscorlib]System.String
565                 br AFTER
566         OBJECT:
567                 ldtoken [mscorlib]System.Object
568         AFTER:
569                 call class [mscorlib]'System.Type' class [mscorlib]'System.Type'::'GetTypeFromHandle'(valuetype [mscorlib]'System.RuntimeTypeHandle')
570                 callvirt instance string class [mscorlib]System.Type::get_FullName ()
571                 ldstr "System.String"
572                 callvirt instance bool class [mscorlib]System.Object::Equals(object)
573                 ldc.i4.0
574                 ceq
575                 ret 
576         }
577                 
578         .method public static int32 test_0_bug59580  ()
579         {
580                 ldc.r4          float32(0x7FC00000)
581                 ldc.r4          float32(0x7FC00000)
582                 bge.un          pass
583                 br              fail
584         pass:
585                 ldc.i4.0
586                 ret
587         fail:
588                 ldc.i4.1
589                 ret
590         }
591         
592         .method public static int32 test_1_bug60056  () {
593                 .locals init (int32 m5)
594                         
595                 ldc.i4.m1
596                 stloc.0
597                 
598                 ldc.i4.1
599                 conv.u8
600                 
601                 ldloc.0
602                 conv.i8
603                 mul
604                 
605                 ldc.i4.m1
606                 conv.i8
607                 ceq
608                 ret
609         }
610         
611         .method public static int32 test_1_conv_u8_cfold  () {
612                 ldc.i4.m1
613                 conv.u8
614                 
615                 ldc.i8 0x00000000ffffffff
616                 
617                 ceq
618                 ret
619         }
620         
621         .method public static int32 test_1_array_type_mismatch_ldelema  () {
622                 .locals init (int32 r)
623                 
624                         ldc.i4.1
625                         newarr string
626                         ldc.i4.0 
627                         ldelema string
628                         pop
629                 
630                 .try {
631                         ldc.i4.1
632                         newarr string
633                         ldc.i4.0 
634                         ldelema object
635                         pop
636                         
637                         leave end
638                 } catch [mscorlib]System.ArrayTypeMismatchException {
639                         pop
640                         ldc.i4.1
641                         stloc.0
642                         leave end
643                 }
644         end:
645                 ldloc.0
646                 ret
647         }
648
649         .method public static int32 test_1_conv_ovf_i8_with_i4 () {
650                         ldc.i4.m1 
651                         conv.ovf.i8
652                         conv.ovf.i4
653                         neg
654                         ret
655         }
656
657         // bug #72148
658     .method public static int32 test_0_initlocals_float_ptr () {
659         .maxstack 3
660         .locals init (
661                 float32[]       V_0,
662                 float32& pinned V_1,
663                 unsigned int32  V_2)
664                         ldc.i4.s 0x0f
665                         newarr [mscorlib]System.Single
666                         stloc.0 
667                         ldloc.0 
668                         ldc.i4.0 
669                         ldc.r4 1.13
670                         stelem.r4 
671                         ldloc.0 
672                         ldc.i4.0 
673                         ldelema [mscorlib]System.Single
674                         stloc.1 
675                         ldloc.1 
676                         conv.i 
677                         ldind.u4 
678                         stloc.2 
679                         ldc.i4.0
680                         ret
681         }
682
683         .class nested private auto ansi sealed beforefieldinit FooStruct 
684                 extends [mscorlib]System.ValueType {
685
686                 .method public hidebysig specialname rtspecialname instance void .ctor () cil managed {
687                         .maxstack 8
688                         ret
689                 }
690         }
691
692         .method public static int32 test_0_newobj_vtype () {
693                 .maxstack 8
694
695                 newobj instance void Tests/FooStruct::.ctor()
696                 pop
697                 ldc.i4.0
698                 ret
699         }
700
701         .method public static int32 test_7_conv_ovf_u8_un () {
702         .maxstack  2
703         .locals    init (unsigned int64)
704
705         ldc.i4.7
706         conv.ovf.u8.un
707         stloc.0
708                 ldloc.0
709                 conv.i4
710         ret
711         }
712
713         .method public static int32 test_1_bug_74591 () {
714                 .maxstack 16
715                 .locals init (int32)
716
717                 ldc.i4.m1
718                 stloc.0
719                 ldloc.0
720                 conv.ovf.i8
721                 ldc.i4.m1
722                 conv.ovf.i8
723                 mul.ovf
724                 conv.i4
725                 ret
726         }
727
728 }