Merge pull request #757 from mlintner/master
[mono.git] / mono / mini / basic.cs
index 8cdad90e5f2b537bd933d420b562a2c6706e2657..477af333e9b4a8401a8b6ec5ab4e7646e6044ac3 100644 (file)
@@ -23,180 +23,207 @@ using System.Reflection;
  * the IL code looks.
  */
 
-class Tests {
-
-       static int Main () {
-               return TestDriver.RunTests (typeof (Tests));
-       }
+#if MOBILE
+class BasicTests
+#else
+class Tests
+#endif
+{
+
+#if !MOBILE
+       public static int Main (string[] args) {
+               return TestDriver.RunTests (typeof (Tests), args);
+       }
+#endif
        
-       static int test_0_return () {
+       public static int test_0_return () {
                return 0;
        }
 
-       static int test_100000_return_large () {
+       public static int test_100000_return_large () {
                return 100000;
        }
 
-       static int test_1_load_bool () {
+       public static int test_1_load_bool () {
                bool a = true;
                return a? 1: 0;
        }
 
-       static int test_0_load_bool_false () {
+       public static int test_0_load_bool_false () {
                bool a = false;
                return a? 1: 0;
        }
 
-       static int test_200_load_byte () {
+       public static int test_200_load_byte () {
                byte a = 200;
                return a;
        }
 
-       static int test_100_load_sbyte () {
+       public static int test_100_load_sbyte () {
                sbyte a = 100;
                return a;
        }
 
-       static int test_200_load_short () {
+       public static int test_200_load_short () {
                short a = 200;
                return a;
        }
 
-       static int test_100_load_ushort () {
+       public static int test_100_load_ushort () {
                ushort a = 100;
                return a;
        }
 
-       static int test_3_add_simple () {
+       public static int test_3_add_simple () {
                int a = 1; 
                int b = 2;
                return a + b;
        }
 
-       static int test_3_add_imm () {
+       public static int test_3_add_imm () {
                int a = 1; 
                return a + 2;
        }
 
-       static int test_13407573_add_largeimm () {
+       public static int test_13407573_add_largeimm () {
                int a = 1; 
                return a + 13407572;
        }
 
-       static int test_1_sub_simple () {
+       public static int test_1_sub_simple () {
                int a = 1; 
                int b = 2;
                return b - a;
        }
 
-       static int test_1_sub_simple_un () {
+       public static int test_1_sub_simple_un () {
                uint a = 1; 
                uint b = 2;
                return (int)(b - a);
        }
 
-       static int test_1_sub_imm () {
+       public static int test_1_sub_imm () {
                int b = 2;
                return b - 1;
        }
 
-       static int test_2_sub_large_imm () {
+       public static int test_2_sub_large_imm () {
                int b = 0xff0f0f;
                return b - 0xff0f0d;
        }
 
-       static int test_0_sub_inv_imm () {
+       public static int test_0_sub_inv_imm () {
                int b = 2;
                return 2 - b;
        }
 
-       static int test_2_and () {
+       public static int test_2_and () {
                int b = 2;
                int a = 3;
                return b & a;
        }
 
-       static int test_0_and_imm () {
+       public static int test_0_and_imm () {
                int b = 2;
                return b & 0x10;
        }
 
-       static int test_0_and_large_imm () {
+       public static int test_0_and_large_imm () {
                int b = 2;
                return b & 0x10000000;
        }
 
-       static int test_0_and_large_imm2 () {
+       public static int test_0_and_large_imm2 () {
                int b = 2;
                return b & 0x100000f0;
        }
 
-       static int test_2_div () {
+       public static int test_2_div () {
                int b = 6;
                int a = 3;
                return b / a;
        }
 
-       static int test_4_div_imm () {
+       public static int test_4_div_imm () {
                int b = 12;
                return b / 3;
        }
 
-       static int test_4_divun_imm () {
+       public static int test_4_divun_imm () {
                uint b = 12;
                return (int)(b / 3);
        }
 
-       static int test_0_div_fold () {
+       public static int test_0_div_fold () {
                int b = -1;
                return b / 2;
        }
 
-       static int test_719177_div_destreg () {
+       public static int test_2_div_fold4 () {
+               int b = -8;
+               return -(b / 4);
+       }
+
+       public static int test_2_div_fold16 () {
+               int b = 32;
+               return b / 16;
+       }
+
+       public static int test_719177_div_destreg () {
                int year = 1970;
                return ((365* (year-1)) + ((year-1)/4));
        }
 
-       static int test_1_remun_imm () {
+       public static int test_1_remun_imm () {
                uint b = 13;
                return (int)(b % 3);
        }
 
-       static int test_2_bigremun_imm () {
+       public static int test_2_bigremun_imm () {
                unchecked {
                        uint b = (uint)-2;
                        return (int)(b % 3);
                }
        }
 
-       static int test_2_rem () {
+       public static int test_2_rem () {
                int b = 5;
                int a = 3;
                return b % a;
        }
 
-       static int test_4_rem_imm () {
+       public static int test_4_rem_imm () {
                int b = 12;
                return b % 8;
        }
 
-       static int test_4_rem_big_imm () {
+       public static int test_0_rem_imm_0 () {
+               int b = 12;
+               return b % 1;
+       }
+
+       public static int test_0_rem_imm_0_neg () {
+               int b = -2;
+               return b % 1;
+       }
+
+       public static int test_4_rem_big_imm () {
                int b = 10004;
                return b % 10000;
        }
 
-       static int test_9_mul () {
+       public static int test_9_mul () {
                int b = 3;
                int a = 3;
                return b * a;
        }
 
-       static int test_15_mul_imm () {
+       public static int test_15_mul_imm () {
                int b = 3;
                return b * 5;
        }
 
-       static int test_24_mul () {
+       public static int test_24_mul () {
                int a = 3;
                int b = 8;
                int res;
@@ -206,7 +233,7 @@ class Tests {
                return res;
        }
 
-       static int test_24_mul_ovf () {
+       public static int test_24_mul_ovf () {
                int a = 3;
                int b = 8;
                int res;
@@ -218,7 +245,7 @@ class Tests {
                return res;
        }
 
-       static int test_24_mul_un () {
+       public static int test_24_mul_un () {
                uint a = 3;
                uint b = 8;
                uint res;
@@ -228,7 +255,7 @@ class Tests {
                return (int)res;
        }
 
-       static int test_24_mul_ovf_un () {
+       public static int test_24_mul_ovf_un () {
                uint a = 3;
                uint b = 8;
                uint res;
@@ -240,125 +267,324 @@ class Tests {
                return (int)res;
        }
 
-       static int test_0_add_un_ovf () {
+       public static int test_0_add_ovf1 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MinValue;
+                       j = 0;
+                       k = i + j;
+               }
+
+               if (k != System.Int32.MinValue)
+                       return 1;
+               return 0;
+       }
+
+       public static int test_0_add_ovf2 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MaxValue;
+                       j = 0;
+                       k = i + j;
+               }
+
+               if (k != System.Int32.MaxValue)
+                       return 2;
+               return 0;
+       }
+
+       public static int test_0_add_ovf3 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MinValue;
+                       j = System.Int32.MaxValue;
+                       k = i + j;
+               }
+
+               if (k != -1)
+                       return 3;
+               return 0;
+       }
+
+       public static int test_0_add_ovf4 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MaxValue;
+                       j = System.Int32.MinValue;
+                       k = i + j;
+               }
+
+               if (k != -1)
+                       return 4;
+               return 0;
+       }
+
+       public static int test_0_add_ovf5 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MinValue + 1234;
+                       j = -1234;
+                       k = i + j;
+               }
+
+               if (k != System.Int32.MinValue)
+                       return 5;
+               return 0;
+       }
+
+       public static int test_0_add_ovf6 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MaxValue - 1234;
+                       j = 1234;
+                       k = i + j;
+               }
+
+               if (k != System.Int32.MaxValue)
+                       return 6;
+
+               return 0;
+       }
+
+       public static int test_0_add_un_ovf () {
                uint n = (uint)134217728 * 16;
                uint number = checked (n + (uint)0);
 
                return number == n ? 0 : 1;
        }
 
-       static int test_3_or () {
+       public static int test_0_sub_ovf1 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MinValue;
+                       j = 0;
+                       k = i - j;
+               }
+
+               if (k != System.Int32.MinValue)
+                       return 1;
+
+               return 0;
+       }
+
+       public static int test_0_sub_ovf2 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MaxValue;
+                       j = 0;
+                       k = i - j;
+               }
+
+               if (k != System.Int32.MaxValue)
+                       return 2;
+
+               return 0;
+       }
+
+       public static int test_0_sub_ovf3 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MinValue;
+                       j = System.Int32.MinValue + 1234;
+                       k = i - j;
+               }
+
+               if (k != -1234)
+                       return 3;
+
+               return 0;
+       }
+
+       public static int test_0_sub_ovf4 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MaxValue;
+                       j = 1234;
+                       k = i - j;
+               }
+
+               if (k != System.Int32.MaxValue - 1234)
+                       return 4;
+
+               return 0;
+       }
+
+       public static int test_0_sub_ovf5 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MaxValue - 1234;
+                       j = -1234;
+                       k = i - j;
+               }
+
+               if (k != System.Int32.MaxValue)
+                       return 5;
+
+               return 0;
+       }
+
+       public static int test_0_sub_ovf6 () {
+               int i, j, k;
+
+               checked {
+                       i = System.Int32.MinValue + 1234;
+                       j = 1234;
+                       k = i - j;
+               }
+
+               if (k != System.Int32.MinValue)
+                       return 6;
+
+               return 0;
+       }
+
+       public static int test_0_sub_ovf_un () {
+               uint i, j, k;
+
+               checked {
+                       i = System.UInt32.MaxValue;
+                       j = 0;
+                       k = i - j;
+               }
+
+               if (k != System.UInt32.MaxValue)
+                       return 1;
+
+               checked {
+                       i = System.UInt32.MaxValue;
+                       j = System.UInt32.MaxValue;
+                       k = i - j;
+               }
+
+               if (k != 0)
+                       return 2;
+
+               return 0;
+       }
+
+       public static int test_3_or () {
                int b = 2;
                int a = 3;
                return b | a;
        }
 
-       static int test_3_or_un () {
+       public static int test_3_or_un () {
                uint b = 2;
                uint a = 3;
                return (int)(b | a);
        }
 
-       static int test_3_or_short_un () {
+       public static int test_3_or_short_un () {
                ushort b = 2;
                ushort a = 3;
                return (int)(b | a);
        }
 
-       static int test_18_or_imm () {
+       public static int test_18_or_imm () {
                int b = 2;
                return b | 0x10;
        }
 
-       static int test_268435458_or_large_imm () {
+       public static int test_268435458_or_large_imm () {
                int b = 2;
                return b | 0x10000000;
        }
 
-       static int test_268435459_or_large_imm2 () {
+       public static int test_268435459_or_large_imm2 () {
                int b = 2;
                return b | 0x10000001;
        }
 
-       static int test_1_xor () {
+       public static int test_1_xor () {
                int b = 2;
                int a = 3;
                return b ^ a;
        }
 
-       static int test_1_xor_imm () {
+       public static int test_1_xor_imm () {
                int b = 2;
                return b ^ 3;
        }
 
-       static int test_983041_xor_imm_large () {
+       public static int test_983041_xor_imm_large () {
                int b = 2;
                return b ^ 0xf0003;
        }
 
-       static int test_1_neg () {
+       public static int test_1_neg () {
                int b = -2;
                b++;
                return -b;
        }
 
-       static int test_2_not () {
+       public static int test_2_not () {
                int b = ~2;
                b = ~b;
                return b;
        }
 
-       static int test_16_shift () {
+       public static int test_16_shift () {
                int b = 2;
                int a = 3;
                return b << a;
        }
        
-       static int test_16_shift_add () {
+       public static int test_16_shift_add () {
                int b = 2;
                int a = 3;
                int c = 0;
                return b << (a + c);
        }
        
-       static int test_16_shift_add2 () {
+       public static int test_16_shift_add2 () {
                int b = 2;
                int a = 3;
                int c = 0;
                return (b + c) << a;
        }
        
-       static int test_16_shift_imm () {
+       public static int test_16_shift_imm () {
                int b = 2;
                return b << 3;
        }
        
-       static int test_524288_shift_imm_large () {
+       public static int test_524288_shift_imm_large () {
                int b = 2;
                return b << 18;
        }
        
-       static int test_12_shift_imm_inv () {
+       public static int test_12_shift_imm_inv () {
                int b = 2;
                return 3 << 2;
        }
 
-       static int test_12_shift_imm_inv_sbyte () {
+       public static int test_12_shift_imm_inv_sbyte () {
                sbyte b = 2;
                return 3 << 2;
        }
 
-       static int test_1_rshift_imm () {
+       public static int test_1_rshift_imm () {
                int b = 8;
                return b >> 3;
        }
        
-       static int test_2_unrshift_imm () {
+       public static int test_2_unrshift_imm () {
                uint b = 16;
                return (int)(b >> 3);
        }
        
-       static int test_0_bigunrshift_imm () {
+       public static int test_0_bigunrshift_imm () {
                unchecked {
                        uint b = (uint)-1;
                        b = b >> 1;
@@ -368,7 +594,7 @@ class Tests {
                }
        }
        
-       static int test_0_bigrshift_imm () {
+       public static int test_0_bigrshift_imm () {
                int b = -1;
                b = b >> 1;
                if (b != -1)
@@ -376,19 +602,19 @@ class Tests {
                return 0;
        }
        
-       static int test_1_rshift () {
+       public static int test_1_rshift () {
                int b = 8;
                int a = 3;
                return b >> a;
        }
        
-       static int test_2_unrshift () {
+       public static int test_2_unrshift () {
                uint b = 16;
                int a = 3;
                return (int)(b >> a);
        }
        
-       static int test_0_bigunrshift () {
+       public static int test_0_bigunrshift () {
                unchecked {
                        uint b = (uint)-1;
                        int a = 1;
@@ -399,7 +625,7 @@ class Tests {
                }
        }
        
-       static int test_0_bigrshift () {
+       public static int test_0_bigrshift () {
                int b = -1;
                int a = 1;
                b = b >> a;
@@ -408,28 +634,28 @@ class Tests {
                return 0;
        }
        
-       static int test_2_cond () {
+       public static int test_2_cond () {
                int b = 2, a = 3, c;
                if (a == b)
                        return 0;
                return 2;
        }
        
-       static int test_2_cond_short () {
+       public static int test_2_cond_short () {
                short b = 2, a = 3, c;
                if (a == b)
                        return 0;
                return 2;
        }
        
-       static int test_2_cond_sbyte () {
+       public static int test_2_cond_sbyte () {
                sbyte b = 2, a = 3, c;
                if (a == b)
                        return 0;
                return 2;
        }
        
-       static int test_6_cascade_cond () {
+       public static int test_6_cascade_cond () {
                int b = 2, a = 3, c;
                if (a == b)
                        return 0;
@@ -443,7 +669,7 @@ class Tests {
                return a + b + c;
        }
        
-       static int test_6_cascade_short () {
+       public static int test_6_cascade_short () {
                short b = 2, a = 3, c;
                if (a == b)
                        return 0;
@@ -457,7 +683,7 @@ class Tests {
                return a + b + c;
        }
 
-       static int test_0_short_sign_extend () {
+       public static int test_0_short_sign_extend () {
                int t1 = 0xffeedd;
                short s1 = (short)t1;
                int t2 = s1;
@@ -466,16 +692,30 @@ class Tests {
                        return 1;
                else
                        return 0;
-       }               
+       }
+
+       public static int test_127_iconv_to_i1 () {
+               int i = 0x100017f;
+               sbyte s = (sbyte)i;
+
+               return s;
+       }
+
+       public static int test_384_iconv_to_i2 () {
+               int i = 0x1000180;
+               short s = (short)i;
+
+               return s;
+       }
        
-       static int test_15_for_loop () {
+       public static int test_15_for_loop () {
                int i;
                for (i = 0; i < 15; ++i) {
                }
                return i;
        }
        
-       static int test_11_nested_for_loop () {
+       public static int test_11_nested_for_loop () {
                int i, j = 0; /* mcs bug here if j not set */
                for (i = 0; i < 15; ++i) {
                        for (j = 200; j >= 5; --j) ;
@@ -483,7 +723,7 @@ class Tests {
                return i - j;
        }
 
-       static int test_11_several_nested_for_loops () {
+       public static int test_11_several_nested_for_loops () {
                int i, j = 0; /* mcs bug here if j not set */
                for (i = 0; i < 15; ++i) {
                        for (j = 200; j >= 5; --j) ;
@@ -495,7 +735,7 @@ class Tests {
                return i - j;
        }
 
-       static int test_0_conv_ovf_i1 () {
+       public static int test_0_conv_ovf_i1 () {
                int c;
 
                //for (int j = 0; j < 10000000; j++)
@@ -509,7 +749,7 @@ class Tests {
                return 0;
        }
        
-       static int test_0_conv_ovf_i1_un () {
+       public static int test_0_conv_ovf_i1_un () {
                uint c;
 
                checked {
@@ -520,7 +760,7 @@ class Tests {
                return 0;
        }
        
-       static int test_0_conv_ovf_i2 () {
+       public static int test_0_conv_ovf_i2 () {
                int c;
 
                checked {
@@ -538,7 +778,7 @@ class Tests {
                return 0;
        }
        
-       static int test_0_conv_ovf_i2_un () {
+       public static int test_0_conv_ovf_i2_un () {
                uint c;
 
                checked {
@@ -549,7 +789,7 @@ class Tests {
                return 0;
        }
        
-       static int test_0_conv_ovf_u2 () {
+       public static int test_0_conv_ovf_u2 () {
                int c;
 
                checked {
@@ -560,7 +800,7 @@ class Tests {
                return 0;
        }
        
-       static int test_0_conv_ovf_u2_un () {
+       public static int test_0_conv_ovf_u2_un () {
                uint c;
 
                checked {
@@ -571,7 +811,7 @@ class Tests {
                return 0;
        }
        
-       static int test_0_conv_ovf_u4 () {
+       public static int test_0_conv_ovf_u4 () {
                int c;
 
                checked {
@@ -581,22 +821,33 @@ class Tests {
                
                return 0;
        }
+
+       public static int test_0_conv_ovf_i4_un () {
+               uint c;
+
+               checked {
+                       c = 0x7fffffff;
+                       int b = (int)c;
+               }
+
+               return 0;
+       }
        
-       static int test_0_bool () {
+       public static int test_0_bool () {
                bool val = true;
                if (val)
                        return 0;
                return 1;
        }
        
-       static int test_1_bool_inverted () {
+       public static int test_1_bool_inverted () {
                bool val = true;
                if (!val)
                        return 0;
                return 1;
        }
 
-       static int test_1_bool_assign () {
+       public static int test_1_bool_assign () {
                bool val = true;
                val = !val; // this should produce a ceq
                if (val)
@@ -604,7 +855,7 @@ class Tests {
                return 1;
        }
 
-       static int test_1_bool_multi () {
+       public static int test_1_bool_multi () {
                bool val = true;
                bool val2 = true;
                val = !val;
@@ -613,7 +864,7 @@ class Tests {
                return 1;
        }
 
-       static int test_16_spill () {
+       public static int test_16_spill () {
                int a = 1;
                int b = 2;
                int c = 3;
@@ -623,7 +874,7 @@ class Tests {
                return (1 + (a + (b + (c + (d + e)))));
        }
 
-       static int test_1_switch () {
+       public static int test_1_switch () {
                int n = 0;
 
                switch (n) {
@@ -636,7 +887,7 @@ class Tests {
                return 1;
        }
 
-       static int test_0_switch_constprop () {
+       public static int test_0_switch_constprop () {
                int n = -1;
 
                switch (n) {
@@ -649,7 +900,7 @@ class Tests {
                return 3;
        }
 
-       static int test_0_switch_constprop2 () {
+       public static int test_0_switch_constprop2 () {
                int n = 3;
 
                switch (n) {
@@ -662,7 +913,7 @@ class Tests {
                return 3;
        }
 
-       static int test_0_while_loop_1 () {
+       public static int test_0_while_loop_1 () {
 
                int value = 255;
                
@@ -673,7 +924,7 @@ class Tests {
                return 0;
        }
 
-       static int test_0_while_loop_2 () {
+       public static int test_0_while_loop_2 () {
                int value = 255;
                int position = 5;
                
@@ -684,7 +935,7 @@ class Tests {
                return 0;
        }
 
-       static int test_0_char_conv () {
+       public static int test_0_char_conv () {
                int i = 1;
                
                char tc = (char) ('0' + i);
@@ -695,16 +946,7 @@ class Tests {
                return 0;
        }
 
-       static unsafe int test_0_pin_string () {
-               string x = "xxx";
-               fixed (char *c = x) {
-                       if (*c != 'x')
-                               return 1;
-               }
-               return 0;
-       }
-
-       static int test_3_shift_regalloc () {
+       public static int test_3_shift_regalloc () {
                int shift = 8;
                int orig = 1;
                byte value = 0xfe;
@@ -719,7 +961,7 @@ class Tests {
 
        enum E {A, B};
        
-       static int test_2_optimize_branches () {
+       public static int test_2_optimize_branches () {
                switch (E.A) {
                case E.A:
                        if (E.A == E.B) {
@@ -729,7 +971,7 @@ class Tests {
                return 2;
        }
 
-       static int test_0_checked_byte_cast () {
+       public static int test_0_checked_byte_cast () {
                int v = 250;
                int b = checked ((byte) (v));
 
@@ -738,7 +980,7 @@ class Tests {
                return 0;
        }
 
-       static int test_0_checked_byte_cast_un () {
+       public static int test_0_checked_byte_cast_un () {
                uint v = 250;
                uint b = checked ((byte) (v));
 
@@ -747,7 +989,7 @@ class Tests {
                return 0;
        }
 
-       static int test_0_checked_short_cast () {
+       public static int test_0_checked_short_cast () {
                int v = 250;
                int b = checked ((ushort) (v));
 
@@ -756,7 +998,7 @@ class Tests {
                return 0;
        }
 
-       static int test_0_checked_short_cast_un () {
+       public static int test_0_checked_short_cast_un () {
                uint v = 250;
                uint b = checked ((ushort) (v));
 
@@ -765,13 +1007,13 @@ class Tests {
                return 0;
        }
        
-       static int test_1_a_eq_b_plus_a () {
+       public static int test_1_a_eq_b_plus_a () {
                int a = 0, b = 1;
                a = b + a;
                return a;
        }
 
-       static int test_0_comp () {
+       public static int test_0_comp () {
                int a = 0;
                int b = -1;
                int error = 1;
@@ -800,7 +1042,7 @@ class Tests {
                return 0;
        }
 
-       static int test_0_comp_unsigned () {
+       public static int test_0_comp_unsigned () {
                uint a = 1;
                uint b = 0xffffffff;
                int error = 1;
@@ -859,7 +1101,7 @@ class Tests {
                return 0;
        }
        
-       static int test_16_cmov () 
+       public static int test_16_cmov () 
        {
                int n = 0;
                if (n == 0)
@@ -867,33 +1109,9 @@ class Tests {
                
                return n;
        }
-       
-       static int my_flags;
-       static int test_0_and_cmp ()
+
+       public static int test_0_and_cmp ()
        {
-               
-               /* various forms of test [mem], imm */
-               
-               my_flags = 0x01020304;
-               
-               if ((my_flags & 0x01020304) == 0)
-                       return 1;
-               
-               if ((my_flags & 0x00000304) == 0)
-                       return 2;
-               
-               if ((my_flags & 0x00000004) == 0)
-                       return 3;
-               
-               if ((my_flags & 0x00000300) == 0)
-                       return 4;
-               
-               if ((my_flags & 0x00020000) == 0)
-                       return 5;
-               
-               if ((my_flags & 0x01000000) == 0)
-                       return 6;
-               
                /* test esi, imm */
                int local = 0x01020304;
                
@@ -914,11 +1132,73 @@ class Tests {
                
                if ((local & 0x01000000) == 0)
                        return 12;
+
+               return 0;
+       }
+
+       public static int test_0_mul_imm_opt ()
+       {
+               int i;
+
+               i = 1;
+               if ((i * 2) != 2)
+                       return 1;
+               i = -1;
+               if ((i * 2) != -2)
+                       return 2;
+               i = 1;
+               if ((i * 3) != 3)
+                       return 3;
+               i = -1;
+               if ((i * 3) != -3)
+                       return 4;
+               i = 1;
+               if ((i * 5) != 5)
+                       return 5;
+               i = -1;
+               if ((i * 5) != -5)
+                       return 6;
+               i = 1;
+               if ((i * 6) != 6)
+                       return 7;
+               i = -1;
+               if ((i * 6) != -6)
+                       return 8;
+               i = 1;
+               if ((i * 9) != 9)
+                       return 9;
+               i = -1;
+               if ((i * 9) != -9)
+                       return 10;
+               i = 1;
+               if ((i * 10) != 10)
+                       return 11;
+               i = -1;
+               if ((i * 10) != -10)
+                       return 12;
+               i = 1;
+               if ((i * 12) != 12)
+                       return 13;
+               i = -1;
+               if ((i * 12) != -12)
+                       return 14;
+               i = 1;
+               if ((i * 25) != 25)
+                       return 15;
+               i = -1;
+               if ((i * 25) != -25)
+                       return 16;
+               i = 1;
+               if ((i * 100) != 100)
+                       return 17;
+               i = -1;
+               if ((i * 100) != -100)
+                       return 18;
                
                return 0;
        }
        
-       static int test_0_cne ()
+       public static int test_0_cne ()
        {
                int x = 0;
                int y = 1;
@@ -933,32 +1213,159 @@ class Tests {
                
                return 0;
        }
-       
-       static byte b;
-       static int test_0_byte_compares ()
+
+       public static int test_0_cmp_regvar_zero ()
        {
-               b = 0xff;
-               if (b == -1)
-                       return 1;
-               b = 0;
-               if (!(b < System.Byte.MaxValue))
-                       return 2;
+               int n = 10;
                
-               if (!(b <= System.Byte.MaxValue))
-                       return 3;
+               if (!(n > 0 && n >= 0 && n != 0))
+                       return 1;
+               if (n < 0 || n <= 0 || n == 0)
+                       return 1;
                
                return 0;
        }
-       static int test_0_cmp_regvar_zero ()
+
+       public static int test_5_div_un_cfold ()
        {
-               int n = 10;
-               
-               if (!(n > 0 && n >= 0 && n != 0))
+               uint i = 10;
+               uint j = 2;
+
+               return (int)(i / j);
+       }
+
+       public static int test_1_rem_un_cfold ()
+       {
+               uint i = 11;
+               uint j = 2;
+
+               return (int)(i % j);
+       }
+
+       public static int test_0_div_opt () {
+               int i;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 567; ++j)
+                       i ++;
+               i += 1234000;
+               if ((i / 2) != 617283)
                        return 1;
-               if (n < 0 || n <= 0 || n == 0)
+               if ((i / 4) != 308641)
+                       return 2;
+               if ((i / 8) != 154320)
+                       return 3;
+               if ((i / 16) != 77160)
+                       return 4;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 567; ++j)
+                       i --;
+               i -= 1234000;
+               if ((i / 2) != -617283)
+                       return 5;
+               if ((i / 4) != -308641)
+                       return 6;
+               if ((i / 8) != -154320)
+                       return 7;
+               if ((i / 16) != -77160)
+                       return 8;
+
+               return 0;
+       }
+
+       public static int test_0_rem_opt () {
+               int i;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 29; ++j)
+                       i ++;
+               if ((i % 2) != 1)
                        return 1;
+               if ((i % 4) != 1)
+                       return 2;
+               if ((i % 8) != 5)
+                       return 3;
+               if ((i % 16) != 13)
+                       return 4;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 29; ++j)
+                       i --;
+               if ((i % 2) != -1)
+                       return 5;
+               if ((i % 4) != -1)
+                       return 6;
+               if ((i % 8) != -5)
+                       return 7;
+               if ((i % 16) != -13)
+                       return 8;
+
+               return 0;
+       }
+
+       public static int cmov (int i) {
+               int j = 0;
+
+               if (i > 0)
+                       j = 1;
+
+               return j;
+       }
+
+       public static int cmov2 (int i) {
+               int j = 0;
+
+               if (i <= 0)
+                       ;
+               else
+                       j = 1;
+
+               return j;
+       }
                
+       public static int test_0_branch_to_cmov_opt () {
+               if (cmov (0) != 0)
+                       return 1;
+               if (cmov (1) != 1)
+                       return 2;
+               if (cmov2 (0) != 0)
+                       return 1;
+               if (cmov2 (1) != 1)
+                       return 2;
+               return 0;
+       }
+
+       public static unsafe int test_0_ishr_sign_extend () {
+               // Check that ishr does sign extension from bit 31 on 64 bit platforms
+               uint val = 0xF0000000u;
+
+               uint *a = &val;
+               uint ui = (uint)((int)(*a) >> 2);
+
+               if (ui != 0xfc000000)
+                       return 1;
+
+               // Same with non-immediates
+               int amount = 2;
+
+               ui = (uint)((int)(*a) >> amount);
+
+               if (ui != 0xfc000000)
+                       return 2;
+
                return 0;
        }
 
+       public static unsafe int test_0_ishr_sign_extend_cfold () {
+               int i = 32768;
+               int j = i << 16;
+               int k = j >> 16;
+
+               return k == -32768 ? 0 : 1;
+       }
 }