2005-02-14 Zoltan Varga <vargaz@freemail.hu>
[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 PASS
305                 ldc.i4.5
306                 br FAIL
307
308 FAIL:
309                 ret
310
311 PASS:   ldc.i4.0
312                 ret
313         }
314
315     .method private static void do_localloc () cil managed {
316         .maxstack 3
317         .locals init (
318                 unsigned int8*  V_0)
319         IL_0000:  ldc.i4.1
320         IL_0001:  ldc.i4 131072
321         IL_0006:  mul
322         IL_0007:  localloc
323         IL_0009:  stloc.0
324         IL_000a:  ret
325     }
326
327         // Check that localloc can't be inlined
328         .method static public int32 test_0_localloc_inline () cil managed {
329                 .maxstack 16
330                 .locals init (
331                         int32 i
332                 )
333
334                 ldc.i4.0
335         stloc.0
336         br COND
337
338 START:  call void class Tests::do_localloc()
339         ldloc.0
340         ldc.i4.1
341         add
342         stloc.0
343 COND:   ldloc.0
344         ldc.i4 1000
345         blt START
346
347                 ldc.i4.0
348                 ret
349         }       
350         
351         .method static public int32 test_3_copy_used_bug () il managed {
352
353                 .locals init (
354                         int32 size,
355                         int32 res
356                 )
357
358                 ldc.i4 0
359                 stloc res
360
361                 ldc.i4 1
362                 stloc size
363
364                 ldloc size
365                 ldloc size
366                 ldloc size
367                 add
368                 stloc size
369                 ldloc size
370                 add
371                 stloc res
372
373                 ldloc res
374                 ret
375         }
376
377         // demonstrate that the copy_used_var is not a fix for the above bug
378         .method static public int32 test_3_copy_used_indir_bug () il managed {
379
380                 .locals init (
381                         int32 size,
382                         int32 res
383                 )
384
385                 ldc.i4 0
386                 stloc res
387
388                 ldc.i4 1
389                 stloc size
390
391                 ldloc size
392                 ldloca size
393                 ldloc size
394                 ldloc size
395                 add
396                 stind.i4
397                 ldloc size
398                 add
399                 stloc res
400
401                 ldloc res
402                 ret
403         }
404
405         .method static public void do_nothing (int32 a) il managed {
406                 ret
407         }
408         
409         // demonstrate the block_split failure: needs -O=inline
410         // mini -O=inline --compile Tests:test_0_split_block_bug iltests.exe
411         .method static public int32 test_0_split_block_bug () il managed {
412
413                 .locals init (
414                         int32 i1
415                 )
416
417                 ldc.i4 1
418                 stloc i1
419  test_label:
420                 ldloc i1
421                 call void class Tests::do_nothing (int32)
422                 ldc.i4 0
423                 brtrue test_label
424                 
425                 ldc.i4 0
426                 ret
427         }
428
429         .method public void inline_do_nothing () il managed {
430                 ret
431         }
432         .method static public int32 test_1_checkthis_inlining () il managed {
433                 ldnull
434                 call instance void class Tests::inline_do_nothing ()
435                 ldc.i4 1
436                 ret
437         }
438
439         .class nested private auto ansi sealed beforefieldinit TailCallStruct 
440                 extends [mscorlib]System.ValueType {
441                 .field public int32 a
442                 .field public int32 b
443         }
444
445         .method static valuetype Tests/TailCallStruct tail1 (valuetype Tests/TailCallStruct arg) {
446                 ldarga 0
447                 ldarga 0
448                 ldfld int32 Tests/TailCallStruct::a
449                 ldc.i4.1
450                 add
451                 stfld int32 Tests/TailCallStruct::a
452                 ldarga 0
453                 ldarga 0
454                 ldfld int32 Tests/TailCallStruct::a
455                 ldc.i4.2
456                 add
457                 stfld int32 Tests/TailCallStruct::a
458                 ldarg.0
459                 ret
460         }
461
462         .method static valuetype Tests/TailCallStruct tail2 (valuetype Tests/TailCallStruct arg) {
463                 ldarg.0
464                 tail.
465                 call valuetype Tests/TailCallStruct Tests::tail1 (valuetype Tests/TailCallStruct)
466                 ret
467         }
468
469         .method static public int32 test_0_tail_calls () il managed {
470                 .maxstack 16
471                 .locals init (
472                         valuetype Tests/TailCallStruct arg
473                 )
474                 ldloca 0
475                 ldc.i4.2
476                 stfld int32 Tests/TailCallStruct::a
477                 ldloca 0
478                 ldc.i4.4
479                 stfld int32 Tests/TailCallStruct::b
480                 ldloc.0
481                 call valuetype Tests/TailCallStruct Tests::tail2 (valuetype Tests/TailCallStruct)
482                 stloc.0
483                 ldloca 0
484                 ldfld int32 Tests/TailCallStruct::a
485                 ldloca 0
486                 ldfld int32 Tests/TailCallStruct::b
487                 add
488                 ldc.i4 9
489                 sub
490                 ret
491         }
492
493         .method static public int32 test_11_switch_with_nonempty_stack () il managed {
494                 .maxstack 16
495
496                 ldc.i4.5
497                 ldc.i4.6
498                 ldc.i4.1
499                 switch (L0, L1)
500         L0: 
501                 add
502                 ret
503         L1:
504                 add
505                 ret
506         }
507  
508     .method public static int32 test_5_endfinally_with_nonempty_stack () il managed {
509                 .maxstack 16
510
511         .try {
512           leave IL_0
513         }
514         finally  {
515           ldc.i4.0
516           endfinally
517         }
518         IL_0:  ldc.i4.5
519                 ret
520     }
521
522         .method public static int32 test_0_conv_ovf_i8_neg () il managed {
523                 .maxstack 16
524
525                 ldc.i4.m1
526                 conv.ovf.i8
527                 conv.i4
528                 ldc.i4.m1
529                 beq L_OK
530                 ldc.i4.1
531                 ret
532         L_OK:
533                 ldc.i4.0
534                 ret
535         }               
536
537         .method public static int32 test_0_get_type_from_handle_on_bblock_boundary () cil managed 
538         {
539                 .maxstack 16
540         
541                 ldc.i4.1
542                 brfalse OBJECT
543         
544                 ldtoken [mscorlib]System.String
545                 br AFTER
546         OBJECT:
547                 ldtoken [mscorlib]System.Object
548         AFTER:
549                 call class [mscorlib]'System.Type' class [mscorlib]'System.Type'::'GetTypeFromHandle'(valuetype [mscorlib]'System.RuntimeTypeHandle')
550                 callvirt instance string class [mscorlib]System.Type::get_FullName ()
551                 ldstr "System.String"
552                 callvirt instance bool class [mscorlib]System.Object::Equals(object)
553                 ldc.i4.0
554                 ceq
555                 ret 
556         }
557                 
558         .method public static int32 test_0_bug59580  ()
559         {
560                 ldc.r4          float32(0x7FC00000)
561                 ldc.r4          float32(0x7FC00000)
562                 bge.un          pass
563                 br              fail
564         pass:
565                 ldc.i4.0
566                 ret
567         fail:
568                 ldc.i4.1
569                 ret
570         }
571         
572         .method public static int32 test_1_bug60056  () {
573                 .locals init (int32 m5)
574                         
575                 ldc.i4.m1
576                 stloc.0
577                 
578                 ldc.i4.1
579                 conv.u8
580                 
581                 ldloc.0
582                 conv.i8
583                 mul
584                 
585                 ldc.i4.m1
586                 conv.i8
587                 ceq
588                 ret
589         }
590         
591         .method public static int32 test_1_conv_u8_cfold  () {
592                 ldc.i4.m1
593                 conv.u8
594                 
595                 ldc.i8 0x00000000ffffffff
596                 
597                 ceq
598                 ret
599         }
600         
601         .method public static int32 test_1_array_type_mismatch_ldelema  () {
602                 .locals init (int32 r)
603                 
604                         ldc.i4.1
605                         newarr string
606                         ldc.i4.0 
607                         ldelema string
608                         pop
609                 
610                 .try {
611                         ldc.i4.1
612                         newarr string
613                         ldc.i4.0 
614                         ldelema object
615                         pop
616                         
617                         leave end
618                 } catch [mscorlib]System.ArrayTypeMismatchException {
619                         pop
620                         ldc.i4.1
621                         stloc.0
622                         leave end
623                 }
624         end:
625                 ldloc.0
626                 ret
627         }
628
629         .method public static int32 test_1_conv_ovf_i8_with_i4 () {
630                         ldc.i4.m1 
631                         conv.ovf.i8
632                         conv.ovf.i4
633                         neg
634                         ret
635         }
636
637         // bug #72148
638     .method public static int32 test_0_initlocals_float_ptr () {
639         .maxstack 3
640         .locals init (
641                 float32[]       V_0,
642                 float32& pinned V_1,
643                 unsigned int32  V_2)
644                         ldc.i4.s 0x0f
645                         newarr [mscorlib]System.Single
646                         stloc.0 
647                         ldloc.0 
648                         ldc.i4.0 
649                         ldc.r4 1.13
650                         stelem.r4 
651                         ldloc.0 
652                         ldc.i4.0 
653                         ldelema [mscorlib]System.Single
654                         stloc.1 
655                         ldloc.1 
656                         conv.i 
657                         ldind.u4 
658                         stloc.2 
659                         ldc.i4.0
660                         ret
661         }
662
663         .class nested private auto ansi sealed beforefieldinit FooStruct 
664                 extends [mscorlib]System.ValueType {
665
666                 .method public hidebysig specialname rtspecialname instance void .ctor () cil managed {
667                         .maxstack 8
668                         ret
669                 }
670         }
671
672         .method public static int32 test_0_newobj_vtype () {
673                 .maxstack 8
674
675                 newobj instance void Tests/FooStruct::.ctor()
676                 pop
677                 ldc.i4.0
678                 ret
679         }
680
681 }