2009-05-20 Rodrigo Kumpera <rkumpera@novell.com>
[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_4_rem_big_imm () {
199                 int b = 10004;
200                 return b % 10000;
201         }
202
203         public static int test_9_mul () {
204                 int b = 3;
205                 int a = 3;
206                 return b * a;
207         }
208
209         public static int test_15_mul_imm () {
210                 int b = 3;
211                 return b * 5;
212         }
213
214         public static int test_24_mul () {
215                 int a = 3;
216                 int b = 8;
217                 int res;
218
219                 res = a * b;
220                 
221                 return res;
222         }
223
224         public static int test_24_mul_ovf () {
225                 int a = 3;
226                 int b = 8;
227                 int res;
228
229                 checked {
230                         res = a * b;
231                 }
232                 
233                 return res;
234         }
235
236         public static int test_24_mul_un () {
237                 uint a = 3;
238                 uint b = 8;
239                 uint res;
240
241                 res = a * b;
242                 
243                 return (int)res;
244         }
245
246         public static int test_24_mul_ovf_un () {
247                 uint a = 3;
248                 uint b = 8;
249                 uint res;
250
251                 checked {
252                         res = a * b;
253                 }
254                 
255                 return (int)res;
256         }
257
258         public static int test_0_add_ovf1 () {
259                 int i, j, k;
260
261                 checked {
262                         i = System.Int32.MinValue;
263                         j = 0;
264                         k = i + j;
265                 }
266
267                 if (k != System.Int32.MinValue)
268                         return 1;
269                 return 0;
270         }
271
272         public static int test_0_add_ovf2 () {
273                 int i, j, k;
274
275                 checked {
276                         i = System.Int32.MaxValue;
277                         j = 0;
278                         k = i + j;
279                 }
280
281                 if (k != System.Int32.MaxValue)
282                         return 2;
283                 return 0;
284         }
285
286         public static int test_0_add_ovf3 () {
287                 int i, j, k;
288
289                 checked {
290                         i = System.Int32.MinValue;
291                         j = System.Int32.MaxValue;
292                         k = i + j;
293                 }
294
295                 if (k != -1)
296                         return 3;
297                 return 0;
298         }
299
300         public static int test_0_add_ovf4 () {
301                 int i, j, k;
302
303                 checked {
304                         i = System.Int32.MaxValue;
305                         j = System.Int32.MinValue;
306                         k = i + j;
307                 }
308
309                 if (k != -1)
310                         return 4;
311                 return 0;
312         }
313
314         public static int test_0_add_ovf5 () {
315                 int i, j, k;
316
317                 checked {
318                         i = System.Int32.MinValue + 1234;
319                         j = -1234;
320                         k = i + j;
321                 }
322
323                 if (k != System.Int32.MinValue)
324                         return 5;
325                 return 0;
326         }
327
328         public static int test_0_add_ovf6 () {
329                 int i, j, k;
330
331                 checked {
332                         i = System.Int32.MaxValue - 1234;
333                         j = 1234;
334                         k = i + j;
335                 }
336
337                 if (k != System.Int32.MaxValue)
338                         return 6;
339
340                 return 0;
341         }
342
343         public static int test_0_add_un_ovf () {
344                 uint n = (uint)134217728 * 16;
345                 uint number = checked (n + (uint)0);
346
347                 return number == n ? 0 : 1;
348         }
349
350         public static int test_0_sub_ovf1 () {
351                 int i, j, k;
352
353                 checked {
354                         i = System.Int32.MinValue;
355                         j = 0;
356                         k = i - j;
357                 }
358
359                 if (k != System.Int32.MinValue)
360                         return 1;
361
362                 return 0;
363         }
364
365         public static int test_0_sub_ovf2 () {
366                 int i, j, k;
367
368                 checked {
369                         i = System.Int32.MaxValue;
370                         j = 0;
371                         k = i - j;
372                 }
373
374                 if (k != System.Int32.MaxValue)
375                         return 2;
376
377                 return 0;
378         }
379
380         public static int test_0_sub_ovf3 () {
381                 int i, j, k;
382
383                 checked {
384                         i = System.Int32.MinValue;
385                         j = System.Int32.MinValue + 1234;
386                         k = i - j;
387                 }
388
389                 if (k != -1234)
390                         return 3;
391
392                 return 0;
393         }
394
395         public static int test_0_sub_ovf4 () {
396                 int i, j, k;
397
398                 checked {
399                         i = System.Int32.MaxValue;
400                         j = 1234;
401                         k = i - j;
402                 }
403
404                 if (k != System.Int32.MaxValue - 1234)
405                         return 4;
406
407                 return 0;
408         }
409
410         public static int test_0_sub_ovf5 () {
411                 int i, j, k;
412
413                 checked {
414                         i = System.Int32.MaxValue - 1234;
415                         j = -1234;
416                         k = i - j;
417                 }
418
419                 if (k != System.Int32.MaxValue)
420                         return 5;
421
422                 return 0;
423         }
424
425         public static int test_0_sub_ovf6 () {
426                 int i, j, k;
427
428                 checked {
429                         i = System.Int32.MinValue + 1234;
430                         j = 1234;
431                         k = i - j;
432                 }
433
434                 if (k != System.Int32.MinValue)
435                         return 6;
436
437                 return 0;
438         }
439
440         public static int test_0_sub_ovf_un () {
441                 uint i, j, k;
442
443                 checked {
444                         i = System.UInt32.MaxValue;
445                         j = 0;
446                         k = i - j;
447                 }
448
449                 if (k != System.UInt32.MaxValue)
450                         return 1;
451
452                 checked {
453                         i = System.UInt32.MaxValue;
454                         j = System.UInt32.MaxValue;
455                         k = i - j;
456                 }
457
458                 if (k != 0)
459                         return 2;
460
461                 return 0;
462         }
463
464         public static int test_3_or () {
465                 int b = 2;
466                 int a = 3;
467                 return b | a;
468         }
469
470         public static int test_3_or_un () {
471                 uint b = 2;
472                 uint a = 3;
473                 return (int)(b | a);
474         }
475
476         public static int test_3_or_short_un () {
477                 ushort b = 2;
478                 ushort a = 3;
479                 return (int)(b | a);
480         }
481
482         public static int test_18_or_imm () {
483                 int b = 2;
484                 return b | 0x10;
485         }
486
487         public static int test_268435458_or_large_imm () {
488                 int b = 2;
489                 return b | 0x10000000;
490         }
491
492         public static int test_268435459_or_large_imm2 () {
493                 int b = 2;
494                 return b | 0x10000001;
495         }
496
497         public static int test_1_xor () {
498                 int b = 2;
499                 int a = 3;
500                 return b ^ a;
501         }
502
503         public static int test_1_xor_imm () {
504                 int b = 2;
505                 return b ^ 3;
506         }
507
508         public static int test_983041_xor_imm_large () {
509                 int b = 2;
510                 return b ^ 0xf0003;
511         }
512
513         public static int test_1_neg () {
514                 int b = -2;
515                 b++;
516                 return -b;
517         }
518
519         public static int test_2_not () {
520                 int b = ~2;
521                 b = ~b;
522                 return b;
523         }
524
525         public static int test_16_shift () {
526                 int b = 2;
527                 int a = 3;
528                 return b << a;
529         }
530         
531         public static int test_16_shift_add () {
532                 int b = 2;
533                 int a = 3;
534                 int c = 0;
535                 return b << (a + c);
536         }
537         
538         public static int test_16_shift_add2 () {
539                 int b = 2;
540                 int a = 3;
541                 int c = 0;
542                 return (b + c) << a;
543         }
544         
545         public static int test_16_shift_imm () {
546                 int b = 2;
547                 return b << 3;
548         }
549         
550         public static int test_524288_shift_imm_large () {
551                 int b = 2;
552                 return b << 18;
553         }
554         
555         public static int test_12_shift_imm_inv () {
556                 int b = 2;
557                 return 3 << 2;
558         }
559
560         public static int test_12_shift_imm_inv_sbyte () {
561                 sbyte b = 2;
562                 return 3 << 2;
563         }
564
565         public static int test_1_rshift_imm () {
566                 int b = 8;
567                 return b >> 3;
568         }
569         
570         public static int test_2_unrshift_imm () {
571                 uint b = 16;
572                 return (int)(b >> 3);
573         }
574         
575         public static int test_0_bigunrshift_imm () {
576                 unchecked {
577                         uint b = (uint)-1;
578                         b = b >> 1;
579                         if (b != 0x7fffffff)
580                                 return 1;
581                         return 0;
582                 }
583         }
584         
585         public static int test_0_bigrshift_imm () {
586                 int b = -1;
587                 b = b >> 1;
588                 if (b != -1)
589                         return 1;
590                 return 0;
591         }
592         
593         public static int test_1_rshift () {
594                 int b = 8;
595                 int a = 3;
596                 return b >> a;
597         }
598         
599         public static int test_2_unrshift () {
600                 uint b = 16;
601                 int a = 3;
602                 return (int)(b >> a);
603         }
604         
605         public static int test_0_bigunrshift () {
606                 unchecked {
607                         uint b = (uint)-1;
608                         int a = 1;
609                         b = b >> a;
610                         if (b != 0x7fffffff)
611                                 return 1;
612                         return 0;
613                 }
614         }
615         
616         public static int test_0_bigrshift () {
617                 int b = -1;
618                 int a = 1;
619                 b = b >> a;
620                 if (b != -1)
621                         return 1;
622                 return 0;
623         }
624         
625         public static int test_2_cond () {
626                 int b = 2, a = 3, c;
627                 if (a == b)
628                         return 0;
629                 return 2;
630         }
631         
632         public static int test_2_cond_short () {
633                 short b = 2, a = 3, c;
634                 if (a == b)
635                         return 0;
636                 return 2;
637         }
638         
639         public static int test_2_cond_sbyte () {
640                 sbyte b = 2, a = 3, c;
641                 if (a == b)
642                         return 0;
643                 return 2;
644         }
645         
646         public static int test_6_cascade_cond () {
647                 int b = 2, a = 3, c;
648                 if (a == b)
649                         return 0;
650                 else if (b > a)
651                         return 1;
652                 else if (b != b)
653                         return 2;
654                 else {
655                         c = 1;
656                 }
657                 return a + b + c;
658         }
659         
660         public static int test_6_cascade_short () {
661                 short b = 2, a = 3, c;
662                 if (a == b)
663                         return 0;
664                 else if (b > a)
665                         return 1;
666                 else if (b != b)
667                         return 2;
668                 else {
669                         c = 1;
670                 }
671                 return a + b + c;
672         }
673
674         public static int test_0_short_sign_extend () {
675                 int t1 = 0xffeedd;
676                 short s1 = (short)t1;
677                 int t2 = s1;
678
679                 if ((uint)t2 != 0xffffeedd) 
680                         return 1;
681                 else
682                         return 0;
683         }
684
685         public static int test_127_iconv_to_i1 () {
686                 int i = 0x100017f;
687                 sbyte s = (sbyte)i;
688
689                 return s;
690         }
691
692         public static int test_384_iconv_to_i2 () {
693                 int i = 0x1000180;
694                 short s = (short)i;
695
696                 return s;
697         }
698         
699         public static int test_15_for_loop () {
700                 int i;
701                 for (i = 0; i < 15; ++i) {
702                 }
703                 return i;
704         }
705         
706         public static int test_11_nested_for_loop () {
707                 int i, j = 0; /* mcs bug here if j not set */
708                 for (i = 0; i < 15; ++i) {
709                         for (j = 200; j >= 5; --j) ;
710                 }
711                 return i - j;
712         }
713
714         public static int test_11_several_nested_for_loops () {
715                 int i, j = 0; /* mcs bug here if j not set */
716                 for (i = 0; i < 15; ++i) {
717                         for (j = 200; j >= 5; --j) ;
718                 }
719                 i = j = 0;
720                 for (i = 0; i < 15; ++i) {
721                         for (j = 200; j >= 5; --j) ;
722                 }
723                 return i - j;
724         }
725
726         public static int test_0_conv_ovf_i1 () {
727                 int c;
728
729                 //for (int j = 0; j < 10000000; j++)
730                 checked {
731                         c = 127;
732                         sbyte b = (sbyte)c;
733                         c = -128;
734                         b = (sbyte)c;
735                 }
736
737                 return 0;
738         }
739         
740         public static int test_0_conv_ovf_i1_un () {
741                 uint c;
742
743                 checked {
744                         c = 127;
745                         sbyte b = (sbyte)c;
746                 }
747                 
748                 return 0;
749         }
750         
751         public static int test_0_conv_ovf_i2 () {
752                 int c;
753
754                 checked {
755                         c = 32767;
756                         Int16 b = (Int16)c;
757                         c = -32768;
758                         b = (Int16)c;
759                         unchecked {
760                                 uint u = 0xfffffffd;
761                                 c = (int)u;
762                         }
763                         b = (Int16)c;
764                 }
765                 
766                 return 0;
767         }
768         
769         public static int test_0_conv_ovf_i2_un () {
770                 uint c;
771
772                 checked {
773                         c = 32767;
774                         Int16 b = (Int16)c;
775                 }
776                 
777                 return 0;
778         }
779         
780         public static int test_0_conv_ovf_u2 () {
781                 int c;
782
783                 checked {
784                         c = 65535;
785                         UInt16 b = (UInt16)c;
786                 }
787                 
788                 return 0;
789         }
790         
791         public static int test_0_conv_ovf_u2_un () {
792                 uint c;
793
794                 checked {
795                         c = 65535;
796                         UInt16 b = (UInt16)c;
797                 }
798                 
799                 return 0;
800         }
801         
802         public static int test_0_conv_ovf_u4 () {
803                 int c;
804
805                 checked {
806                         c = 0x7fffffff;
807                         uint b = (uint)c;
808                 }
809                 
810                 return 0;
811         }
812
813         public static int test_0_conv_ovf_i4_un () {
814                 uint c;
815
816                 checked {
817                         c = 0x7fffffff;
818                         int b = (int)c;
819                 }
820
821                 return 0;
822         }
823         
824         public static int test_0_bool () {
825                 bool val = true;
826                 if (val)
827                         return 0;
828                 return 1;
829         }
830         
831         public static int test_1_bool_inverted () {
832                 bool val = true;
833                 if (!val)
834                         return 0;
835                 return 1;
836         }
837
838         public static int test_1_bool_assign () {
839                 bool val = true;
840                 val = !val; // this should produce a ceq
841                 if (val)
842                         return 0;
843                 return 1;
844         }
845
846         public static int test_1_bool_multi () {
847                 bool val = true;
848                 bool val2 = true;
849                 val = !val;
850                 if ((val && !val2) && (!val2 && val))
851                         return 0;
852                 return 1;
853         }
854
855         public static int test_16_spill () {
856                 int a = 1;
857                 int b = 2;
858                 int c = 3;
859                 int d = 4;
860                 int e = 5;
861
862                 return (1 + (a + (b + (c + (d + e)))));
863         }
864
865         public static int test_1_switch () {
866                 int n = 0;
867
868                 switch (n) {
869                 case 0: return 1;
870                 case 1: return 2;
871                 case -1: return 3;
872                 default:
873                         return 4;
874                 }
875                 return 1;
876         }
877
878         public static int test_0_switch_constprop () {
879                 int n = -1;
880
881                 switch (n) {
882                 case 0: return 2;
883                 case 1: return 3;
884                 case 2: return 3;                       
885                 default:
886                         return 0;
887                 }
888                 return 3;
889         }
890
891         public static int test_0_switch_constprop2 () {
892                 int n = 3;
893
894                 switch (n) {
895                 case 0: return 2;
896                 case 1: return 3;
897                 case 2: return 3;                       
898                 default:
899                         return 0;
900                 }
901                 return 3;
902         }
903
904         public static int test_0_while_loop_1 () {
905
906                 int value = 255;
907                 
908                 do {
909                         value = value >> 4;
910                 } while (value != 0);
911                 
912                 return 0;
913         }
914
915         public static int test_0_while_loop_2 () {
916                 int value = 255;
917                 int position = 5;
918                 
919                 do {
920                         value = value >> 4;
921                 } while (value != 0 && position > 1);
922         
923                 return 0;
924         }
925
926         public static int test_0_char_conv () {
927                 int i = 1;
928                 
929                 char tc = (char) ('0' + i);
930
931                 if (tc != '1')
932                         return 1;
933                 
934                 return 0;
935         }
936
937         public static int test_3_shift_regalloc () {
938                 int shift = 8;
939                 int orig = 1;
940                 byte value = 0xfe;
941
942                 orig &= ~(0xff << shift);
943                 orig |= value << shift;
944
945                 if (orig == 0xfe01)
946                         return 3;
947                 return 0;
948         }
949
950         enum E {A, B};
951         
952         public static int test_2_optimize_branches () {
953                 switch (E.A) {
954                 case E.A:
955                         if (E.A == E.B) {
956                         }
957                         break;
958                 }
959                 return 2;
960         }
961
962         public static int test_0_checked_byte_cast () {
963                 int v = 250;
964                 int b = checked ((byte) (v));
965
966                 if (b != 250)
967                         return 1;
968                 return 0;
969         }
970
971         public static int test_0_checked_byte_cast_un () {
972                 uint v = 250;
973                 uint b = checked ((byte) (v));
974
975                 if (b != 250)
976                         return 1;
977                 return 0;
978         }
979
980         public static int test_0_checked_short_cast () {
981                 int v = 250;
982                 int b = checked ((ushort) (v));
983
984                 if (b != 250)
985                         return 1;
986                 return 0;
987         }
988
989         public static int test_0_checked_short_cast_un () {
990                 uint v = 250;
991                 uint b = checked ((ushort) (v));
992
993                 if (b != 250)
994                         return 1;
995                 return 0;
996         }
997         
998         public static int test_1_a_eq_b_plus_a () {
999                 int a = 0, b = 1;
1000                 a = b + a;
1001                 return a;
1002         }
1003
1004         public static int test_0_comp () {
1005                 int a = 0;
1006                 int b = -1;
1007                 int error = 1;
1008                 bool val;
1009
1010                 val = a < b;
1011                 if (val)
1012                         return error;
1013                 error++;
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 == a;
1026                 if (!val)
1027                         return error;
1028                 error ++;
1029
1030                 return 0;
1031         }
1032
1033         public static int test_0_comp_unsigned () {
1034                 uint a = 1;
1035                 uint b = 0xffffffff;
1036                 int error = 1;
1037                 bool val;
1038
1039                 val = a < b;
1040                 if (!val)
1041                         return error;
1042                 error++;
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 = b < a;
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                 return 0;
1090         }
1091         
1092         public static int test_16_cmov () 
1093         {
1094                 int n = 0;
1095                 if (n == 0)
1096                         n = 16;
1097                 
1098                 return n;
1099         }
1100
1101         public static int test_0_and_cmp ()
1102         {
1103                 /* test esi, imm */
1104                 int local = 0x01020304;
1105                 
1106                 if ((local & 0x01020304) == 0)
1107                         return 7;
1108                 
1109                 if ((local & 0x00000304) == 0)
1110                         return 8;
1111                 
1112                 if ((local & 0x00000004) == 0)
1113                         return 9;
1114                 
1115                 if ((local & 0x00000300) == 0)
1116                         return 10;
1117                 
1118                 if ((local & 0x00020000) == 0)
1119                         return 11;
1120                 
1121                 if ((local & 0x01000000) == 0)
1122                         return 12;
1123
1124                 return 0;
1125         }
1126
1127         public static int test_0_mul_imm_opt ()
1128         {
1129                 int i;
1130
1131                 i = 1;
1132                 if ((i * 2) != 2)
1133                         return 1;
1134                 i = -1;
1135                 if ((i * 2) != -2)
1136                         return 2;
1137                 i = 1;
1138                 if ((i * 3) != 3)
1139                         return 3;
1140                 i = -1;
1141                 if ((i * 3) != -3)
1142                         return 4;
1143                 i = 1;
1144                 if ((i * 5) != 5)
1145                         return 5;
1146                 i = -1;
1147                 if ((i * 5) != -5)
1148                         return 6;
1149                 i = 1;
1150                 if ((i * 6) != 6)
1151                         return 7;
1152                 i = -1;
1153                 if ((i * 6) != -6)
1154                         return 8;
1155                 i = 1;
1156                 if ((i * 9) != 9)
1157                         return 9;
1158                 i = -1;
1159                 if ((i * 9) != -9)
1160                         return 10;
1161                 i = 1;
1162                 if ((i * 10) != 10)
1163                         return 11;
1164                 i = -1;
1165                 if ((i * 10) != -10)
1166                         return 12;
1167                 i = 1;
1168                 if ((i * 12) != 12)
1169                         return 13;
1170                 i = -1;
1171                 if ((i * 12) != -12)
1172                         return 14;
1173                 i = 1;
1174                 if ((i * 25) != 25)
1175                         return 15;
1176                 i = -1;
1177                 if ((i * 25) != -25)
1178                         return 16;
1179                 i = 1;
1180                 if ((i * 100) != 100)
1181                         return 17;
1182                 i = -1;
1183                 if ((i * 100) != -100)
1184                         return 18;
1185                 
1186                 return 0;
1187         }
1188         
1189         public static int test_0_cne ()
1190         {
1191                 int x = 0;
1192                 int y = 1;
1193                 
1194                 bool b = x != y;
1195                 bool bb = x != x;
1196                 
1197                 if (!b)
1198                         return 1;
1199                 if (bb)
1200                         return 2;
1201                 
1202                 return 0;
1203         }
1204
1205         public static int test_0_cmp_regvar_zero ()
1206         {
1207                 int n = 10;
1208                 
1209                 if (!(n > 0 && n >= 0 && n != 0))
1210                         return 1;
1211                 if (n < 0 || n <= 0 || n == 0)
1212                         return 1;
1213                 
1214                 return 0;
1215         }
1216
1217         public static int test_5_div_un_cfold ()
1218         {
1219                 uint i = 10;
1220                 uint j = 2;
1221
1222                 return (int)(i / j);
1223         }
1224
1225         public static int test_1_rem_un_cfold ()
1226         {
1227                 uint i = 11;
1228                 uint j = 2;
1229
1230                 return (int)(i % j);
1231         }
1232
1233         public static int test_0_div_opt () {
1234                 int i;
1235
1236                 // Avoid cfolding this
1237                 i = 0;
1238                 for (int j = 0; j < 1234567; ++j)
1239                         i ++;
1240                 if ((i / 2) != 617283)
1241                         return 1;
1242                 if ((i / 4) != 308641)
1243                         return 2;
1244                 if ((i / 8) != 154320)
1245                         return 3;
1246                 if ((i / 16) != 77160)
1247                         return 4;
1248
1249                 // Avoid cfolding this
1250                 i = 0;
1251                 for (int j = 0; j < 1234567; ++j)
1252                         i --;
1253                 if ((i / 2) != -617283)
1254                         return 5;
1255                 if ((i / 4) != -308641)
1256                         return 6;
1257                 if ((i / 8) != -154320)
1258                         return 7;
1259                 if ((i / 16) != -77160)
1260                         return 8;
1261
1262                 return 0;
1263         }
1264
1265         public static int test_0_rem_opt () {
1266                 int i;
1267
1268                 // Avoid cfolding this
1269                 i = 0;
1270                 for (int j = 0; j < 29; ++j)
1271                         i ++;
1272                 if ((i % 2) != 1)
1273                         return 1;
1274                 if ((i % 4) != 1)
1275                         return 2;
1276                 if ((i % 8) != 5)
1277                         return 3;
1278                 if ((i % 16) != 13)
1279                         return 4;
1280
1281                 // Avoid cfolding this
1282                 i = 0;
1283                 for (int j = 0; j < 29; ++j)
1284                         i --;
1285                 if ((i % 2) != -1)
1286                         return 5;
1287                 if ((i % 4) != -1)
1288                         return 6;
1289                 if ((i % 8) != -5)
1290                         return 7;
1291                 if ((i % 16) != -13)
1292                         return 8;
1293
1294                 return 0;
1295         }
1296
1297         public static int cmov (int i) {
1298                 int j = 0;
1299
1300                 if (i > 0)
1301                         j = 1;
1302
1303                 return j;
1304         }
1305
1306         public static int cmov2 (int i) {
1307                 int j = 0;
1308
1309                 if (i <= 0)
1310                         ;
1311                 else
1312                         j = 1;
1313
1314                 return j;
1315         }
1316                 
1317         public static int test_0_branch_to_cmov_opt () {
1318                 if (cmov (0) != 0)
1319                         return 1;
1320                 if (cmov (1) != 1)
1321                         return 2;
1322                 if (cmov2 (0) != 0)
1323                         return 1;
1324                 if (cmov2 (1) != 1)
1325                         return 2;
1326                 return 0;
1327         }
1328
1329         //repro for #505375
1330         public static int test_2_cprop_bug () {
1331                 int idx = 0;
1332                 int a = 1;
1333                 var cmp = System.Collections.Generic.Comparer<int>.Default ;
1334                 if (cmp.Compare (a, 0) > 0)
1335                         a = 0;
1336                 do { idx++; } while (cmp.Compare (idx - 1, a) == 0);
1337                 return idx;
1338         }
1339
1340
1341 }