2004-08-08 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 static public int32 test_3_copy_used_bug () il managed {
278
279                 .locals init (
280                         int32 size,
281                         int32 res
282                 )
283
284                 ldc.i4 0
285                 stloc res
286
287                 ldc.i4 1
288                 stloc size
289
290                 ldloc size
291                 ldloc size
292                 ldloc size
293                 add
294                 stloc size
295                 ldloc size
296                 add
297                 stloc res
298
299                 ldloc res
300                 ret
301         }
302
303         // demonstrate that the copy_used_var is not a fix for the above bug
304         .method static public int32 test_3_copy_used_indir_bug () il managed {
305
306                 .locals init (
307                         int32 size,
308                         int32 res
309                 )
310
311                 ldc.i4 0
312                 stloc res
313
314                 ldc.i4 1
315                 stloc size
316
317                 ldloc size
318                 ldloca size
319                 ldloc size
320                 ldloc size
321                 add
322                 stind.i4
323                 ldloc size
324                 add
325                 stloc res
326
327                 ldloc res
328                 ret
329         }
330
331         .method static public void do_nothing (int32 a) il managed {
332                 ret
333         }
334         
335         // demonstrate the block_split failure: needs -O=inline
336         // mini -O=inline --compile Tests:test_0_split_block_bug iltests.exe
337         .method static public int32 test_0_split_block_bug () il managed {
338
339                 .locals init (
340                         int32 i1
341                 )
342
343                 ldc.i4 1
344                 stloc i1
345  test_label:
346                 ldloc i1
347                 call void class Tests::do_nothing (int32)
348                 ldc.i4 0
349                 brtrue test_label
350                 
351                 ldc.i4 0
352                 ret
353         }
354
355         .method public void inline_do_nothing () il managed {
356                 ret
357         }
358         .method static public int32 test_1_checkthis_inlining () il managed {
359                 ldnull
360                 call instance void class Tests::inline_do_nothing ()
361                 ldc.i4 1
362                 ret
363         }
364
365         .class nested private auto ansi sealed beforefieldinit TailCallStruct 
366                 extends [mscorlib]System.ValueType {
367                 .field public int32 a
368                 .field public int32 b
369         }
370
371         .method static valuetype Tests/TailCallStruct tail1 (valuetype Tests/TailCallStruct arg) {
372                 ldarga 0
373                 ldarga 0
374                 ldfld int32 Tests/TailCallStruct::a
375                 ldc.i4.1
376                 add
377                 stfld int32 Tests/TailCallStruct::a
378                 ldarga 0
379                 ldarga 0
380                 ldfld int32 Tests/TailCallStruct::a
381                 ldc.i4.2
382                 add
383                 stfld int32 Tests/TailCallStruct::a
384                 ldarg.0
385                 ret
386         }
387
388         .method static valuetype Tests/TailCallStruct tail2 (valuetype Tests/TailCallStruct arg) {
389                 ldarg.0
390                 tail.
391                 call valuetype Tests/TailCallStruct Tests::tail1 (valuetype Tests/TailCallStruct)
392                 ret
393         }
394
395         .method static public int32 test_0_tail_calls () il managed {
396                 .maxstack 16
397                 .locals init (
398                         valuetype Tests/TailCallStruct arg
399                 )
400                 ldloca 0
401                 ldc.i4.2
402                 stfld int32 Tests/TailCallStruct::a
403                 ldloca 0
404                 ldc.i4.4
405                 stfld int32 Tests/TailCallStruct::b
406                 ldloc.0
407                 call valuetype Tests/TailCallStruct Tests::tail2 (valuetype Tests/TailCallStruct)
408                 stloc.0
409                 ldloca 0
410                 ldfld int32 Tests/TailCallStruct::a
411                 ldloca 0
412                 ldfld int32 Tests/TailCallStruct::b
413                 add
414                 ldc.i4 9
415                 sub
416                 ret
417         }
418
419         .method static public int32 test_11_switch_with_nonempty_stack () il managed {
420                 .maxstack 16
421
422                 ldc.i4.5
423                 ldc.i4.6
424                 ldc.i4.1
425                 switch (L0, L1)
426         L0: 
427                 add
428                 ret
429         L1:
430                 add
431                 ret
432         }
433  
434     .method public static int32 test_5_endfinally_with_nonempty_stack () il managed {
435                 .maxstack 16
436
437         .try {
438           leave IL_0
439         }
440         finally  {
441           ldc.i4.0
442           endfinally
443         }
444         IL_0:  ldc.i4.5
445                 ret
446     }
447
448         .method public static int32 test_0_conv_ovf_i8_neg () il managed {
449                 .maxstack 16
450
451                 ldc.i4.m1
452                 conv.ovf.i8
453                 conv.i4
454                 ldc.i4.m1
455                 beq L_OK
456                 ldc.i4.1
457                 ret
458         L_OK:
459                 ldc.i4.0
460                 ret
461         }               
462
463         .method public static int32 test_0_get_type_from_handle_on_bblock_boundary () cil managed 
464         {
465                 .entrypoint
466                 .maxstack 16
467         
468                 ldc.i4.1
469                 brfalse OBJECT
470         
471                 ldtoken [mscorlib]System.String
472                 br AFTER
473         OBJECT:
474                 ldtoken [mscorlib]System.Object
475         AFTER:
476                 call class [mscorlib]'System.Type' class [mscorlib]'System.Type'::'GetTypeFromHandle'(valuetype [mscorlib]'System.RuntimeTypeHandle')
477                 callvirt string class [mscorlib]System.Type::get_FullName ()
478                 ldstr "System.String"
479                 callvirt bool class [mscorlib]System.Object::Equals(object)
480                 ldc.i4.0
481                 ceq
482                 ret 
483         }
484                 
485         .method public static int32 test_0_bug59580  ()
486         {
487                 ldc.r4          float32(0x7FC00000)
488                 ldc.r4          float32(0x7FC00000)
489                 bge.un          pass
490                 br              fail
491         pass:
492                 ldc.i4.0
493                 ret
494         fail:
495                 ldc.i4.1
496                 ret
497         }
498         
499         .method public static int32 test_1_bug60056  () {
500                 .locals init (int32 m5)
501                         
502                 ldc.i4.m1
503                 stloc.0
504                 
505                 ldc.i4.1
506                 conv.u8
507                 
508                 ldloc.0
509                 conv.i8
510                 mul
511                 
512                 ldc.i4.m1
513                 conv.i8
514                 ceq
515                 ret
516         }
517 }