b700efa87e39503de0291560b09a388d4600241e
[mono.git] / mono / mini / basic.cs
1 using System;
2 using System.Reflection;
3
4 /*
5  * Regression tests for the mono JIT.
6  *
7  * Each test needs to be of the form:
8  *
9  * static int test_<result>_<name> ();
10  *
11  * where <result> is an integer (the value that needs to be returned by
12  * the method to make it pass.
13  * <name> is a user-displayed name used to identify the test.
14  *
15  * The tests can be driven in two ways:
16  * *) running the program directly: Main() uses reflection to find and invoke
17  *      the test methods (this is useful mostly to check that the tests are correct)
18  * *) with the --regression switch of the jit (this is the preferred way since
19  *      all the tests will be run with optimizations on and off)
20  *
21  * The reflection logic could be moved to a .dll since we need at least another
22  * regression test file written in IL code to have better control on how
23  * the IL code looks.
24  */
25
26 class Tests {
27
28         static int Main () {
29                 return TestDriver.RunTests (typeof (Tests));
30         }
31         
32         public static int test_0_return () {
33                 return 0;
34         }
35
36         public static int test_100000_return_large () {
37                 return 100000;
38         }
39
40         public static int test_1_load_bool () {
41                 bool a = true;
42                 return a? 1: 0;
43         }
44
45         public static int test_0_load_bool_false () {
46                 bool a = false;
47                 return a? 1: 0;
48         }
49
50         public static int test_200_load_byte () {
51                 byte a = 200;
52                 return a;
53         }
54
55         public static int test_100_load_sbyte () {
56                 sbyte a = 100;
57                 return a;
58         }
59
60         public static int test_200_load_short () {
61                 short a = 200;
62                 return a;
63         }
64
65         public static int test_100_load_ushort () {
66                 ushort a = 100;
67                 return a;
68         }
69
70         public static int test_3_add_simple () {
71                 int a = 1; 
72                 int b = 2;
73                 return a + b;
74         }
75
76         public static int test_3_add_imm () {
77                 int a = 1; 
78                 return a + 2;
79         }
80
81         public static int test_13407573_add_largeimm () {
82                 int a = 1; 
83                 return a + 13407572;
84         }
85
86         public static int test_1_sub_simple () {
87                 int a = 1; 
88                 int b = 2;
89                 return b - a;
90         }
91
92         public static int test_1_sub_simple_un () {
93                 uint a = 1; 
94                 uint b = 2;
95                 return (int)(b - a);
96         }
97
98         public static int test_1_sub_imm () {
99                 int b = 2;
100                 return b - 1;
101         }
102
103         public static int test_2_sub_large_imm () {
104                 int b = 0xff0f0f;
105                 return b - 0xff0f0d;
106         }
107
108         public static int test_0_sub_inv_imm () {
109                 int b = 2;
110                 return 2 - b;
111         }
112
113         public static int test_2_and () {
114                 int b = 2;
115                 int a = 3;
116                 return b & a;
117         }
118
119         public static int test_0_and_imm () {
120                 int b = 2;
121                 return b & 0x10;
122         }
123
124         public static int test_0_and_large_imm () {
125                 int b = 2;
126                 return b & 0x10000000;
127         }
128
129         public static int test_0_and_large_imm2 () {
130                 int b = 2;
131                 return b & 0x100000f0;
132         }
133
134         public static int test_2_div () {
135                 int b = 6;
136                 int a = 3;
137                 return b / a;
138         }
139
140         public static int test_4_div_imm () {
141                 int b = 12;
142                 return b / 3;
143         }
144
145         public static int test_4_divun_imm () {
146                 uint b = 12;
147                 return (int)(b / 3);
148         }
149
150         public static int test_0_div_fold () {
151                 int b = -1;
152                 return b / 2;
153         }
154
155         public static int test_2_div_fold4 () {
156                 int b = -8;
157                 return -(b / 4);
158         }
159
160         public static int test_2_div_fold16 () {
161                 int b = 32;
162                 return b / 16;
163         }
164
165         public static int test_719177_div_destreg () {
166                 int year = 1970;
167                 return ((365* (year-1)) + ((year-1)/4));
168         }
169
170         public static int test_1_remun_imm () {
171                 uint b = 13;
172                 return (int)(b % 3);
173         }
174
175         public static int test_2_bigremun_imm () {
176                 unchecked {
177                         uint b = (uint)-2;
178                         return (int)(b % 3);
179                 }
180         }
181
182         public static int test_2_rem () {
183                 int b = 5;
184                 int a = 3;
185                 return b % a;
186         }
187
188         public static int test_4_rem_imm () {
189                 int b = 12;
190                 return b % 8;
191         }
192
193         public static int test_0_rem_imm_0 () {
194                 int b = 12;
195                 return b % 1;
196         }
197
198         public static int test_0_rem_imm_0_neg () {
199                 int b = -2;
200                 return b % 1;
201         }
202
203         public static int test_4_rem_big_imm () {
204                 int b = 10004;
205                 return b % 10000;
206         }
207
208         public static int test_9_mul () {
209                 int b = 3;
210                 int a = 3;
211                 return b * a;
212         }
213
214         public static int test_15_mul_imm () {
215                 int b = 3;
216                 return b * 5;
217         }
218
219         public static int test_24_mul () {
220                 int a = 3;
221                 int b = 8;
222                 int res;
223
224                 res = a * b;
225                 
226                 return res;
227         }
228
229         public static int test_24_mul_ovf () {
230                 int a = 3;
231                 int b = 8;
232                 int res;
233
234                 checked {
235                         res = a * b;
236                 }
237                 
238                 return res;
239         }
240
241         public static int test_24_mul_un () {
242                 uint a = 3;
243                 uint b = 8;
244                 uint res;
245
246                 res = a * b;
247                 
248                 return (int)res;
249         }
250
251         public static int test_24_mul_ovf_un () {
252                 uint a = 3;
253                 uint b = 8;
254                 uint res;
255
256                 checked {
257                         res = a * b;
258                 }
259                 
260                 return (int)res;
261         }
262
263         public static int test_0_add_ovf1 () {
264                 int i, j, k;
265
266                 checked {
267                         i = System.Int32.MinValue;
268                         j = 0;
269                         k = i + j;
270                 }
271
272                 if (k != System.Int32.MinValue)
273                         return 1;
274                 return 0;
275         }
276
277         public static int test_0_add_ovf2 () {
278                 int i, j, k;
279
280                 checked {
281                         i = System.Int32.MaxValue;
282                         j = 0;
283                         k = i + j;
284                 }
285
286                 if (k != System.Int32.MaxValue)
287                         return 2;
288                 return 0;
289         }
290
291         public static int test_0_add_ovf3 () {
292                 int i, j, k;
293
294                 checked {
295                         i = System.Int32.MinValue;
296                         j = System.Int32.MaxValue;
297                         k = i + j;
298                 }
299
300                 if (k != -1)
301                         return 3;
302                 return 0;
303         }
304
305         public static int test_0_add_ovf4 () {
306                 int i, j, k;
307
308                 checked {
309                         i = System.Int32.MaxValue;
310                         j = System.Int32.MinValue;
311                         k = i + j;
312                 }
313
314                 if (k != -1)
315                         return 4;
316                 return 0;
317         }
318
319         public static int test_0_add_ovf5 () {
320                 int i, j, k;
321
322                 checked {
323                         i = System.Int32.MinValue + 1234;
324                         j = -1234;
325                         k = i + j;
326                 }
327
328                 if (k != System.Int32.MinValue)
329                         return 5;
330                 return 0;
331         }
332
333         public static int test_0_add_ovf6 () {
334                 int i, j, k;
335
336                 checked {
337                         i = System.Int32.MaxValue - 1234;
338                         j = 1234;
339                         k = i + j;
340                 }
341
342                 if (k != System.Int32.MaxValue)
343                         return 6;
344
345                 return 0;
346         }
347
348         public static int test_0_add_un_ovf () {
349                 uint n = (uint)134217728 * 16;
350                 uint number = checked (n + (uint)0);
351
352                 return number == n ? 0 : 1;
353         }
354
355         public static int test_0_sub_ovf1 () {
356                 int i, j, k;
357
358                 checked {
359                         i = System.Int32.MinValue;
360                         j = 0;
361                         k = i - j;
362                 }
363
364                 if (k != System.Int32.MinValue)
365                         return 1;
366
367                 return 0;
368         }
369
370         public static int test_0_sub_ovf2 () {
371                 int i, j, k;
372
373                 checked {
374                         i = System.Int32.MaxValue;
375                         j = 0;
376                         k = i - j;
377                 }
378
379                 if (k != System.Int32.MaxValue)
380                         return 2;
381
382                 return 0;
383         }
384
385         public static int test_0_sub_ovf3 () {
386                 int i, j, k;
387
388                 checked {
389                         i = System.Int32.MinValue;
390                         j = System.Int32.MinValue + 1234;
391                         k = i - j;
392                 }
393
394                 if (k != -1234)
395                         return 3;
396
397                 return 0;
398         }
399
400         public static int test_0_sub_ovf4 () {
401                 int i, j, k;
402
403                 checked {
404                         i = System.Int32.MaxValue;
405                         j = 1234;
406                         k = i - j;
407                 }
408
409                 if (k != System.Int32.MaxValue - 1234)
410                         return 4;
411
412                 return 0;
413         }
414
415         public static int test_0_sub_ovf5 () {
416                 int i, j, k;
417
418                 checked {
419                         i = System.Int32.MaxValue - 1234;
420                         j = -1234;
421                         k = i - j;
422                 }
423
424                 if (k != System.Int32.MaxValue)
425                         return 5;
426
427                 return 0;
428         }
429
430         public static int test_0_sub_ovf6 () {
431                 int i, j, k;
432
433                 checked {
434                         i = System.Int32.MinValue + 1234;
435                         j = 1234;
436                         k = i - j;
437                 }
438
439                 if (k != System.Int32.MinValue)
440                         return 6;
441
442                 return 0;
443         }
444
445         public static int test_0_sub_ovf_un () {
446                 uint i, j, k;
447
448                 checked {
449                         i = System.UInt32.MaxValue;
450                         j = 0;
451                         k = i - j;
452                 }
453
454                 if (k != System.UInt32.MaxValue)
455                         return 1;
456
457                 checked {
458                         i = System.UInt32.MaxValue;
459                         j = System.UInt32.MaxValue;
460                         k = i - j;
461                 }
462
463                 if (k != 0)
464                         return 2;
465
466                 return 0;
467         }
468
469         public static int test_3_or () {
470                 int b = 2;
471                 int a = 3;
472                 return b | a;
473         }
474
475         public static int test_3_or_un () {
476                 uint b = 2;
477                 uint a = 3;
478                 return (int)(b | a);
479         }
480
481         public static int test_3_or_short_un () {
482                 ushort b = 2;
483                 ushort a = 3;
484                 return (int)(b | a);
485         }
486
487         public static int test_18_or_imm () {
488                 int b = 2;
489                 return b | 0x10;
490         }
491
492         public static int test_268435458_or_large_imm () {
493                 int b = 2;
494                 return b | 0x10000000;
495         }
496
497         public static int test_268435459_or_large_imm2 () {
498                 int b = 2;
499                 return b | 0x10000001;
500         }
501
502         public static int test_1_xor () {
503                 int b = 2;
504                 int a = 3;
505                 return b ^ a;
506         }
507
508         public static int test_1_xor_imm () {
509                 int b = 2;
510                 return b ^ 3;
511         }
512
513         public static int test_983041_xor_imm_large () {
514                 int b = 2;
515                 return b ^ 0xf0003;
516         }
517
518         public static int test_1_neg () {
519                 int b = -2;
520                 b++;
521                 return -b;
522         }
523
524         public static int test_2_not () {
525                 int b = ~2;
526                 b = ~b;
527                 return b;
528         }
529
530         public static int test_16_shift () {
531                 int b = 2;
532                 int a = 3;
533                 return b << a;
534         }
535         
536         public static int test_16_shift_add () {
537                 int b = 2;
538                 int a = 3;
539                 int c = 0;
540                 return b << (a + c);
541         }
542         
543         public static int test_16_shift_add2 () {
544                 int b = 2;
545                 int a = 3;
546                 int c = 0;
547                 return (b + c) << a;
548         }
549         
550         public static int test_16_shift_imm () {
551                 int b = 2;
552                 return b << 3;
553         }
554         
555         public static int test_524288_shift_imm_large () {
556                 int b = 2;
557                 return b << 18;
558         }
559         
560         public static int test_12_shift_imm_inv () {
561                 int b = 2;
562                 return 3 << 2;
563         }
564
565         public static int test_12_shift_imm_inv_sbyte () {
566                 sbyte b = 2;
567                 return 3 << 2;
568         }
569
570         public static int test_1_rshift_imm () {
571                 int b = 8;
572                 return b >> 3;
573         }
574         
575         public static int test_2_unrshift_imm () {
576                 uint b = 16;
577                 return (int)(b >> 3);
578         }
579         
580         public static int test_0_bigunrshift_imm () {
581                 unchecked {
582                         uint b = (uint)-1;
583                         b = b >> 1;
584                         if (b != 0x7fffffff)
585                                 return 1;
586                         return 0;
587                 }
588         }
589         
590         public static int test_0_bigrshift_imm () {
591                 int b = -1;
592                 b = b >> 1;
593                 if (b != -1)
594                         return 1;
595                 return 0;
596         }
597         
598         public static int test_1_rshift () {
599                 int b = 8;
600                 int a = 3;
601                 return b >> a;
602         }
603         
604         public static int test_2_unrshift () {
605                 uint b = 16;
606                 int a = 3;
607                 return (int)(b >> a);
608         }
609         
610         public static int test_0_bigunrshift () {
611                 unchecked {
612                         uint b = (uint)-1;
613                         int a = 1;
614                         b = b >> a;
615                         if (b != 0x7fffffff)
616                                 return 1;
617                         return 0;
618                 }
619         }
620         
621         public static int test_0_bigrshift () {
622                 int b = -1;
623                 int a = 1;
624                 b = b >> a;
625                 if (b != -1)
626                         return 1;
627                 return 0;
628         }
629         
630         public static int test_2_cond () {
631                 int b = 2, a = 3, c;
632                 if (a == b)
633                         return 0;
634                 return 2;
635         }
636         
637         public static int test_2_cond_short () {
638                 short b = 2, a = 3, c;
639                 if (a == b)
640                         return 0;
641                 return 2;
642         }
643         
644         public static int test_2_cond_sbyte () {
645                 sbyte b = 2, a = 3, c;
646                 if (a == b)
647                         return 0;
648                 return 2;
649         }
650         
651         public static int test_6_cascade_cond () {
652                 int b = 2, a = 3, c;
653                 if (a == b)
654                         return 0;
655                 else if (b > a)
656                         return 1;
657                 else if (b != b)
658                         return 2;
659                 else {
660                         c = 1;
661                 }
662                 return a + b + c;
663         }
664         
665         public static int test_6_cascade_short () {
666                 short b = 2, a = 3, c;
667                 if (a == b)
668                         return 0;
669                 else if (b > a)
670                         return 1;
671                 else if (b != b)
672                         return 2;
673                 else {
674                         c = 1;
675                 }
676                 return a + b + c;
677         }
678
679         public static int test_0_short_sign_extend () {
680                 int t1 = 0xffeedd;
681                 short s1 = (short)t1;
682                 int t2 = s1;
683
684                 if ((uint)t2 != 0xffffeedd) 
685                         return 1;
686                 else
687                         return 0;
688         }
689
690         public static int test_127_iconv_to_i1 () {
691                 int i = 0x100017f;
692                 sbyte s = (sbyte)i;
693
694                 return s;
695         }
696
697         public static int test_384_iconv_to_i2 () {
698                 int i = 0x1000180;
699                 short s = (short)i;
700
701                 return s;
702         }
703         
704         public static int test_15_for_loop () {
705                 int i;
706                 for (i = 0; i < 15; ++i) {
707                 }
708                 return i;
709         }
710         
711         public static int test_11_nested_for_loop () {
712                 int i, j = 0; /* mcs bug here if j not set */
713                 for (i = 0; i < 15; ++i) {
714                         for (j = 200; j >= 5; --j) ;
715                 }
716                 return i - j;
717         }
718
719         public static int test_11_several_nested_for_loops () {
720                 int i, j = 0; /* mcs bug here if j not set */
721                 for (i = 0; i < 15; ++i) {
722                         for (j = 200; j >= 5; --j) ;
723                 }
724                 i = j = 0;
725                 for (i = 0; i < 15; ++i) {
726                         for (j = 200; j >= 5; --j) ;
727                 }
728                 return i - j;
729         }
730
731         public static int test_0_conv_ovf_i1 () {
732                 int c;
733
734                 //for (int j = 0; j < 10000000; j++)
735                 checked {
736                         c = 127;
737                         sbyte b = (sbyte)c;
738                         c = -128;
739                         b = (sbyte)c;
740                 }
741
742                 return 0;
743         }
744         
745         public static int test_0_conv_ovf_i1_un () {
746                 uint c;
747
748                 checked {
749                         c = 127;
750                         sbyte b = (sbyte)c;
751                 }
752                 
753                 return 0;
754         }
755         
756         public static int test_0_conv_ovf_i2 () {
757                 int c;
758
759                 checked {
760                         c = 32767;
761                         Int16 b = (Int16)c;
762                         c = -32768;
763                         b = (Int16)c;
764                         unchecked {
765                                 uint u = 0xfffffffd;
766                                 c = (int)u;
767                         }
768                         b = (Int16)c;
769                 }
770                 
771                 return 0;
772         }
773         
774         public static int test_0_conv_ovf_i2_un () {
775                 uint c;
776
777                 checked {
778                         c = 32767;
779                         Int16 b = (Int16)c;
780                 }
781                 
782                 return 0;
783         }
784         
785         public static int test_0_conv_ovf_u2 () {
786                 int c;
787
788                 checked {
789                         c = 65535;
790                         UInt16 b = (UInt16)c;
791                 }
792                 
793                 return 0;
794         }
795         
796         public static int test_0_conv_ovf_u2_un () {
797                 uint c;
798
799                 checked {
800                         c = 65535;
801                         UInt16 b = (UInt16)c;
802                 }
803                 
804                 return 0;
805         }
806         
807         public static int test_0_conv_ovf_u4 () {
808                 int c;
809
810                 checked {
811                         c = 0x7fffffff;
812                         uint b = (uint)c;
813                 }
814                 
815                 return 0;
816         }
817
818         public static int test_0_conv_ovf_i4_un () {
819                 uint c;
820
821                 checked {
822                         c = 0x7fffffff;
823                         int b = (int)c;
824                 }
825
826                 return 0;
827         }
828         
829         public static int test_0_bool () {
830                 bool val = true;
831                 if (val)
832                         return 0;
833                 return 1;
834         }
835         
836         public static int test_1_bool_inverted () {
837                 bool val = true;
838                 if (!val)
839                         return 0;
840                 return 1;
841         }
842
843         public static int test_1_bool_assign () {
844                 bool val = true;
845                 val = !val; // this should produce a ceq
846                 if (val)
847                         return 0;
848                 return 1;
849         }
850
851         public static int test_1_bool_multi () {
852                 bool val = true;
853                 bool val2 = true;
854                 val = !val;
855                 if ((val && !val2) && (!val2 && val))
856                         return 0;
857                 return 1;
858         }
859
860         public static int test_16_spill () {
861                 int a = 1;
862                 int b = 2;
863                 int c = 3;
864                 int d = 4;
865                 int e = 5;
866
867                 return (1 + (a + (b + (c + (d + e)))));
868         }
869
870         public static int test_1_switch () {
871                 int n = 0;
872
873                 switch (n) {
874                 case 0: return 1;
875                 case 1: return 2;
876                 case -1: return 3;
877                 default:
878                         return 4;
879                 }
880                 return 1;
881         }
882
883         public static int test_0_switch_constprop () {
884                 int n = -1;
885
886                 switch (n) {
887                 case 0: return 2;
888                 case 1: return 3;
889                 case 2: return 3;                       
890                 default:
891                         return 0;
892                 }
893                 return 3;
894         }
895
896         public static int test_0_switch_constprop2 () {
897                 int n = 3;
898
899                 switch (n) {
900                 case 0: return 2;
901                 case 1: return 3;
902                 case 2: return 3;                       
903                 default:
904                         return 0;
905                 }
906                 return 3;
907         }
908
909         public static int test_0_while_loop_1 () {
910
911                 int value = 255;
912                 
913                 do {
914                         value = value >> 4;
915                 } while (value != 0);
916                 
917                 return 0;
918         }
919
920         public static int test_0_while_loop_2 () {
921                 int value = 255;
922                 int position = 5;
923                 
924                 do {
925                         value = value >> 4;
926                 } while (value != 0 && position > 1);
927         
928                 return 0;
929         }
930
931         public static int test_0_char_conv () {
932                 int i = 1;
933                 
934                 char tc = (char) ('0' + i);
935
936                 if (tc != '1')
937                         return 1;
938                 
939                 return 0;
940         }
941
942         public static int test_3_shift_regalloc () {
943                 int shift = 8;
944                 int orig = 1;
945                 byte value = 0xfe;
946
947                 orig &= ~(0xff << shift);
948                 orig |= value << shift;
949
950                 if (orig == 0xfe01)
951                         return 3;
952                 return 0;
953         }
954
955         enum E {A, B};
956         
957         public static int test_2_optimize_branches () {
958                 switch (E.A) {
959                 case E.A:
960                         if (E.A == E.B) {
961                         }
962                         break;
963                 }
964                 return 2;
965         }
966
967         public static int test_0_checked_byte_cast () {
968                 int v = 250;
969                 int b = checked ((byte) (v));
970
971                 if (b != 250)
972                         return 1;
973                 return 0;
974         }
975
976         public static int test_0_checked_byte_cast_un () {
977                 uint v = 250;
978                 uint b = checked ((byte) (v));
979
980                 if (b != 250)
981                         return 1;
982                 return 0;
983         }
984
985         public static int test_0_checked_short_cast () {
986                 int v = 250;
987                 int b = checked ((ushort) (v));
988
989                 if (b != 250)
990                         return 1;
991                 return 0;
992         }
993
994         public static int test_0_checked_short_cast_un () {
995                 uint v = 250;
996                 uint b = checked ((ushort) (v));
997
998                 if (b != 250)
999                         return 1;
1000                 return 0;
1001         }
1002         
1003         public static int test_1_a_eq_b_plus_a () {
1004                 int a = 0, b = 1;
1005                 a = b + a;
1006                 return a;
1007         }
1008
1009         public static int test_0_comp () {
1010                 int a = 0;
1011                 int b = -1;
1012                 int error = 1;
1013                 bool val;
1014
1015                 val = a < b;
1016                 if (val)
1017                         return error;
1018                 error++;
1019
1020                 val = a > b;
1021                 if (!val)
1022                         return error;
1023                 error ++;
1024
1025                 val = a == b;
1026                 if (val)
1027                         return error;
1028                 error ++;
1029
1030                 val = a == a;
1031                 if (!val)
1032                         return error;
1033                 error ++;
1034
1035                 return 0;
1036         }
1037
1038         public static int test_0_comp_unsigned () {
1039                 uint a = 1;
1040                 uint b = 0xffffffff;
1041                 int error = 1;
1042                 bool val;
1043
1044                 val = a < b;
1045                 if (!val)
1046                         return error;
1047                 error++;
1048
1049                 val = a <= b;
1050                 if (!val)
1051                         return error;
1052                 error++;
1053
1054                 val = a == b;
1055                 if (val)
1056                         return error;
1057                 error++;
1058
1059                 val = a >= b;
1060                 if (val)
1061                         return error;
1062                 error++;
1063
1064                 val = a > b;
1065                 if (val)
1066                         return error;
1067                 error++;
1068
1069                 val = b < a;
1070                 if (val)
1071                         return error;
1072                 error++;
1073
1074                 val = b <= a;
1075                 if (val)
1076                         return error;
1077                 error++;
1078
1079                 val = b == a;
1080                 if (val)
1081                         return error;
1082                 error++;
1083
1084                 val = b > a;
1085                 if (!val)
1086                         return error;
1087                 error++;
1088
1089                 val = b >= a;
1090                 if (!val)
1091                         return error;
1092                 error++;
1093
1094                 return 0;
1095         }
1096         
1097         public static int test_16_cmov () 
1098         {
1099                 int n = 0;
1100                 if (n == 0)
1101                         n = 16;
1102                 
1103                 return n;
1104         }
1105
1106         public static int test_0_and_cmp ()
1107         {
1108                 /* test esi, imm */
1109                 int local = 0x01020304;
1110                 
1111                 if ((local & 0x01020304) == 0)
1112                         return 7;
1113                 
1114                 if ((local & 0x00000304) == 0)
1115                         return 8;
1116                 
1117                 if ((local & 0x00000004) == 0)
1118                         return 9;
1119                 
1120                 if ((local & 0x00000300) == 0)
1121                         return 10;
1122                 
1123                 if ((local & 0x00020000) == 0)
1124                         return 11;
1125                 
1126                 if ((local & 0x01000000) == 0)
1127                         return 12;
1128
1129                 return 0;
1130         }
1131
1132         public static int test_0_mul_imm_opt ()
1133         {
1134                 int i;
1135
1136                 i = 1;
1137                 if ((i * 2) != 2)
1138                         return 1;
1139                 i = -1;
1140                 if ((i * 2) != -2)
1141                         return 2;
1142                 i = 1;
1143                 if ((i * 3) != 3)
1144                         return 3;
1145                 i = -1;
1146                 if ((i * 3) != -3)
1147                         return 4;
1148                 i = 1;
1149                 if ((i * 5) != 5)
1150                         return 5;
1151                 i = -1;
1152                 if ((i * 5) != -5)
1153                         return 6;
1154                 i = 1;
1155                 if ((i * 6) != 6)
1156                         return 7;
1157                 i = -1;
1158                 if ((i * 6) != -6)
1159                         return 8;
1160                 i = 1;
1161                 if ((i * 9) != 9)
1162                         return 9;
1163                 i = -1;
1164                 if ((i * 9) != -9)
1165                         return 10;
1166                 i = 1;
1167                 if ((i * 10) != 10)
1168                         return 11;
1169                 i = -1;
1170                 if ((i * 10) != -10)
1171                         return 12;
1172                 i = 1;
1173                 if ((i * 12) != 12)
1174                         return 13;
1175                 i = -1;
1176                 if ((i * 12) != -12)
1177                         return 14;
1178                 i = 1;
1179                 if ((i * 25) != 25)
1180                         return 15;
1181                 i = -1;
1182                 if ((i * 25) != -25)
1183                         return 16;
1184                 i = 1;
1185                 if ((i * 100) != 100)
1186                         return 17;
1187                 i = -1;
1188                 if ((i * 100) != -100)
1189                         return 18;
1190                 
1191                 return 0;
1192         }
1193         
1194         public static int test_0_cne ()
1195         {
1196                 int x = 0;
1197                 int y = 1;
1198                 
1199                 bool b = x != y;
1200                 bool bb = x != x;
1201                 
1202                 if (!b)
1203                         return 1;
1204                 if (bb)
1205                         return 2;
1206                 
1207                 return 0;
1208         }
1209
1210         public static int test_0_cmp_regvar_zero ()
1211         {
1212                 int n = 10;
1213                 
1214                 if (!(n > 0 && n >= 0 && n != 0))
1215                         return 1;
1216                 if (n < 0 || n <= 0 || n == 0)
1217                         return 1;
1218                 
1219                 return 0;
1220         }
1221
1222         public static int test_5_div_un_cfold ()
1223         {
1224                 uint i = 10;
1225                 uint j = 2;
1226
1227                 return (int)(i / j);
1228         }
1229
1230         public static int test_1_rem_un_cfold ()
1231         {
1232                 uint i = 11;
1233                 uint j = 2;
1234
1235                 return (int)(i % j);
1236         }
1237
1238         public static int test_0_div_opt () {
1239                 int i;
1240
1241                 // Avoid cfolding this
1242                 i = 0;
1243                 for (int j = 0; j < 567; ++j)
1244                         i ++;
1245                 i += 1234000;
1246                 if ((i / 2) != 617283)
1247                         return 1;
1248                 if ((i / 4) != 308641)
1249                         return 2;
1250                 if ((i / 8) != 154320)
1251                         return 3;
1252                 if ((i / 16) != 77160)
1253                         return 4;
1254
1255                 // Avoid cfolding this
1256                 i = 0;
1257                 for (int j = 0; j < 567; ++j)
1258                         i --;
1259                 i -= 1234000;
1260                 if ((i / 2) != -617283)
1261                         return 5;
1262                 if ((i / 4) != -308641)
1263                         return 6;
1264                 if ((i / 8) != -154320)
1265                         return 7;
1266                 if ((i / 16) != -77160)
1267                         return 8;
1268
1269                 return 0;
1270         }
1271
1272         public static int test_0_rem_opt () {
1273                 int i;
1274
1275                 // Avoid cfolding this
1276                 i = 0;
1277                 for (int j = 0; j < 29; ++j)
1278                         i ++;
1279                 if ((i % 2) != 1)
1280                         return 1;
1281                 if ((i % 4) != 1)
1282                         return 2;
1283                 if ((i % 8) != 5)
1284                         return 3;
1285                 if ((i % 16) != 13)
1286                         return 4;
1287
1288                 // Avoid cfolding this
1289                 i = 0;
1290                 for (int j = 0; j < 29; ++j)
1291                         i --;
1292                 if ((i % 2) != -1)
1293                         return 5;
1294                 if ((i % 4) != -1)
1295                         return 6;
1296                 if ((i % 8) != -5)
1297                         return 7;
1298                 if ((i % 16) != -13)
1299                         return 8;
1300
1301                 return 0;
1302         }
1303
1304         public static int cmov (int i) {
1305                 int j = 0;
1306
1307                 if (i > 0)
1308                         j = 1;
1309
1310                 return j;
1311         }
1312
1313         public static int cmov2 (int i) {
1314                 int j = 0;
1315
1316                 if (i <= 0)
1317                         ;
1318                 else
1319                         j = 1;
1320
1321                 return j;
1322         }
1323                 
1324         public static int test_0_branch_to_cmov_opt () {
1325                 if (cmov (0) != 0)
1326                         return 1;
1327                 if (cmov (1) != 1)
1328                         return 2;
1329                 if (cmov2 (0) != 0)
1330                         return 1;
1331                 if (cmov2 (1) != 1)
1332                         return 2;
1333                 return 0;
1334         }
1335
1336         public static unsafe int test_0_ishr_sign_extend () {
1337                 // Check that ishr does sign extension from bit 31 on 64 bit platforms
1338                 uint val = 0xF0000000u;
1339
1340                 uint *a = &val;
1341                 uint ui = (uint)((int)(*a) >> 2);
1342
1343                 if (ui != 0xfc000000)
1344                         return 1;
1345
1346                 // Same with non-immediates
1347                 int amount = 2;
1348
1349                 ui = (uint)((int)(*a) >> amount);
1350
1351                 if (ui != 0xfc000000)
1352                         return 2;
1353
1354                 return 0;
1355         }
1356
1357         public static unsafe int test_0_ishr_sign_extend_cfold () {
1358                 int i = 32768;
1359                 int j = i << 16;
1360                 int k = j >> 16;
1361
1362                 return k == -32768 ? 0 : 1;
1363         }
1364 }