2004-11-24 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() il managed {
8                 .entrypoint
9                 
10                 ldtoken Tests
11                 call       class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
12                 call       int32 [TestDriver]TestDriver::RunTests(class [mscorlib]System.Type)
13                 ret
14         }
15
16         // make sure the register allocator works when the return value of
17         // 'div' is discarded
18         .method static public int32 test_0_div_regalloc () il managed {
19                 .locals init (
20                         int32 i
21                 )
22
23                 ldloc 0
24                 ldc.i4.s 0xa
25                 div
26                 pop
27                 ldc.i4.0
28                 ret
29         }
30         
31         
32         .method static public int32 test_1_ceq_to_i4 () il managed {
33                 .locals init (
34                         int32   foo
35                 )
36                 ldc.i4 500
37                 stloc foo
38                 ldloc foo
39                 ldc.i4 500
40                 ceq
41                 stloc foo
42                 ldloc foo
43                 ret
44         }
45         
46         .method static public int32 test_3_shl_regvars () il managed {
47                 .locals init (
48                         int32   a,
49                         int32   b,
50                         int32   r1,
51                         int32   r2,
52                         int32   r3
53                 )
54                         
55                 ldc.i4.2
56                 stloc      a
57                 ldc.i4.1
58                 stloc      b
59         
60                 ldloc      a
61                 ldloc      b
62                 shl 
63                 stloc      r1
64                 
65                 ldloc      a
66                 ldloc      b
67                 shl 
68                 stloc      r2
69                 
70                 ldloc      a
71                 ldloc      b
72                 shl 
73                 stloc      r3
74                 
75                 ldloc      r1
76                 ldc.i4.4
77                 ceq
78                 
79                 ldloc      r2
80                 ldc.i4.4
81                 ceq
82                 
83                 ldloc      r3
84                 ldc.i4.4
85                 ceq
86                 
87                 add
88                 add
89                 
90                 ret
91         }
92         
93         .method static public int32 test_1_fceq_to_i4 () il managed {
94         
95                 .locals init (
96                         float64 foo,
97                         int32   val
98                 )
99
100                 ldc.r8      2
101                 stloc       foo
102                 
103                 ldloc       foo
104                 ldc.r8      2
105                 ceq
106                 stloc       val
107                 
108                 ldloc       val
109                 ret
110         }
111
112         //
113         // This should be manually checked. Basically under -O=linears,
114         // you should not see tons of register spilling.
115         //
116         .method static public int32 test_1_bytedreg_free () il managed {
117                 .locals init (
118                         int32   foo
119                 )
120                 ldc.i4 500
121                 stloc foo
122                 ldloc foo
123                 ldc.i4 500
124                 ceq
125                 stloc foo
126                 
127                 ldloc foo
128                 ldc.i4 1
129                 ceq
130                 stloc foo
131
132                 ldloc foo
133                 ldc.i4 1
134                 ceq
135                 stloc foo
136
137                 ldloc foo
138                 ldc.i4 1
139                 ceq
140                 stloc foo
141                 
142                 ldloc foo
143                 ldc.i4 1
144                 ceq
145                 stloc foo
146                 
147                 ldloc foo
148                 ret
149         }
150         
151         //
152         // This should be manually checked. Basically under -O=linears,
153         // you should not see tons of register spilling.
154         //
155         .method static public int32 test_0_bytesreg1_free () il managed {
156                 .locals init (
157                         unsigned int8      dest,
158                         int32              src,
159                         unsigned int8&     pdest
160                 )
161
162                 ldloca     dest
163                 stloc      pdest
164                 
165                 ldloc      pdest
166                 ldloc      src
167                 stind.i1
168                 
169                 ldloc      pdest
170                 ldloc      src
171                 stind.i1
172                 
173                 ldloc      pdest
174                 ldloc      src
175                 stind.i1
176                 
177                 ldloc      pdest
178                 ldloc      src
179                 stind.i1
180                 
181                 ldloc      pdest
182                 ldloc      src
183                 stind.i1
184                 
185                 ldloc      pdest
186                 ldloc      src
187                 stind.i1
188                 
189                 ldloc      pdest
190                 ldind.i1
191                 ret
192         }
193         
194         .method static public int32 test_1_shift_regvar () il managed {
195         
196                 .locals init (
197                         int32   v7FFFFFFF,
198                         int32   v1
199                 )
200                 
201                 ldc.i4  0x7FFFFFFF
202                 stloc   v7FFFFFFF
203         
204                 ldc.i4.1
205                 stloc v1
206                 
207                 ldloc   v7FFFFFFF
208                 ldloc   v1
209                 shl
210                 ldc.i4  0xFFFFFFFE
211                 ceq
212                 ret
213         }
214         
215         // this only happens with the managed pointer, not an unmanaged one.
216         .method static public int32 test_0_foo () il managed {
217         
218                 .locals init (
219                         int32&  buf
220                 )
221                 
222                 ldc.i4.5
223                 localloc
224                 
225                 stloc buf
226                 ldloc buf
227                 
228                 ldind.i4
229                 
230                 ret
231         }
232
233         .method static public int32 test_0_localloc () cil managed {
234                 .locals init (native int, native int, native int)
235
236                 ldc.i4 6
237                 localloc
238                 conv.i
239                 stloc.0
240
241                 ldc.i4 6
242                 localloc
243                 conv.i
244                 stloc.1
245
246                 ldc.i4 6
247                 localloc
248                 conv.i
249                 stloc.2
250
251                 // br OK1
252                 ldloc.1
253                 ldc.i4 999999
254                 stind.i4
255                 ldloc.1
256                 ldind.i4
257                 ldc.i4 999999
258                 beq OK1
259                 br FAIL
260
261 OK1:
262                 ldloc.0
263                 ldc.i4 999999
264                 stind.i4
265                 ldloc.0
266                 ldind.i4
267                 ldc.i4 999999
268                 beq PASS
269
270 FAIL:   ldc.i4.1
271                 ret
272
273 PASS:   ldc.i4.0
274                 ret
275         }
276
277     .method private static void do_localloc () cil managed {
278         .maxstack 3
279         .locals init (
280                 unsigned int8*  V_0)
281         IL_0000:  ldc.i4.1
282         IL_0001:  ldc.i4 131072
283         IL_0006:  mul
284         IL_0007:  localloc
285         IL_0009:  stloc.0
286         IL_000a:  ret
287     }
288
289         // Check that localloc can't be inlined
290         .method static public int32 test_0_localloc_inline () cil managed {
291                 .maxstack 16
292                 .locals init (
293                         int32 i
294                 )
295
296                 ldc.i4.0
297         stloc.0
298         br COND
299
300 START:  call void class Tests::do_localloc()
301         ldloc.0
302         ldc.i4.1
303         add
304         stloc.0
305 COND:   ldloc.0
306         ldc.i4 1000
307         blt START
308
309                 ldc.i4.0
310                 ret
311         }       
312         
313         .method static public int32 test_3_copy_used_bug () il managed {
314
315                 .locals init (
316                         int32 size,
317                         int32 res
318                 )
319
320                 ldc.i4 0
321                 stloc res
322
323                 ldc.i4 1
324                 stloc size
325
326                 ldloc size
327                 ldloc size
328                 ldloc size
329                 add
330                 stloc size
331                 ldloc size
332                 add
333                 stloc res
334
335                 ldloc res
336                 ret
337         }
338
339         // demonstrate that the copy_used_var is not a fix for the above bug
340         .method static public int32 test_3_copy_used_indir_bug () il managed {
341
342                 .locals init (
343                         int32 size,
344                         int32 res
345                 )
346
347                 ldc.i4 0
348                 stloc res
349
350                 ldc.i4 1
351                 stloc size
352
353                 ldloc size
354                 ldloca size
355                 ldloc size
356                 ldloc size
357                 add
358                 stind.i4
359                 ldloc size
360                 add
361                 stloc res
362
363                 ldloc res
364                 ret
365         }
366
367         .method static public void do_nothing (int32 a) il managed {
368                 ret
369         }
370         
371         // demonstrate the block_split failure: needs -O=inline
372         // mini -O=inline --compile Tests:test_0_split_block_bug iltests.exe
373         .method static public int32 test_0_split_block_bug () il managed {
374
375                 .locals init (
376                         int32 i1
377                 )
378
379                 ldc.i4 1
380                 stloc i1
381  test_label:
382                 ldloc i1
383                 call void class Tests::do_nothing (int32)
384                 ldc.i4 0
385                 brtrue test_label
386                 
387                 ldc.i4 0
388                 ret
389         }
390
391         .method public void inline_do_nothing () il managed {
392                 ret
393         }
394         .method static public int32 test_1_checkthis_inlining () il managed {
395                 ldnull
396                 call instance void class Tests::inline_do_nothing ()
397                 ldc.i4 1
398                 ret
399         }
400
401         .class nested private auto ansi sealed beforefieldinit TailCallStruct 
402                 extends [mscorlib]System.ValueType {
403                 .field public int32 a
404                 .field public int32 b
405         }
406
407         .method static valuetype Tests/TailCallStruct tail1 (valuetype Tests/TailCallStruct arg) {
408                 ldarga 0
409                 ldarga 0
410                 ldfld int32 Tests/TailCallStruct::a
411                 ldc.i4.1
412                 add
413                 stfld int32 Tests/TailCallStruct::a
414                 ldarga 0
415                 ldarga 0
416                 ldfld int32 Tests/TailCallStruct::a
417                 ldc.i4.2
418                 add
419                 stfld int32 Tests/TailCallStruct::a
420                 ldarg.0
421                 ret
422         }
423
424         .method static valuetype Tests/TailCallStruct tail2 (valuetype Tests/TailCallStruct arg) {
425                 ldarg.0
426                 tail.
427                 call valuetype Tests/TailCallStruct Tests::tail1 (valuetype Tests/TailCallStruct)
428                 ret
429         }
430
431         .method static public int32 test_0_tail_calls () il managed {
432                 .maxstack 16
433                 .locals init (
434                         valuetype Tests/TailCallStruct arg
435                 )
436                 ldloca 0
437                 ldc.i4.2
438                 stfld int32 Tests/TailCallStruct::a
439                 ldloca 0
440                 ldc.i4.4
441                 stfld int32 Tests/TailCallStruct::b
442                 ldloc.0
443                 call valuetype Tests/TailCallStruct Tests::tail2 (valuetype Tests/TailCallStruct)
444                 stloc.0
445                 ldloca 0
446                 ldfld int32 Tests/TailCallStruct::a
447                 ldloca 0
448                 ldfld int32 Tests/TailCallStruct::b
449                 add
450                 ldc.i4 9
451                 sub
452                 ret
453         }
454
455         .method static public int32 test_11_switch_with_nonempty_stack () il managed {
456                 .maxstack 16
457
458                 ldc.i4.5
459                 ldc.i4.6
460                 ldc.i4.1
461                 switch (L0, L1)
462         L0: 
463                 add
464                 ret
465         L1:
466                 add
467                 ret
468         }
469  
470     .method public static int32 test_5_endfinally_with_nonempty_stack () il managed {
471                 .maxstack 16
472
473         .try {
474           leave IL_0
475         }
476         finally  {
477           ldc.i4.0
478           endfinally
479         }
480         IL_0:  ldc.i4.5
481                 ret
482     }
483
484         .method public static int32 test_0_conv_ovf_i8_neg () il managed {
485                 .maxstack 16
486
487                 ldc.i4.m1
488                 conv.ovf.i8
489                 conv.i4
490                 ldc.i4.m1
491                 beq L_OK
492                 ldc.i4.1
493                 ret
494         L_OK:
495                 ldc.i4.0
496                 ret
497         }               
498
499         .method public static int32 test_0_get_type_from_handle_on_bblock_boundary () cil managed 
500         {
501                 .entrypoint
502                 .maxstack 16
503         
504                 ldc.i4.1
505                 brfalse OBJECT
506         
507                 ldtoken [mscorlib]System.String
508                 br AFTER
509         OBJECT:
510                 ldtoken [mscorlib]System.Object
511         AFTER:
512                 call class [mscorlib]'System.Type' class [mscorlib]'System.Type'::'GetTypeFromHandle'(valuetype [mscorlib]'System.RuntimeTypeHandle')
513                 callvirt string class [mscorlib]System.Type::get_FullName ()
514                 ldstr "System.String"
515                 callvirt bool class [mscorlib]System.Object::Equals(object)
516                 ldc.i4.0
517                 ceq
518                 ret 
519         }
520                 
521         .method public static int32 test_0_bug59580  ()
522         {
523                 ldc.r4          float32(0x7FC00000)
524                 ldc.r4          float32(0x7FC00000)
525                 bge.un          pass
526                 br              fail
527         pass:
528                 ldc.i4.0
529                 ret
530         fail:
531                 ldc.i4.1
532                 ret
533         }
534         
535         .method public static int32 test_1_bug60056  () {
536                 .locals init (int32 m5)
537                         
538                 ldc.i4.m1
539                 stloc.0
540                 
541                 ldc.i4.1
542                 conv.u8
543                 
544                 ldloc.0
545                 conv.i8
546                 mul
547                 
548                 ldc.i4.m1
549                 conv.i8
550                 ceq
551                 ret
552         }
553         
554         .method public static int32 test_1_conv_u8_cfold  () {
555                 ldc.i4.m1
556                 conv.u8
557                 
558                 ldc.i8 0x00000000ffffffff
559                 
560                 ceq
561                 ret
562         }
563 }