1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
//
// This test excercises a few new optimizations that were entered in the context
// of Binary operators and EmitBranchable.
//
// There are a number of cases:
//
// EmitBranchable can be called with an `onTrue' (false for if, true for loops).
//
// The == and != operators handle the Null compares specially
using System;
class X {
static int one = 1;
static int two = 2;
static int three = 3;
static int four = 4;
static bool t = true;
static bool f = false;
static int fcalls = 0;
static int tcalls = 0;
static bool ff ()
{
fcalls++;
return false;
}
static bool tt ()
{
tcalls++;
return true;
}
static int test_if ()
{
//
// Ands in the if context
//
if (f && f)
return 1;
if (t && f)
return 2;
if (f && t)
return 3;
if (one < two && f)
return 4;
if (one > two && t)
return 5;
if (one < two && t)
Console.WriteLine ("");
if (ff () && ff ())
return 6;
if (fcalls != 1)
return 10;
if (tt () && tt ()){
if (tcalls != 2)
return 11;
if (tt () && ff ())
return 8;
if (tcalls != 3)
return 12;
if (fcalls != 2)
return 13;
if (ff () && tt ())
return 9;
if (fcalls != 3)
return 14;
if (tcalls != 3)
return 15;
} else
return 7;
if (one < two && four > three){
if (one == one && two != three){
} else
return 20;
} else
return 21;
if (one == two || two != two)
return 22;
object o = null;
if (o == null || false){
o = 1;
if (o != null || false)
o = null;
else
return 23;
if (true || o == null){
if (o != null || o == null){
if (o == null && o != null)
return 25;
if (o == null && one == two)
return 26;
if (one == one && o != null)
return 27;
o = 1;
if (two == two && o == null)
return 28;
return 0;
}
return 25;
}
return 26;
}
return 27;
}
//
// This tests emitbranchable with an `onTrue' set to tru
//
static int test_while ()
{
int count = 0;
while (t && t){
count++;
break;
}
if (count != 1)
return 1;
while (f || t){
count++; break;
}
if (count != 2)
return 2;
while (f || f){
count++; break;
}
if (count != 2)
return 3;
while (one < two && two > one){
count++;
break;
}
if (count != 3)
return 4;
while (one < one || two > one){
count++;
break;
}
if (count != 4)
return 5;
while (one < one || two > two){
count++;
break;
}
if (count != 4)
return 6;
while (one < two && t){
count++;
break;
}
if (count != 5)
return 7;
while (one < one || t){
count++;
break;
}
if (count != 6)
return 8;
while (one < one || f){
count++;
break;
}
if (count != 6)
return 9;
return 0;
}
static int test_inline ()
{
bool lt = t || f;
if (!lt)
return 1;
return 0;
}
public static int Main ()
{
int v;
object o = null;
if (o == null || false)
o = 1;
else
o = 2;
Console.WriteLine ("V: "+ o);
v = test_if ();
if (v != 0)
return v;
v = test_inline ();
if (v != 0)
return 30 + v;
v = test_while ();
if (v != 0)
return 90 + v;
Console.WriteLine ("test ok");
return 0;
}
}
|