Fri May 14 14:28:22 CEST 2004 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / mini / iltests.il
1 .assembly iltests {}\r
2 .assembly extern TestDriver {}\r
3 .assembly extern mscorlib {}\r
4 \r
5 .class public auto ansi sealed beforefieldinit Tests {\r
6 \r
7         .method static public int32 Main() il managed {\r
8                 .entrypoint\r
9                 \r
10                 ldtoken Tests\r
11                 call       class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)\r
12                 call       int32 [TestDriver]TestDriver::RunTests(class [mscorlib]System.Type)\r
13                 ret\r
14         }\r
15 \r
16         // make sure the register allocator works when the return value of\r
17         // 'div' is discarded\r
18         .method static public int32 test_0_div_regalloc () il managed {\r
19                 .locals init (\r
20                         int32 i\r
21                 )\r
22 \r
23                 ldloc 0\r
24                 ldc.i4.s 0xa\r
25                 div\r
26                 pop\r
27                 ldc.i4.0\r
28                 ret\r
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         \r
233         .method static public int32 test_3_copy_used_bug () il managed {\r
234 \r
235                 .locals init (\r
236                         int32 size,\r
237                         int32 res\r
238                 )\r
239 \r
240                 ldc.i4 0\r
241                 stloc res\r
242 \r
243                 ldc.i4 1\r
244                 stloc size\r
245 \r
246                 ldloc size\r
247                 ldloc size\r
248                 ldloc size\r
249                 add\r
250                 stloc size\r
251                 ldloc size\r
252                 add\r
253                 stloc res\r
254 \r
255                 ldloc res\r
256                 ret\r
257         }\r
258 \r
259         // demonstrate that the copy_used_var is not a fix for the above bug\r
260         .method static public int32 test_3_copy_used_indir_bug () il managed {\r
261 \r
262                 .locals init (\r
263                         int32 size,\r
264                         int32 res\r
265                 )\r
266 \r
267                 ldc.i4 0\r
268                 stloc res\r
269 \r
270                 ldc.i4 1\r
271                 stloc size\r
272 \r
273                 ldloc size\r
274                 ldloca size\r
275                 ldloc size\r
276                 ldloc size\r
277                 add\r
278                 stind.i4\r
279                 ldloc size\r
280                 add\r
281                 stloc res\r
282 \r
283                 ldloc res\r
284                 ret\r
285         }\r
286 \r
287         .method static public void do_nothing (int32 a) il managed {\r
288                 ret\r
289         }\r
290         \r
291         // demonstrate the block_split failure: needs -O=inline\r
292         // mini -O=inline --compile Tests:test_0_split_block_bug iltests.exe\r
293         .method static public int32 test_0_split_block_bug () il managed {\r
294 \r
295                 .locals init (\r
296                         int32 i1\r
297                 )\r
298 \r
299                 ldc.i4 1\r
300                 stloc i1\r
301  test_label:\r
302                 ldloc i1\r
303                 call void class Tests::do_nothing (int32)\r
304                 ldc.i4 0\r
305                 brtrue test_label\r
306                 \r
307                 ldc.i4 0\r
308                 ret\r
309         }\r
310 \r
311         .method public void inline_do_nothing () il managed {\r
312                 ret\r
313         }\r
314         .method static public int32 test_1_checkthis_inlining () il managed {\r
315                 ldnull\r
316                 call instance void class Tests::inline_do_nothing ()\r
317                 ldc.i4 1\r
318                 ret\r
319         }\r
320 \r
321         .class nested private auto ansi sealed beforefieldinit TailCallStruct \r
322                 extends [mscorlib]System.ValueType {\r
323                 .field public int32 a\r
324                 .field public int32 b\r
325         }\r
326 \r
327         .method static valuetype Tests/TailCallStruct tail1 (valuetype Tests/TailCallStruct arg) {\r
328                 ldarga 0\r
329                 ldarga 0\r
330                 ldfld int32 Tests/TailCallStruct::a\r
331                 ldc.i4.1\r
332                 add\r
333                 stfld int32 Tests/TailCallStruct::a\r
334                 ldarga 0\r
335                 ldarga 0\r
336                 ldfld int32 Tests/TailCallStruct::a\r
337                 ldc.i4.2\r
338                 add\r
339                 stfld int32 Tests/TailCallStruct::a\r
340                 ldarg.0\r
341                 ret\r
342         }\r
343 \r
344         .method static valuetype Tests/TailCallStruct tail2 (valuetype Tests/TailCallStruct arg) {\r
345                 ldarg.0\r
346                 tail.\r
347                 call valuetype Tests/TailCallStruct Tests::tail1 (valuetype Tests/TailCallStruct)\r
348                 ret\r
349         }\r
350 \r
351         .method static public int32 test_0_tail_calls () il managed {\r
352                 .maxstack 16\r
353                 .locals init (\r
354                         valuetype Tests/TailCallStruct arg\r
355                 )\r
356                 ldloca 0\r
357                 ldc.i4.2\r
358                 stfld int32 Tests/TailCallStruct::a\r
359                 ldloca 0\r
360                 ldc.i4.4\r
361                 stfld int32 Tests/TailCallStruct::b\r
362                 ldloc.0\r
363                 call valuetype Tests/TailCallStruct Tests::tail2 (valuetype Tests/TailCallStruct)\r
364                 stloc.0\r
365                 ldloca 0\r
366                 ldfld int32 Tests/TailCallStruct::a\r
367                 ldloca 0\r
368                 ldfld int32 Tests/TailCallStruct::b\r
369                 add\r
370                 ldc.i4 9\r
371                 sub\r
372                 ret\r
373         }\r
374 \r
375         .method static public int32 test_11_switch_with_nonempty_stack () il managed {\r
376                 .maxstack 16\r
377 \r
378                 ldc.i4.5\r
379                 ldc.i4.6\r
380                 ldc.i4.1\r
381                 switch (L0, L1)\r
382         L0: \r
383                 add\r
384                 ret\r
385         L1:\r
386                 add\r
387                 ret\r
388         }\r
389  \r
390     .method public static int32 test_5_endfinally_with_nonempty_stack () il managed {\r
391                 .maxstack 16\r
392 \r
393         .try {\r
394           leave IL_0\r
395         }\r
396         finally  {\r
397           ldc.i4.0\r
398           endfinally\r
399         }\r
400         IL_0:  ldc.i4.5\r
401                 ret\r
402     }\r
403 \r
404         .method public static int32 test_0_conv_ovf_i8_neg () il managed {\r
405                 .maxstack 16\r
406 \r
407                 ldc.i4.m1\r
408                 conv.ovf.i8\r
409                 conv.i4\r
410                 ldc.i4.m1\r
411                 beq L_OK\r
412                 ldc.i4.1\r
413                 ret\r
414         L_OK:\r
415                 ldc.i4.0\r
416                 ret\r
417         }               \r
418                 \r
419 }\r