This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[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_3_copy_used_bug () il managed {
234
235                 .locals init (
236                         int32 size,
237                         int32 res
238                 )
239
240                 ldc.i4 0
241                 stloc res
242
243                 ldc.i4 1
244                 stloc size
245
246                 ldloc size
247                 ldloc size
248                 ldloc size
249                 add
250                 stloc size
251                 ldloc size
252                 add
253                 stloc res
254
255                 ldloc res
256                 ret
257         }
258
259         // demonstrate that the copy_used_var is not a fix for the above bug
260         .method static public int32 test_3_copy_used_indir_bug () il managed {
261
262                 .locals init (
263                         int32 size,
264                         int32 res
265                 )
266
267                 ldc.i4 0
268                 stloc res
269
270                 ldc.i4 1
271                 stloc size
272
273                 ldloc size
274                 ldloca size
275                 ldloc size
276                 ldloc size
277                 add
278                 stind.i4
279                 ldloc size
280                 add
281                 stloc res
282
283                 ldloc res
284                 ret
285         }
286
287         .method static public void do_nothing (int32 a) il managed {
288                 ret
289         }
290         
291         // demonstrate the block_split failure: needs -O=inline
292         // mini -O=inline --compile Tests:test_0_split_block_bug iltests.exe
293         .method static public int32 test_0_split_block_bug () il managed {
294
295                 .locals init (
296                         int32 i1
297                 )
298
299                 ldc.i4 1
300                 stloc i1
301  test_label:
302                 ldloc i1
303                 call void class Tests::do_nothing (int32)
304                 ldc.i4 0
305                 brtrue test_label
306                 
307                 ldc.i4 0
308                 ret
309         }
310
311         .method public void inline_do_nothing () il managed {
312                 ret
313         }
314         .method static public int32 test_1_checkthis_inlining () il managed {
315                 ldnull
316                 call instance void class Tests::inline_do_nothing ()
317                 ldc.i4 1
318                 ret
319         }
320
321         .class nested private auto ansi sealed beforefieldinit TailCallStruct 
322                 extends [mscorlib]System.ValueType {
323                 .field public int32 a
324                 .field public int32 b
325         }
326
327         .method static valuetype Tests/TailCallStruct tail1 (valuetype Tests/TailCallStruct arg) {
328                 ldarga 0
329                 ldarga 0
330                 ldfld int32 Tests/TailCallStruct::a
331                 ldc.i4.1
332                 add
333                 stfld int32 Tests/TailCallStruct::a
334                 ldarga 0
335                 ldarga 0
336                 ldfld int32 Tests/TailCallStruct::a
337                 ldc.i4.2
338                 add
339                 stfld int32 Tests/TailCallStruct::a
340                 ldarg.0
341                 ret
342         }
343
344         .method static valuetype Tests/TailCallStruct tail2 (valuetype Tests/TailCallStruct arg) {
345                 ldarg.0
346                 tail.
347                 call valuetype Tests/TailCallStruct Tests::tail1 (valuetype Tests/TailCallStruct)
348                 ret
349         }
350
351         .method static public int32 test_0_tail_calls () il managed {
352                 .maxstack 16
353                 .locals init (
354                         valuetype Tests/TailCallStruct arg
355                 )
356                 ldloca 0
357                 ldc.i4.2
358                 stfld int32 Tests/TailCallStruct::a
359                 ldloca 0
360                 ldc.i4.4
361                 stfld int32 Tests/TailCallStruct::b
362                 ldloc.0
363                 call valuetype Tests/TailCallStruct Tests::tail2 (valuetype Tests/TailCallStruct)
364                 stloc.0
365                 ldloca 0
366                 ldfld int32 Tests/TailCallStruct::a
367                 ldloca 0
368                 ldfld int32 Tests/TailCallStruct::b
369                 add
370                 ldc.i4 9
371                 sub
372                 ret
373         }
374
375         .method static public int32 test_11_switch_with_nonempty_stack () il managed {
376                 .maxstack 16
377
378                 ldc.i4.5
379                 ldc.i4.6
380                 ldc.i4.1
381                 switch (L0, L1)
382         L0: 
383                 add
384                 ret
385         L1:
386                 add
387                 ret
388         }
389  
390     .method public static int32 test_5_endfinally_with_nonempty_stack () il managed {
391                 .maxstack 16
392
393         .try {
394           leave IL_0
395         }
396         finally  {
397           ldc.i4.0
398           endfinally
399         }
400         IL_0:  ldc.i4.5
401                 ret
402     }
403
404         .method public static int32 test_0_conv_ovf_i8_neg () il managed {
405                 .maxstack 16
406
407                 ldc.i4.m1
408                 conv.ovf.i8
409                 conv.i4
410                 ldc.i4.m1
411                 beq L_OK
412                 ldc.i4.1
413                 ret
414         L_OK:
415                 ldc.i4.0
416                 ret
417         }               
418
419         .method public static int32 test_0_get_type_from_handle_on_bblock_boundary () cil managed 
420         {
421                 .entrypoint
422                 .maxstack 16
423         
424                 ldc.i4.1
425                 brfalse OBJECT
426         
427                 ldtoken [mscorlib]System.String
428                 br AFTER
429         OBJECT:
430                 ldtoken [mscorlib]System.Object
431         AFTER:
432                 call class [mscorlib]'System.Type' class [mscorlib]'System.Type'::'GetTypeFromHandle'(valuetype [mscorlib]'System.RuntimeTypeHandle')
433                 callvirt string class [mscorlib]System.Type::get_FullName ()
434                 ldstr "System.String"
435                 callvirt bool class [mscorlib]System.Object::Equals(object)
436                 ldc.i4.0
437                 ceq
438                 ret 
439         }
440                 
441         .method public static int32 test_0_bug59580  ()
442         {
443                 ldc.r4          float32(0x7FC00000)
444                 ldc.r4          float32(0x7FC00000)
445                 bge.un          pass
446                 br              fail
447         pass:
448                 ldc.i4.0
449                 ret
450         fail:
451                 ldc.i4.1
452                 ret
453         }
454         
455         .method public static int32 test_1_bug60056  () {
456                 .locals init (int32 m5)
457                         
458                 ldc.i4.m1
459                 stloc.0
460                 
461                 ldc.i4.1
462                 conv.u8
463                 
464                 ldloc.0
465                 conv.i8
466                 mul
467                 
468                 ldc.i4.m1
469                 conv.i8
470                 ceq
471                 ret
472         }
473 }