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