2007-01-28 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_15_for_loop () {
681                 int i;
682                 for (i = 0; i < 15; ++i) {
683                 }
684                 return i;
685         }
686         
687         public static int test_11_nested_for_loop () {
688                 int i, j = 0; /* mcs bug here if j not set */
689                 for (i = 0; i < 15; ++i) {
690                         for (j = 200; j >= 5; --j) ;
691                 }
692                 return i - j;
693         }
694
695         public static int test_11_several_nested_for_loops () {
696                 int i, j = 0; /* mcs bug here if j not set */
697                 for (i = 0; i < 15; ++i) {
698                         for (j = 200; j >= 5; --j) ;
699                 }
700                 i = j = 0;
701                 for (i = 0; i < 15; ++i) {
702                         for (j = 200; j >= 5; --j) ;
703                 }
704                 return i - j;
705         }
706
707         public static int test_0_conv_ovf_i1 () {
708                 int c;
709
710                 //for (int j = 0; j < 10000000; j++)
711                 checked {
712                         c = 127;
713                         sbyte b = (sbyte)c;
714                         c = -128;
715                         b = (sbyte)c;
716                 }
717
718                 return 0;
719         }
720         
721         public static int test_0_conv_ovf_i1_un () {
722                 uint c;
723
724                 checked {
725                         c = 127;
726                         sbyte b = (sbyte)c;
727                 }
728                 
729                 return 0;
730         }
731         
732         public static int test_0_conv_ovf_i2 () {
733                 int c;
734
735                 checked {
736                         c = 32767;
737                         Int16 b = (Int16)c;
738                         c = -32768;
739                         b = (Int16)c;
740                         unchecked {
741                                 uint u = 0xfffffffd;
742                                 c = (int)u;
743                         }
744                         b = (Int16)c;
745                 }
746                 
747                 return 0;
748         }
749         
750         public static int test_0_conv_ovf_i2_un () {
751                 uint c;
752
753                 checked {
754                         c = 32767;
755                         Int16 b = (Int16)c;
756                 }
757                 
758                 return 0;
759         }
760         
761         public static int test_0_conv_ovf_u2 () {
762                 int c;
763
764                 checked {
765                         c = 65535;
766                         UInt16 b = (UInt16)c;
767                 }
768                 
769                 return 0;
770         }
771         
772         public static int test_0_conv_ovf_u2_un () {
773                 uint c;
774
775                 checked {
776                         c = 65535;
777                         UInt16 b = (UInt16)c;
778                 }
779                 
780                 return 0;
781         }
782         
783         public static int test_0_conv_ovf_u4 () {
784                 int c;
785
786                 checked {
787                         c = 0x7fffffff;
788                         uint b = (uint)c;
789                 }
790                 
791                 return 0;
792         }
793
794         public static int test_0_conv_ovf_i4_un () {
795                 uint c;
796
797                 checked {
798                         c = 0x7fffffff;
799                         int b = (int)c;
800                 }
801
802                 return 0;
803         }
804         
805         public static int test_0_bool () {
806                 bool val = true;
807                 if (val)
808                         return 0;
809                 return 1;
810         }
811         
812         public static int test_1_bool_inverted () {
813                 bool val = true;
814                 if (!val)
815                         return 0;
816                 return 1;
817         }
818
819         public static int test_1_bool_assign () {
820                 bool val = true;
821                 val = !val; // this should produce a ceq
822                 if (val)
823                         return 0;
824                 return 1;
825         }
826
827         public static int test_1_bool_multi () {
828                 bool val = true;
829                 bool val2 = true;
830                 val = !val;
831                 if ((val && !val2) && (!val2 && val))
832                         return 0;
833                 return 1;
834         }
835
836         public static int test_16_spill () {
837                 int a = 1;
838                 int b = 2;
839                 int c = 3;
840                 int d = 4;
841                 int e = 5;
842
843                 return (1 + (a + (b + (c + (d + e)))));
844         }
845
846         public static int test_1_switch () {
847                 int n = 0;
848
849                 switch (n) {
850                 case 0: return 1;
851                 case 1: return 2;
852                 case -1: return 3;
853                 default:
854                         return 4;
855                 }
856                 return 1;
857         }
858
859         public static int test_0_switch_constprop () {
860                 int n = -1;
861
862                 switch (n) {
863                 case 0: return 2;
864                 case 1: return 3;
865                 case 2: return 3;                       
866                 default:
867                         return 0;
868                 }
869                 return 3;
870         }
871
872         public static int test_0_switch_constprop2 () {
873                 int n = 3;
874
875                 switch (n) {
876                 case 0: return 2;
877                 case 1: return 3;
878                 case 2: return 3;                       
879                 default:
880                         return 0;
881                 }
882                 return 3;
883         }
884
885         public static int test_0_while_loop_1 () {
886
887                 int value = 255;
888                 
889                 do {
890                         value = value >> 4;
891                 } while (value != 0);
892                 
893                 return 0;
894         }
895
896         public static int test_0_while_loop_2 () {
897                 int value = 255;
898                 int position = 5;
899                 
900                 do {
901                         value = value >> 4;
902                 } while (value != 0 && position > 1);
903         
904                 return 0;
905         }
906
907         public static int test_0_char_conv () {
908                 int i = 1;
909                 
910                 char tc = (char) ('0' + i);
911
912                 if (tc != '1')
913                         return 1;
914                 
915                 return 0;
916         }
917
918         public static int test_3_shift_regalloc () {
919                 int shift = 8;
920                 int orig = 1;
921                 byte value = 0xfe;
922
923                 orig &= ~(0xff << shift);
924                 orig |= value << shift;
925
926                 if (orig == 0xfe01)
927                         return 3;
928                 return 0;
929         }
930
931         enum E {A, B};
932         
933         public static int test_2_optimize_branches () {
934                 switch (E.A) {
935                 case E.A:
936                         if (E.A == E.B) {
937                         }
938                         break;
939                 }
940                 return 2;
941         }
942
943         public static int test_0_checked_byte_cast () {
944                 int v = 250;
945                 int b = checked ((byte) (v));
946
947                 if (b != 250)
948                         return 1;
949                 return 0;
950         }
951
952         public static int test_0_checked_byte_cast_un () {
953                 uint v = 250;
954                 uint b = checked ((byte) (v));
955
956                 if (b != 250)
957                         return 1;
958                 return 0;
959         }
960
961         public static int test_0_checked_short_cast () {
962                 int v = 250;
963                 int b = checked ((ushort) (v));
964
965                 if (b != 250)
966                         return 1;
967                 return 0;
968         }
969
970         public static int test_0_checked_short_cast_un () {
971                 uint v = 250;
972                 uint b = checked ((ushort) (v));
973
974                 if (b != 250)
975                         return 1;
976                 return 0;
977         }
978         
979         public static int test_1_a_eq_b_plus_a () {
980                 int a = 0, b = 1;
981                 a = b + a;
982                 return a;
983         }
984
985         public static int test_0_comp () {
986                 int a = 0;
987                 int b = -1;
988                 int error = 1;
989                 bool val;
990
991                 val = a < b;
992                 if (val)
993                         return error;
994                 error++;
995
996                 val = a > b;
997                 if (!val)
998                         return error;
999                 error ++;
1000
1001                 val = a == b;
1002                 if (val)
1003                         return error;
1004                 error ++;
1005
1006                 val = a == a;
1007                 if (!val)
1008                         return error;
1009                 error ++;
1010
1011                 return 0;
1012         }
1013
1014         public static int test_0_comp_unsigned () {
1015                 uint a = 1;
1016                 uint b = 0xffffffff;
1017                 int error = 1;
1018                 bool val;
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 == b;
1031                 if (val)
1032                         return error;
1033                 error++;
1034
1035                 val = a >= b;
1036                 if (val)
1037                         return error;
1038                 error++;
1039
1040                 val = a > b;
1041                 if (val)
1042                         return error;
1043                 error++;
1044
1045                 val = b < a;
1046                 if (val)
1047                         return error;
1048                 error++;
1049
1050                 val = b <= a;
1051                 if (val)
1052                         return error;
1053                 error++;
1054
1055                 val = b == a;
1056                 if (val)
1057                         return error;
1058                 error++;
1059
1060                 val = b > a;
1061                 if (!val)
1062                         return error;
1063                 error++;
1064
1065                 val = b >= a;
1066                 if (!val)
1067                         return error;
1068                 error++;
1069
1070                 return 0;
1071         }
1072         
1073         public static int test_16_cmov () 
1074         {
1075                 int n = 0;
1076                 if (n == 0)
1077                         n = 16;
1078                 
1079                 return n;
1080         }
1081
1082         public static int test_0_and_cmp ()
1083         {
1084                 /* test esi, imm */
1085                 int local = 0x01020304;
1086                 
1087                 if ((local & 0x01020304) == 0)
1088                         return 7;
1089                 
1090                 if ((local & 0x00000304) == 0)
1091                         return 8;
1092                 
1093                 if ((local & 0x00000004) == 0)
1094                         return 9;
1095                 
1096                 if ((local & 0x00000300) == 0)
1097                         return 10;
1098                 
1099                 if ((local & 0x00020000) == 0)
1100                         return 11;
1101                 
1102                 if ((local & 0x01000000) == 0)
1103                         return 12;
1104
1105                 return 0;
1106         }
1107
1108         public static int test_0_mul_imm_opt ()
1109         {
1110                 int i;
1111
1112                 i = 1;
1113                 if ((i * 2) != 2)
1114                         return 1;
1115                 i = -1;
1116                 if ((i * 2) != -2)
1117                         return 2;
1118                 i = 1;
1119                 if ((i * 3) != 3)
1120                         return 3;
1121                 i = -1;
1122                 if ((i * 3) != -3)
1123                         return 4;
1124                 i = 1;
1125                 if ((i * 5) != 5)
1126                         return 5;
1127                 i = -1;
1128                 if ((i * 5) != -5)
1129                         return 6;
1130                 i = 1;
1131                 if ((i * 6) != 6)
1132                         return 7;
1133                 i = -1;
1134                 if ((i * 6) != -6)
1135                         return 8;
1136                 i = 1;
1137                 if ((i * 9) != 9)
1138                         return 9;
1139                 i = -1;
1140                 if ((i * 9) != -9)
1141                         return 10;
1142                 i = 1;
1143                 if ((i * 10) != 10)
1144                         return 11;
1145                 i = -1;
1146                 if ((i * 10) != -10)
1147                         return 12;
1148                 i = 1;
1149                 if ((i * 12) != 12)
1150                         return 13;
1151                 i = -1;
1152                 if ((i * 12) != -12)
1153                         return 14;
1154                 i = 1;
1155                 if ((i * 25) != 25)
1156                         return 15;
1157                 i = -1;
1158                 if ((i * 25) != -25)
1159                         return 16;
1160                 i = 1;
1161                 if ((i * 100) != 100)
1162                         return 17;
1163                 i = -1;
1164                 if ((i * 100) != -100)
1165                         return 18;
1166                 
1167                 return 0;
1168         }
1169         
1170         public static int test_0_cne ()
1171         {
1172                 int x = 0;
1173                 int y = 1;
1174                 
1175                 bool b = x != y;
1176                 bool bb = x != x;
1177                 
1178                 if (!b)
1179                         return 1;
1180                 if (bb)
1181                         return 2;
1182                 
1183                 return 0;
1184         }
1185
1186         public static int test_0_cmp_regvar_zero ()
1187         {
1188                 int n = 10;
1189                 
1190                 if (!(n > 0 && n >= 0 && n != 0))
1191                         return 1;
1192                 if (n < 0 || n <= 0 || n == 0)
1193                         return 1;
1194                 
1195                 return 0;
1196         }
1197
1198         public static int test_5_div_un_cfold ()
1199         {
1200                 uint i = 10;
1201                 uint j = 2;
1202
1203                 return (int)(i / j);
1204         }
1205
1206         public static int test_1_rem_un_cfold ()
1207         {
1208                 uint i = 11;
1209                 uint j = 2;
1210
1211                 return (int)(i % j);
1212         }
1213
1214         public static int test_0_div_opt () {
1215                 int i;
1216
1217                 // Avoid cfolding this
1218                 i = 0;
1219                 for (int j = 0; j < 1234567; ++j)
1220                         i ++;
1221                 if ((i / 2) != 617283)
1222                         return 1;
1223                 if ((i / 4) != 308641)
1224                         return 2;
1225                 if ((i / 8) != 154320)
1226                         return 3;
1227                 if ((i / 16) != 77160)
1228                         return 4;
1229
1230                 // Avoid cfolding this
1231                 i = 0;
1232                 for (int j = 0; j < 1234567; ++j)
1233                         i --;
1234                 if ((i / 2) != -617283)
1235                         return 5;
1236                 if ((i / 4) != -308641)
1237                         return 6;
1238                 if ((i / 8) != -154320)
1239                         return 7;
1240                 if ((i / 16) != -77160)
1241                         return 8;
1242
1243                 return 0;
1244         }
1245
1246         public static int test_0_rem_opt () {
1247                 int i;
1248
1249                 // Avoid cfolding this
1250                 i = 0;
1251                 for (int j = 0; j < 29; ++j)
1252                         i ++;
1253                 if ((i % 2) != 1)
1254                         return 1;
1255                 if ((i % 4) != 1)
1256                         return 2;
1257                 if ((i % 8) != 5)
1258                         return 3;
1259                 if ((i % 16) != 13)
1260                         return 4;
1261
1262                 // Avoid cfolding this
1263                 i = 0;
1264                 for (int j = 0; j < 29; ++j)
1265                         i --;
1266                 if ((i % 2) != -1)
1267                         return 5;
1268                 if ((i % 4) != -1)
1269                         return 6;
1270                 if ((i % 8) != -5)
1271                         return 7;
1272                 if ((i % 16) != -13)
1273                         return 8;
1274
1275                 return 0;
1276         }
1277
1278 }