1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import java.lang.reflect.Method; 18 19 public class Main { 20 21 public static void assertBooleanEquals(boolean expected, boolean result) { 22 if (expected != result) { 23 throw new Error("Expected: " + expected + ", found: " + result); 24 } 25 } 26 27 public static void assertIntEquals(int expected, int result) { 28 if (expected != result) { 29 throw new Error("Expected: " + expected + ", found: " + result); 30 } 31 } 32 33 public static void assertLongEquals(long expected, long result) { 34 if (expected != result) { 35 throw new Error("Expected: " + expected + ", found: " + result); 36 } 37 } 38 39 public static void assertFloatEquals(float expected, float result) { 40 if (expected != result) { 41 throw new Error("Expected: " + expected + ", found: " + result); 42 } 43 } 44 45 public static void assertDoubleEquals(double expected, double result) { 46 if (expected != result) { 47 throw new Error("Expected: " + expected + ", found: " + result); 48 } 49 } 50 51 public static void assertStringEquals(String expected, String result) { 52 if (expected == null ? result != null : !expected.equals(result)) { 53 throw new Error("Expected: " + expected + ", found: " + result); 54 } 55 } 56 57 /** 58 * Tiny programs exercising optimizations of arithmetic identities. 59 */ 60 61 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (before) 62 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 63 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 64 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const0>>,<<Arg>>] 65 /// CHECK-DAG: Return [<<Add>>] 66 67 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after) 68 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 69 /// CHECK-DAG: Return [<<Arg>>] 70 71 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after) 72 /// CHECK-NOT: Add 73 74 public static long $noinline$Add0(long arg) { 75 return 0 + arg; 76 } 77 78 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (before) 79 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue 80 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 81 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 82 /// CHECK-DAG: <<ConstM3:i\d+>> IntConstant -3 83 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4 84 /// CHECK-DAG: <<Add1:i\d+>> Add [<<ArgValue>>,<<Const1>>] 85 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Add1>>,<<Const2>>] 86 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add2>>,<<ConstM3>>] 87 /// CHECK-DAG: <<Add4:i\d+>> Add [<<Add3>>,<<Const4>>] 88 /// CHECK-DAG: Return [<<Add4>>] 89 90 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (after) 91 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue 92 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4 93 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const4>>] 94 /// CHECK-DAG: Return [<<Add>>] 95 96 public static int $noinline$AddAddSubAddConst(int arg) { 97 return arg + 1 + 2 - 3 + 4; 98 } 99 100 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (before) 101 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 102 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 103 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>] 104 /// CHECK-DAG: Return [<<And>>] 105 106 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after) 107 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 108 /// CHECK-DAG: Return [<<Arg>>] 109 110 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after) 111 /// CHECK-NOT: And 112 113 public static int $noinline$AndAllOnes(int arg) { 114 return arg & -1; 115 } 116 117 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (before) 118 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 119 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28 120 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15 121 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>] 122 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>] 123 /// CHECK-DAG: Return [<<And>>] 124 125 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after) 126 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 127 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28 128 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>] 129 /// CHECK-DAG: Return [<<UShr>>] 130 131 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after) 132 /// CHECK-NOT: And 133 134 public static int $noinline$UShr28And15(int arg) { 135 return (arg >>> 28) & 15; 136 } 137 138 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (before) 139 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 140 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60 141 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15 142 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>] 143 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>] 144 /// CHECK-DAG: Return [<<And>>] 145 146 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after) 147 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 148 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60 149 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>] 150 /// CHECK-DAG: Return [<<UShr>>] 151 152 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after) 153 /// CHECK-NOT: And 154 155 public static long $noinline$UShr60And15(long arg) { 156 return (arg >>> 60) & 15; 157 } 158 159 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (before) 160 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 161 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28 162 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 163 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>] 164 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>] 165 /// CHECK-DAG: Return [<<And>>] 166 167 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (after) 168 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 169 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28 170 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 171 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>] 172 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>] 173 /// CHECK-DAG: Return [<<And>>] 174 175 public static int $noinline$UShr28And7(int arg) { 176 return (arg >>> 28) & 7; 177 } 178 179 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (before) 180 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 181 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60 182 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7 183 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>] 184 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>] 185 /// CHECK-DAG: Return [<<And>>] 186 187 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (after) 188 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 189 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60 190 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7 191 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>] 192 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>] 193 /// CHECK-DAG: Return [<<And>>] 194 195 public static long $noinline$UShr60And7(long arg) { 196 return (arg >>> 60) & 7; 197 } 198 199 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (before) 200 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 201 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24 202 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 203 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>] 204 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>] 205 /// CHECK-DAG: Return [<<And>>] 206 207 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after) 208 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 209 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24 210 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>] 211 /// CHECK-DAG: Return [<<UShr>>] 212 213 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after) 214 /// CHECK-NOT: Shr 215 /// CHECK-NOT: And 216 217 public static int $noinline$Shr24And255(int arg) { 218 return (arg >> 24) & 255; 219 } 220 221 /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (before) 222 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 223 /// CHECK-DAG: <<Const25:i\d+>> IntConstant 25 224 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127 225 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const25>>] 226 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>] 227 /// CHECK-DAG: Return [<<And>>] 228 229 /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (after) 230 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 231 /// CHECK-DAG: <<Const25:i\d+>> IntConstant 25 232 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const25>>] 233 /// CHECK-DAG: Return [<<UShr>>] 234 235 /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (after) 236 /// CHECK-NOT: Shr 237 /// CHECK-NOT: And 238 239 public static int $noinline$Shr25And127(int arg) { 240 return (arg >> 25) & 127; 241 } 242 243 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (before) 244 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 245 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56 246 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255 247 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>] 248 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>] 249 /// CHECK-DAG: Return [<<And>>] 250 251 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after) 252 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 253 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56 254 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>] 255 /// CHECK-DAG: Return [<<UShr>>] 256 257 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after) 258 /// CHECK-NOT: Shr 259 /// CHECK-NOT: And 260 261 public static long $noinline$Shr56And255(long arg) { 262 return (arg >> 56) & 255; 263 } 264 265 /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (before) 266 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 267 /// CHECK-DAG: <<Const57:i\d+>> IntConstant 57 268 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127 269 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const57>>] 270 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>] 271 /// CHECK-DAG: Return [<<And>>] 272 273 /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (after) 274 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 275 /// CHECK-DAG: <<Const57:i\d+>> IntConstant 57 276 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const57>>] 277 /// CHECK-DAG: Return [<<UShr>>] 278 279 /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (after) 280 /// CHECK-NOT: Shr 281 /// CHECK-NOT: And 282 283 public static long $noinline$Shr57And127(long arg) { 284 return (arg >> 57) & 127; 285 } 286 287 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (before) 288 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 289 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24 290 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127 291 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>] 292 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>] 293 /// CHECK-DAG: Return [<<And>>] 294 295 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (after) 296 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 297 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24 298 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127 299 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>] 300 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>] 301 /// CHECK-DAG: Return [<<And>>] 302 303 public static int $noinline$Shr24And127(int arg) { 304 return (arg >> 24) & 127; 305 } 306 307 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (before) 308 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 309 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56 310 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127 311 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>] 312 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>] 313 /// CHECK-DAG: Return [<<And>>] 314 315 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (after) 316 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 317 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56 318 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127 319 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>] 320 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>] 321 /// CHECK-DAG: Return [<<And>>] 322 323 public static long $noinline$Shr56And127(long arg) { 324 return (arg >> 56) & 127; 325 } 326 327 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (before) 328 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 329 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1 330 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>] 331 /// CHECK-DAG: Return [<<Div>>] 332 333 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after) 334 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 335 /// CHECK-DAG: Return [<<Arg>>] 336 337 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after) 338 /// CHECK-NOT: Div 339 340 public static long $noinline$Div1(long arg) { 341 return arg / 1; 342 } 343 344 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (before) 345 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 346 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1 347 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>] 348 /// CHECK-DAG: Return [<<Div>>] 349 350 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after) 351 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 352 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>] 353 /// CHECK-DAG: Return [<<Neg>>] 354 355 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after) 356 /// CHECK-NOT: Div 357 358 public static int $noinline$DivN1(int arg) { 359 return arg / -1; 360 } 361 362 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (before) 363 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 364 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1 365 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>] 366 /// CHECK-DAG: Return [<<Mul>>] 367 368 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after) 369 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 370 /// CHECK-DAG: Return [<<Arg>>] 371 372 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after) 373 /// CHECK-NOT: Mul 374 375 public static long $noinline$Mul1(long arg) { 376 return arg * 1; 377 } 378 379 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (before) 380 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 381 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1 382 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>] 383 /// CHECK-DAG: Return [<<Mul>>] 384 385 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after) 386 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 387 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>] 388 /// CHECK-DAG: Return [<<Neg>>] 389 390 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after) 391 /// CHECK-NOT: Mul 392 393 public static int $noinline$MulN1(int arg) { 394 return arg * -1; 395 } 396 397 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (before) 398 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 399 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128 400 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>] 401 /// CHECK-DAG: Return [<<Mul>>] 402 403 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after) 404 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 405 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 406 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>] 407 /// CHECK-DAG: Return [<<Shl>>] 408 409 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after) 410 /// CHECK-NOT: Mul 411 412 public static long $noinline$MulPowerOfTwo128(long arg) { 413 return arg * 128; 414 } 415 416 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (before) 417 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue 418 /// CHECK-DAG: <<Const10:j\d+>> LongConstant 10 419 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11 420 /// CHECK-DAG: <<Const12:j\d+>> LongConstant 12 421 /// CHECK-DAG: <<Mul1:j\d+>> Mul [<<Const10>>,<<ArgValue>>] 422 /// CHECK-DAG: <<Mul2:j\d+>> Mul [<<Mul1>>,<<Const11>>] 423 /// CHECK-DAG: <<Mul3:j\d+>> Mul [<<Mul2>>,<<Const12>>] 424 /// CHECK-DAG: Return [<<Mul3>>] 425 426 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (after) 427 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue 428 /// CHECK-DAG: <<Const1320:j\d+>> LongConstant 1320 429 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<ArgValue>>,<<Const1320>>] 430 /// CHECK-DAG: Return [<<Mul>>] 431 432 public static long $noinline$MulMulMulConst(long arg) { 433 return 10 * arg * 11 * 12; 434 } 435 436 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (before) 437 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 438 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 439 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>] 440 /// CHECK-DAG: Return [<<Or>>] 441 442 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after) 443 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 444 /// CHECK-DAG: Return [<<Arg>>] 445 446 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after) 447 /// CHECK-NOT: Or 448 449 public static int $noinline$Or0(int arg) { 450 return arg | 0; 451 } 452 453 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (before) 454 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 455 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>] 456 /// CHECK-DAG: Return [<<Or>>] 457 458 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after) 459 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 460 /// CHECK-DAG: Return [<<Arg>>] 461 462 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after) 463 /// CHECK-NOT: Or 464 465 public static long $noinline$OrSame(long arg) { 466 return arg | arg; 467 } 468 469 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (before) 470 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 471 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 472 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>] 473 /// CHECK-DAG: Return [<<Shl>>] 474 475 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after) 476 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 477 /// CHECK-DAG: Return [<<Arg>>] 478 479 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after) 480 /// CHECK-NOT: Shl 481 482 public static int $noinline$Shl0(int arg) { 483 return arg << 0; 484 } 485 486 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (before) 487 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 488 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 489 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>] 490 /// CHECK-DAG: Return [<<Shr>>] 491 492 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after) 493 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 494 /// CHECK-DAG: Return [<<Arg>>] 495 496 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after) 497 /// CHECK-NOT: Shr 498 499 public static long $noinline$Shr0(long arg) { 500 return arg >> 0; 501 } 502 503 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (before) 504 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 505 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64 506 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const64>>] 507 /// CHECK-DAG: Return [<<Shr>>] 508 509 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after) 510 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 511 /// CHECK-DAG: Return [<<Arg>>] 512 513 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after) 514 /// CHECK-NOT: Shr 515 516 public static long $noinline$Shr64(long arg) { 517 return arg >> 64; 518 } 519 520 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (before) 521 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 522 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 523 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>] 524 /// CHECK-DAG: Return [<<Sub>>] 525 526 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after) 527 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 528 /// CHECK-DAG: Return [<<Arg>>] 529 530 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after) 531 /// CHECK-NOT: Sub 532 533 public static long $noinline$Sub0(long arg) { 534 return arg - 0; 535 } 536 537 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (before) 538 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 539 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 540 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>] 541 /// CHECK-DAG: Return [<<Sub>>] 542 543 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after) 544 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 545 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>] 546 /// CHECK-DAG: Return [<<Neg>>] 547 548 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after) 549 /// CHECK-NOT: Sub 550 551 public static int $noinline$SubAliasNeg(int arg) { 552 return 0 - arg; 553 } 554 555 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (before) 556 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue 557 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 558 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6 559 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<ArgValue>>] 560 /// CHECK-DAG: <<Add:i\d+>> Add [<<Sub>>,<<Const6>>] 561 /// CHECK-DAG: Return [<<Add>>] 562 563 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (after) 564 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue 565 /// CHECK-DAG: <<Const11:i\d+>> IntConstant 11 566 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const11>>,<<ArgValue>>] 567 /// CHECK-DAG: Return [<<Sub>>] 568 569 public static int $noinline$SubAddConst1(int arg) { 570 return 5 - arg + 6; 571 } 572 573 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (before) 574 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue 575 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14 576 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 577 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const13>>] 578 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const14>>,<<Add>>] 579 /// CHECK-DAG: Return [<<Sub>>] 580 581 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (after) 582 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue 583 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 584 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const1>>,<<ArgValue>>] 585 /// CHECK-DAG: Return [<<Sub>>] 586 587 public static int $noinline$SubAddConst2(int arg) { 588 return 14 - (arg + 13); 589 } 590 591 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (before) 592 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue 593 /// CHECK-DAG: <<Const17:j\d+>> LongConstant 17 594 /// CHECK-DAG: <<Const18:j\d+>> LongConstant 18 595 /// CHECK-DAG: <<Sub1:j\d+>> Sub [<<Const18>>,<<ArgValue>>] 596 /// CHECK-DAG: <<Sub2:j\d+>> Sub [<<Const17>>,<<Sub1>>] 597 /// CHECK-DAG: Return [<<Sub2>>] 598 599 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (after) 600 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue 601 /// CHECK-DAG: <<ConstM1:j\d+>> LongConstant -1 602 /// CHECK-DAG: <<Add:j\d+>> Add [<<ArgValue>>,<<ConstM1>>] 603 /// CHECK-DAG: Return [<<Add>>] 604 605 public static long $noinline$SubSubConst(long arg) { 606 return 17 - (18 - arg); 607 } 608 609 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (before) 610 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 611 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 612 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>] 613 /// CHECK-DAG: Return [<<UShr>>] 614 615 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after) 616 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 617 /// CHECK-DAG: Return [<<Arg>>] 618 619 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after) 620 /// CHECK-NOT: UShr 621 622 public static long $noinline$UShr0(long arg) { 623 return arg >>> 0; 624 } 625 626 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (before) 627 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 628 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 629 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>] 630 /// CHECK-DAG: Return [<<Xor>>] 631 632 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after) 633 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 634 /// CHECK-DAG: Return [<<Arg>>] 635 636 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after) 637 /// CHECK-NOT: Xor 638 639 public static int $noinline$Xor0(int arg) { 640 return arg ^ 0; 641 } 642 643 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (before) 644 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 645 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 646 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>] 647 /// CHECK-DAG: Return [<<Xor>>] 648 649 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after) 650 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 651 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>] 652 /// CHECK-DAG: Return [<<Not>>] 653 654 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after) 655 /// CHECK-NOT: Xor 656 657 public static int $noinline$XorAllOnes(int arg) { 658 return arg ^ -1; 659 } 660 661 /** 662 * Test that addition or subtraction operation with both inputs negated are 663 * optimized to use a single negation after the operation. 664 * The transformation tested is implemented in 665 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`. 666 */ 667 668 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (before) 669 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 670 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 671 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>] 672 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>] 673 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>] 674 /// CHECK-DAG: Return [<<Add>>] 675 676 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (after) 677 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 678 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 679 /// CHECK-NOT: Neg 680 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>] 681 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>] 682 /// CHECK-DAG: Return [<<Neg>>] 683 684 public static int $noinline$AddNegs1(int arg1, int arg2) { 685 return -arg1 + -arg2; 686 } 687 688 /** 689 * This is similar to the test-case AddNegs1, but the negations have 690 * multiple uses. 691 * The transformation tested is implemented in 692 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`. 693 * The current code won't perform the previous optimization. The 694 * transformations do not look at other uses of their inputs. As they don't 695 * know what will happen with other uses, they do not take the risk of 696 * increasing the register pressure by creating or extending live ranges. 697 */ 698 699 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (before) 700 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 701 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 702 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>] 703 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>] 704 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>] 705 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>] 706 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>] 707 /// CHECK-DAG: Return [<<Or>>] 708 709 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (after) 710 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 711 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 712 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>] 713 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>] 714 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>] 715 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>] 716 /// CHECK-NOT: Neg 717 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>] 718 /// CHECK-DAG: Return [<<Or>>] 719 720 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) GVN (after) 721 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 722 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 723 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>] 724 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>] 725 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>] 726 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add>>,<<Add>>] 727 /// CHECK-DAG: Return [<<Or>>] 728 729 public static int $noinline$AddNegs2(int arg1, int arg2) { 730 int temp1 = -arg1; 731 int temp2 = -arg2; 732 return (temp1 + temp2) | (temp1 + temp2); 733 } 734 735 /** 736 * This follows test-cases AddNegs1 and AddNegs2. 737 * The transformation tested is implemented in 738 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`. 739 * The optimization should not happen if it moves an additional instruction in 740 * the loop. 741 */ 742 743 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (before) 744 // -------------- Arguments and initial negation operations. 745 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 746 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 747 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>] 748 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>] 749 /// CHECK: Goto 750 // -------------- Loop 751 /// CHECK: SuspendCheck 752 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>] 753 /// CHECK: Goto 754 755 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (after) 756 // -------------- Arguments and initial negation operations. 757 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 758 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 759 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>] 760 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>] 761 /// CHECK: Goto 762 // -------------- Loop 763 /// CHECK: SuspendCheck 764 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>] 765 /// CHECK-NOT: Neg 766 /// CHECK: Goto 767 768 public static long $noinline$AddNegs3(long arg1, long arg2) { 769 long res = 0; 770 long n_arg1 = -arg1; 771 long n_arg2 = -arg2; 772 for (long i = 0; i < 1; i++) { 773 res += n_arg1 + n_arg2 + i; 774 } 775 return res; 776 } 777 778 /** 779 * Test the simplification of an addition with a negated argument into a 780 * subtraction. 781 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`. 782 */ 783 784 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (before) 785 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 786 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 787 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>] 788 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>] 789 /// CHECK-DAG: Return [<<Add>>] 790 791 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after) 792 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 793 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 794 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>] 795 /// CHECK-DAG: Return [<<Sub>>] 796 797 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after) 798 /// CHECK-NOT: Neg 799 /// CHECK-NOT: Add 800 801 public static long $noinline$AddNeg1(long arg1, long arg2) { 802 return -arg1 + arg2; 803 } 804 805 /** 806 * This is similar to the test-case AddNeg1, but the negation has two uses. 807 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`. 808 * The current code won't perform the previous optimization. The 809 * transformations do not look at other uses of their inputs. As they don't 810 * know what will happen with other uses, they do not take the risk of 811 * increasing the register pressure by creating or extending live ranges. 812 */ 813 814 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (before) 815 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 816 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 817 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>] 818 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>] 819 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>] 820 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>] 821 /// CHECK-DAG: Return [<<Res>>] 822 823 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after) 824 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 825 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 826 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>] 827 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>] 828 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>] 829 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>] 830 /// CHECK-DAG: Return [<<Res>>] 831 832 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after) 833 /// CHECK-NOT: Sub 834 835 public static long $noinline$AddNeg2(long arg1, long arg2) { 836 long temp = -arg2; 837 return (arg1 + temp) | (arg1 + temp); 838 } 839 840 /** 841 * Test simplification of the `-(-var)` pattern. 842 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`. 843 */ 844 845 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (before) 846 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 847 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>] 848 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>] 849 /// CHECK-DAG: Return [<<Neg2>>] 850 851 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after) 852 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 853 /// CHECK-DAG: Return [<<Arg>>] 854 855 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after) 856 /// CHECK-NOT: Neg 857 858 public static long $noinline$NegNeg1(long arg) { 859 return -(-arg); 860 } 861 862 /** 863 * Test 'multi-step' simplification, where a first transformation yields a 864 * new simplification possibility for the current instruction. 865 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg` 866 * and in `InstructionSimplifierVisitor::VisitAdd`. 867 */ 868 869 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (before) 870 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 871 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>] 872 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>] 873 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>] 874 /// CHECK-DAG: Return [<<Add>>] 875 876 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after) 877 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 878 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>] 879 /// CHECK-DAG: Return [<<Sub>>] 880 881 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after) 882 /// CHECK-NOT: Neg 883 /// CHECK-NOT: Add 884 885 /// CHECK-START: int Main.$noinline$NegNeg2(int) constant_folding$after_inlining (after) 886 /// CHECK: <<Const0:i\d+>> IntConstant 0 887 /// CHECK-NOT: Neg 888 /// CHECK-NOT: Add 889 /// CHECK: Return [<<Const0>>] 890 891 public static int $noinline$NegNeg2(int arg) { 892 int temp = -arg; 893 return temp + -temp; 894 } 895 896 /** 897 * Test another 'multi-step' simplification, where a first transformation 898 * yields a new simplification possibility for the current instruction. 899 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg` 900 * and in `InstructionSimplifierVisitor::VisitSub`. 901 */ 902 903 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (before) 904 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 905 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 906 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>] 907 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>] 908 /// CHECK-DAG: Return [<<Sub>>] 909 910 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after) 911 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 912 /// CHECK-DAG: Return [<<Arg>>] 913 914 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after) 915 /// CHECK-NOT: Neg 916 /// CHECK-NOT: Sub 917 918 public static long $noinline$NegNeg3(long arg) { 919 return 0 - -arg; 920 } 921 922 /** 923 * Test that a negated subtraction is simplified to a subtraction with its 924 * arguments reversed. 925 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`. 926 */ 927 928 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (before) 929 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 930 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 931 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>] 932 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>] 933 /// CHECK-DAG: Return [<<Neg>>] 934 935 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after) 936 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 937 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 938 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>] 939 /// CHECK-DAG: Return [<<Sub>>] 940 941 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after) 942 /// CHECK-NOT: Neg 943 944 public static int $noinline$NegSub1(int arg1, int arg2) { 945 return -(arg1 - arg2); 946 } 947 948 /** 949 * This is similar to the test-case NegSub1, but the subtraction has 950 * multiple uses. 951 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`. 952 * The current code won't perform the previous optimization. The 953 * transformations do not look at other uses of their inputs. As they don't 954 * know what will happen with other uses, they do not take the risk of 955 * increasing the register pressure by creating or extending live ranges. 956 */ 957 958 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (before) 959 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 960 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 961 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>] 962 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>] 963 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>] 964 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>] 965 /// CHECK-DAG: Return [<<Or>>] 966 967 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (after) 968 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 969 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 970 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>] 971 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>] 972 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>] 973 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>] 974 /// CHECK-DAG: Return [<<Or>>] 975 976 public static int $noinline$NegSub2(int arg1, int arg2) { 977 int temp = arg1 - arg2; 978 return -temp | -temp; 979 } 980 981 /** 982 * Test simplification of the `~~var` pattern. 983 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`. 984 */ 985 986 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (before) 987 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 988 /// CHECK-DAG: <<ConstNeg1:j\d+>> LongConstant -1 989 /// CHECK-DAG: <<Not1:j\d+>> Xor [<<Arg>>,<<ConstNeg1>>] 990 /// CHECK-DAG: <<Not2:j\d+>> Xor [<<Not1>>,<<ConstNeg1>>] 991 /// CHECK-DAG: Return [<<Not2>>] 992 993 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after) 994 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 995 /// CHECK-DAG: Return [<<Arg>>] 996 997 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after) 998 /// CHECK-NOT: Xor 999 1000 public static long $noinline$NotNot1(long arg) { 1001 return ~~arg; 1002 } 1003 1004 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (before) 1005 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1006 /// CHECK-DAG: <<ConstNeg1:i\d+>> IntConstant -1 1007 /// CHECK-DAG: <<Not1:i\d+>> Xor [<<Arg>>,<<ConstNeg1>>] 1008 /// CHECK-DAG: <<Not2:i\d+>> Xor [<<Not1>>,<<ConstNeg1>>] 1009 /// CHECK-DAG: <<Add:i\d+>> Add [<<Not2>>,<<Not1>>] 1010 /// CHECK-DAG: Return [<<Add>>] 1011 1012 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after) 1013 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1014 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>] 1015 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>] 1016 /// CHECK-DAG: Return [<<Add>>] 1017 1018 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after) 1019 /// CHECK: Not 1020 /// CHECK-NOT: Not 1021 1022 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after) 1023 /// CHECK-NOT: Xor 1024 1025 public static int $noinline$NotNot2(int arg) { 1026 int temp = ~arg; 1027 return temp + ~temp; 1028 } 1029 1030 /** 1031 * Test the simplification of a subtraction with a negated argument. 1032 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`. 1033 */ 1034 1035 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (before) 1036 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 1037 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 1038 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>] 1039 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>] 1040 /// CHECK-DAG: Return [<<Sub>>] 1041 1042 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after) 1043 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 1044 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 1045 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>] 1046 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>] 1047 /// CHECK-DAG: Return [<<Neg>>] 1048 1049 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after) 1050 /// CHECK-NOT: Sub 1051 1052 public static int $noinline$SubNeg1(int arg1, int arg2) { 1053 return -arg1 - arg2; 1054 } 1055 1056 /** 1057 * This is similar to the test-case SubNeg1, but the negation has 1058 * multiple uses. 1059 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`. 1060 * The current code won't perform the previous optimization. The 1061 * transformations do not look at other uses of their inputs. As they don't 1062 * know what will happen with other uses, they do not take the risk of 1063 * increasing the register pressure by creating or extending live ranges. 1064 */ 1065 1066 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before) 1067 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 1068 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 1069 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>] 1070 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>] 1071 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>] 1072 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>] 1073 /// CHECK-DAG: Return [<<Or>>] 1074 1075 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after) 1076 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue 1077 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue 1078 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>] 1079 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>] 1080 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>] 1081 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>] 1082 /// CHECK-DAG: Return [<<Or>>] 1083 1084 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after) 1085 /// CHECK-NOT: Add 1086 1087 public static int $noinline$SubNeg2(int arg1, int arg2) { 1088 int temp = -arg1; 1089 return (temp - arg2) | (temp - arg2); 1090 } 1091 1092 /** 1093 * This follows test-cases SubNeg1 and SubNeg2. 1094 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`. 1095 * The optimization should not happen if it moves an additional instruction in 1096 * the loop. 1097 */ 1098 1099 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before) 1100 // -------------- Arguments and initial negation operation. 1101 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 1102 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 1103 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>] 1104 /// CHECK: Goto 1105 // -------------- Loop 1106 /// CHECK: SuspendCheck 1107 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>] 1108 /// CHECK: Goto 1109 1110 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after) 1111 // -------------- Arguments and initial negation operation. 1112 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue 1113 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue 1114 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>] 1115 /// CHECK-DAG: Goto 1116 // -------------- Loop 1117 /// CHECK: SuspendCheck 1118 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>] 1119 /// CHECK-NOT: Neg 1120 /// CHECK: Goto 1121 1122 public static long $noinline$SubNeg3(long arg1, long arg2) { 1123 long res = 0; 1124 long temp = -arg1; 1125 for (long i = 0; i < 1; i++) { 1126 res += temp - arg2 - i; 1127 } 1128 return res; 1129 } 1130 1131 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before) 1132 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1133 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1134 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1135 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 1136 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>] 1137 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>] 1138 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>] 1139 /// CHECK-DAG: Return [<<NotCond>>] 1140 1141 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after) 1142 /// CHECK-DAG: <<True:i\d+>> IntConstant 1 1143 /// CHECK-DAG: Return [<<True>>] 1144 1145 public static boolean $noinline$EqualBoolVsIntConst(boolean arg) { 1146 // Make calls that will be inlined to make sure the instruction simplifier 1147 // sees the simplification (dead code elimination will also try to simplify it). 1148 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) != 2; 1149 } 1150 1151 public static int $inline$ReturnArg(int arg) { 1152 return arg; 1153 } 1154 1155 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before) 1156 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1157 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1158 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1159 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 1160 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>] 1161 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>] 1162 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>] 1163 /// CHECK-DAG: Return [<<NotCond>>] 1164 1165 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after) 1166 /// CHECK-DAG: <<False:i\d+>> IntConstant 0 1167 /// CHECK-DAG: Return [<<False>>] 1168 1169 public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) { 1170 // Make calls that will be inlined to make sure the instruction simplifier 1171 // sees the simplification (dead code elimination will also try to simplify it). 1172 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) == 2; 1173 } 1174 1175 /* 1176 * Test simplification of double Boolean negation. Note that sometimes 1177 * both negations can be removed but we only expect the simplifier to 1178 * remove the second. 1179 */ 1180 1181 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (before) 1182 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1183 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 0 1184 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue 1185 /// CHECK-DAG: <<NotResult:z\d+>> NotEqual [<<Result>>,<<Const1>>] 1186 /// CHECK-DAG: If [<<NotResult>>] 1187 1188 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after) 1189 /// CHECK-NOT: NotEqual 1190 1191 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after) 1192 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1193 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue 1194 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1195 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1196 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>] 1197 /// CHECK-DAG: Return [<<Phi>>] 1198 1199 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before) 1200 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1201 /// CHECK-NOT: BooleanNot [<<Arg>>] 1202 /// CHECK-NOT: Phi 1203 1204 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before) 1205 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1206 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1207 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1208 /// CHECK-DAG: <<Sel:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>] 1209 /// CHECK-DAG: <<Sel2:i\d+>> Select [<<Const1>>,<<Const0>>,<<Sel>>] 1210 /// CHECK-DAG: Return [<<Sel2>>] 1211 1212 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after) 1213 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1214 /// CHECK: BooleanNot [<<Arg>>] 1215 /// CHECK-NEXT: Goto 1216 1217 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after) 1218 /// CHECK-NOT: Select 1219 1220 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) dead_code_elimination$final (after) 1221 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 1222 /// CHECK-NOT: BooleanNot [<<Arg>>] 1223 /// CHECK-DAG: Return [<<Arg>>] 1224 1225 public static boolean NegateValue(boolean arg) { 1226 return !arg; 1227 } 1228 1229 public static boolean $noinline$NotNotBool(boolean arg) { 1230 return !(NegateValue(arg)); 1231 } 1232 1233 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before) 1234 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1235 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2 1236 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>] 1237 /// CHECK-DAG: Return [<<Div>>] 1238 1239 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after) 1240 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1241 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5 1242 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>] 1243 /// CHECK-DAG: Return [<<Mul>>] 1244 1245 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after) 1246 /// CHECK-NOT: Div 1247 1248 public static float $noinline$Div2(float arg) { 1249 return arg / 2.0f; 1250 } 1251 1252 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before) 1253 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue 1254 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2 1255 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>] 1256 /// CHECK-DAG: Return [<<Div>>] 1257 1258 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after) 1259 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue 1260 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5 1261 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>] 1262 /// CHECK-DAG: Return [<<Mul>>] 1263 1264 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after) 1265 /// CHECK-NOT: Div 1266 public static double $noinline$Div2(double arg) { 1267 return arg / 2.0; 1268 } 1269 1270 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before) 1271 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1272 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25 1273 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>] 1274 /// CHECK-DAG: Return [<<Div>>] 1275 1276 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after) 1277 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1278 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4 1279 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>] 1280 /// CHECK-DAG: Return [<<Mul>>] 1281 1282 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after) 1283 /// CHECK-NOT: Div 1284 1285 public static float $noinline$DivMP25(float arg) { 1286 return arg / -0.25f; 1287 } 1288 1289 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before) 1290 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue 1291 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25 1292 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>] 1293 /// CHECK-DAG: Return [<<Div>>] 1294 1295 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after) 1296 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue 1297 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4 1298 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>] 1299 /// CHECK-DAG: Return [<<Mul>>] 1300 1301 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after) 1302 /// CHECK-NOT: Div 1303 public static double $noinline$DivMP25(double arg) { 1304 return arg / -0.25f; 1305 } 1306 1307 /** 1308 * Test strength reduction of factors of the form (2^n + 1). 1309 */ 1310 1311 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before) 1312 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1313 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9 1314 /// CHECK: Mul [<<Arg>>,<<Const9>>] 1315 1316 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after) 1317 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1318 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 1319 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>] 1320 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>] 1321 1322 public static int $noinline$mulPow2Plus1(int arg) { 1323 return arg * 9; 1324 } 1325 1326 /** 1327 * Test strength reduction of factors of the form (2^n - 1). 1328 */ 1329 1330 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before) 1331 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1332 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31 1333 /// CHECK: Mul [<<Const31>>,<<Arg>>] 1334 1335 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after) 1336 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1337 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 1338 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>] 1339 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>] 1340 1341 public static long $noinline$mulPow2Minus1(long arg) { 1342 return arg * 31; 1343 } 1344 1345 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (before) 1346 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1347 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1348 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1349 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet 1350 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>] 1351 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>] 1352 /// CHECK-DAG: Return [<<Select>>] 1353 1354 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (after) 1355 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet 1356 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1357 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1358 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>] 1359 /// CHECK-DAG: Return [<<Select>>] 1360 1361 public static int $noinline$booleanFieldNotEqualOne() { 1362 return (booleanField == $inline$true()) ? 13 : 54; 1363 } 1364 1365 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (before) 1366 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1367 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1368 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1369 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet 1370 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>] 1371 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>] 1372 /// CHECK-DAG: Return [<<Select>>] 1373 1374 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (after) 1375 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet 1376 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1377 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1378 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>] 1379 /// CHECK-DAG: Return [<<Select>>] 1380 1381 public static int $noinline$booleanFieldEqualZero() { 1382 return (booleanField != $inline$false()) ? 13 : 54; 1383 } 1384 1385 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (before) 1386 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1387 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1388 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1389 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1390 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 1391 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1392 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>] 1393 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>] 1394 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>] 1395 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>] 1396 /// CHECK-DAG: Return [<<Result>>] 1397 1398 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (after) 1399 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1400 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1401 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 1402 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1403 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>] 1404 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>] 1405 /// CHECK-DAG: Return [<<Result>>] 1406 // Note that we match `LE` from Select because there are two identical 1407 // LessThanOrEqual instructions. 1408 1409 public static int $noinline$intConditionNotEqualOne(int i) { 1410 return ((i > 42) == $inline$true()) ? 13 : 54; 1411 } 1412 1413 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (before) 1414 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1415 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1416 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1417 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1418 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 1419 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1420 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>] 1421 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>] 1422 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>] 1423 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>] 1424 /// CHECK-DAG: Return [<<Result>>] 1425 1426 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (after) 1427 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1428 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1429 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 1430 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1431 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>] 1432 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>] 1433 /// CHECK-DAG: Return [<<Result>>] 1434 // Note that we match `LE` from Select because there are two identical 1435 // LessThanOrEqual instructions. 1436 1437 public static int $noinline$intConditionEqualZero(int i) { 1438 return ((i > 42) != $inline$false()) ? 13 : 54; 1439 } 1440 1441 // Test that conditions on float/double are not flipped. 1442 1443 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after) 1444 /// CHECK: LessThanOrEqual 1445 1446 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after) 1447 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1448 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1449 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1450 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42 1451 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>] 1452 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>] 1453 /// CHECK-DAG: Return [<<Select>>] 1454 1455 public static int $noinline$floatConditionNotEqualOne(float f) { 1456 return ((f > 42.0f) == true) ? 13 : 54; 1457 } 1458 1459 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after) 1460 /// CHECK: LessThanOrEqual 1461 1462 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after) 1463 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue 1464 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13 1465 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54 1466 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42 1467 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>] 1468 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>] 1469 /// CHECK-DAG: Return [<<Select>>] 1470 1471 public static int $noinline$doubleConditionEqualZero(double d) { 1472 return ((d > 42.0) != false) ? 13 : 54; 1473 } 1474 1475 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before) 1476 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1477 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1478 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>] 1479 /// CHECK-DAG: Return [<<Int>>] 1480 1481 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after) 1482 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1483 /// CHECK-DAG: Return [<<Arg>>] 1484 1485 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after) 1486 /// CHECK-NOT: TypeConversion 1487 1488 public static int $noinline$intToDoubleToInt(int value) { 1489 // Lossless conversion followed by a conversion back. 1490 return (int) (double) value; 1491 } 1492 1493 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before) 1494 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1495 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1496 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>] 1497 1498 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after) 1499 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1500 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>] 1501 1502 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after) 1503 /// CHECK-DAG: TypeConversion 1504 /// CHECK-NOT: TypeConversion 1505 1506 public static String $noinline$intToDoubleToIntPrint(int value) { 1507 // Lossless conversion followed by a conversion back 1508 // with another use of the intermediate result. 1509 double d = (double) value; 1510 int i = (int) d; 1511 return "d=" + d + ", i=" + i; 1512 } 1513 1514 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before) 1515 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 1516 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1517 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>] 1518 /// CHECK-DAG: Return [<<Int>>] 1519 1520 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after) 1521 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 1522 /// CHECK-DAG: Return [<<Arg>>] 1523 1524 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after) 1525 /// CHECK-NOT: TypeConversion 1526 1527 public static int $noinline$byteToDoubleToInt(byte value) { 1528 // Lossless conversion followed by another conversion, use implicit conversion. 1529 return (int) (double) value; 1530 } 1531 1532 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before) 1533 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1534 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1535 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>] 1536 /// CHECK-DAG: Return [<<Int>>] 1537 1538 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after) 1539 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1540 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>] 1541 /// CHECK-DAG: Return [<<Int>>] 1542 1543 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after) 1544 /// CHECK-DAG: TypeConversion 1545 /// CHECK-NOT: TypeConversion 1546 1547 public static int $noinline$floatToDoubleToInt(float value) { 1548 // Lossless conversion followed by another conversion. 1549 return (int) (double) value; 1550 } 1551 1552 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before) 1553 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1554 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1555 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>] 1556 1557 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after) 1558 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1559 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1560 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>] 1561 1562 public static String $noinline$floatToDoubleToIntPrint(float value) { 1563 // Lossless conversion followed by another conversion with 1564 // an extra use of the intermediate result. 1565 double d = (double) value; 1566 int i = (int) d; 1567 return "d=" + d + ", i=" + i; 1568 } 1569 1570 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before) 1571 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 1572 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1573 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>] 1574 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>] 1575 /// CHECK-DAG: Return [<<Short>>] 1576 1577 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after) 1578 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 1579 /// CHECK-DAG: Return [<<Arg>>] 1580 1581 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after) 1582 /// CHECK-NOT: TypeConversion 1583 1584 public static short $noinline$byteToDoubleToShort(byte value) { 1585 // Originally, this is byte->double->int->short. The first conversion is lossless, 1586 // so we merge this with the second one to byte->int which we omit as it's an implicit 1587 // conversion. Then we eliminate the resulting byte->short as an implicit conversion. 1588 return (short) (double) value; 1589 } 1590 1591 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before) 1592 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue 1593 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1594 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>] 1595 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>] 1596 /// CHECK-DAG: Return [<<Short>>] 1597 1598 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after) 1599 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue 1600 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>] 1601 /// CHECK-DAG: Return [<<Short>>] 1602 1603 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after) 1604 /// CHECK-DAG: TypeConversion 1605 /// CHECK-NOT: TypeConversion 1606 1607 public static short $noinline$charToDoubleToShort(char value) { 1608 // Originally, this is char->double->int->short. The first conversion is lossless, 1609 // so we merge this with the second one to char->int which we omit as it's an implicit 1610 // conversion. Then we are left with the resulting char->short conversion. 1611 return (short) (double) value; 1612 } 1613 1614 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before) 1615 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1616 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>] 1617 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>] 1618 /// CHECK-DAG: Return [<<Short>>] 1619 1620 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after) 1621 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1622 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>] 1623 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>] 1624 /// CHECK-DAG: Return [<<Short>>] 1625 1626 public static short $noinline$floatToIntToShort(float value) { 1627 // Lossy FP to integral conversion followed by another conversion: no simplification. 1628 return (short) value; 1629 } 1630 1631 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before) 1632 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1633 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>] 1634 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>] 1635 /// CHECK-DAG: Return [<<Int>>] 1636 1637 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after) 1638 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1639 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>] 1640 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>] 1641 /// CHECK-DAG: Return [<<Int>>] 1642 1643 public static int $noinline$intToFloatToInt(int value) { 1644 // Lossy integral to FP conversion followed another conversion: no simplification. 1645 return (int) (float) value; 1646 } 1647 1648 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before) 1649 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1650 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>] 1651 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>] 1652 /// CHECK-DAG: Return [<<Double>>] 1653 1654 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after) 1655 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1656 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>] 1657 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>] 1658 /// CHECK-DAG: Return [<<Double>>] 1659 1660 public static double $noinline$longToIntToDouble(long value) { 1661 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification. 1662 return (double) (int) value; 1663 } 1664 1665 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before) 1666 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1667 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>] 1668 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>] 1669 /// CHECK-DAG: Return [<<Long>>] 1670 1671 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after) 1672 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1673 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>] 1674 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>] 1675 /// CHECK-DAG: Return [<<Long>>] 1676 1677 public static long $noinline$longToIntToLong(long value) { 1678 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification. 1679 return (long) (int) value; 1680 } 1681 1682 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before) 1683 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1684 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>] 1685 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>] 1686 /// CHECK-DAG: Return [<<Short>>] 1687 1688 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after) 1689 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1690 /// CHECK-DAG: Return [<<Arg>>] 1691 1692 public static short $noinline$shortToCharToShort(short value) { 1693 // Integral conversion followed by non-widening integral conversion to original type. 1694 return (short) (char) value; 1695 } 1696 1697 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before) 1698 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1699 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>] 1700 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>] 1701 /// CHECK-DAG: Return [<<Int>>] 1702 1703 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after) 1704 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1705 /// CHECK-DAG: Return [<<Arg>>] 1706 1707 public static int $noinline$shortToLongToInt(short value) { 1708 // Integral conversion followed by non-widening integral conversion, use implicit conversion. 1709 return (int) (long) value; 1710 } 1711 1712 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before) 1713 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1714 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>] 1715 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>] 1716 /// CHECK-DAG: Return [<<Byte>>] 1717 1718 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after) 1719 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1720 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>] 1721 /// CHECK-DAG: Return [<<Byte>>] 1722 1723 public static byte $noinline$shortToCharToByte(short value) { 1724 // Integral conversion followed by non-widening integral conversion losing bits 1725 // from the original type. Simplify to use only one conversion. 1726 return (byte) (char) value; 1727 } 1728 1729 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before) 1730 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1731 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>] 1732 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>] 1733 1734 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after) 1735 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1736 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>] 1737 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>] 1738 1739 public static String $noinline$shortToCharToBytePrint(short value) { 1740 // Integral conversion followed by non-widening integral conversion losing bits 1741 // from the original type with an extra use of the intermediate result. 1742 char c = (char) value; 1743 byte b = (byte) c; 1744 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions. 1745 } 1746 1747 /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (before) 1748 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1749 /// CHECK-DAG: <<Mask:j\d+>> LongConstant -12345678 1750 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>] 1751 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>] 1752 /// CHECK-DAG: Return [<<And>>] 1753 1754 /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (after) 1755 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1756 /// CHECK-DAG: <<Mask:i\d+>> IntConstant -12345678 1757 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Mask>>] 1758 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<And>>] 1759 /// CHECK-DAG: Return [<<Long>>] 1760 1761 public static long $noinline$intAndSmallLongConstant(int value) { 1762 return value & -12345678L; // Shall be simplified (constant is 32-bit). 1763 } 1764 1765 /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (before) 1766 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1767 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 9876543210 1768 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>] 1769 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>] 1770 /// CHECK-DAG: Return [<<And>>] 1771 1772 /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (after) 1773 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1774 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 9876543210 1775 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>] 1776 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>] 1777 /// CHECK-DAG: Return [<<And>>] 1778 1779 public static long $noinline$intAndLargeLongConstant(int value) { 1780 return value & 9876543210L; // Shall not be simplified (constant is not 32-bit). 1781 } 1782 1783 /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (before) 1784 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1785 /// CHECK-DAG: <<Shift:i\d+>> IntConstant 28 1786 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 15 1787 /// CHECK-DAG: <<Shifted:i\d+>> Shr [<<Arg>>,<<Shift>>] 1788 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Shifted>>] 1789 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>] 1790 /// CHECK-DAG: Return [<<And>>] 1791 1792 /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (after) 1793 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1794 /// CHECK-DAG: <<Shift:i\d+>> IntConstant 28 1795 /// CHECK-DAG: <<Shifted:i\d+>> UShr [<<Arg>>,<<Shift>>] 1796 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Shifted>>] 1797 /// CHECK-DAG: Return [<<Long>>] 1798 1799 public static long $noinline$intShr28And15L(int value) { 1800 return (value >> 28) & 15L; 1801 } 1802 1803 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before) 1804 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1805 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255 1806 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>] 1807 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>] 1808 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>] 1809 /// CHECK-DAG: Return [<<Byte>>] 1810 1811 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after) 1812 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1813 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>] 1814 /// CHECK-DAG: Return [<<Byte>>] 1815 1816 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after) 1817 /// CHECK-NOT: And 1818 1819 public static byte $noinline$longAnd0xffToByte(long value) { 1820 return (byte) (value & 0xff); 1821 } 1822 1823 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before) 1824 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1825 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071 1826 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>] 1827 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>] 1828 /// CHECK-DAG: Return [<<Char>>] 1829 1830 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after) 1831 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1832 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>] 1833 /// CHECK-DAG: Return [<<Char>>] 1834 1835 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after) 1836 /// CHECK-NOT: And 1837 1838 public static char $noinline$intAnd0x1ffffToChar(int value) { 1839 // Keeping all significant bits and one more. 1840 return (char) (value & 0x1ffff); 1841 } 1842 1843 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before) 1844 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1845 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303 1846 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>] 1847 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>] 1848 /// CHECK-DAG: Return [<<Short>>] 1849 1850 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after) 1851 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1852 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303 1853 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>] 1854 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>] 1855 /// CHECK-DAG: Return [<<Short>>] 1856 1857 public static short $noinline$intAnd0x17fffToShort(int value) { 1858 // No simplification: clearing a significant bit. 1859 return (short) (value & 0x17fff); 1860 } 1861 1862 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before) 1863 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1864 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 65535 1865 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>] 1866 /// CHECK-DAG: <<Same:s\d+>> TypeConversion [<<And>>] 1867 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Same>>] 1868 /// CHECK-DAG: Return [<<Double>>] 1869 1870 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after) 1871 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 1872 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>] 1873 /// CHECK-DAG: Return [<<Double>>] 1874 1875 public static double $noinline$shortAnd0xffffToShortToDouble(short value) { 1876 short same = (short) (value & 0xffff); 1877 return (double) same; 1878 } 1879 1880 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before) 1881 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1882 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 1883 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Const42>>,<<Arg>>] 1884 1885 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after) 1886 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1887 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 1888 /// CHECK-DAG: <<GE:z\d+>> GreaterThanOrEqual [<<Arg>>,<<Const42>>] 1889 1890 public static int $noinline$intReverseCondition(int i) { 1891 return (42 > i) ? 13 : 54; 1892 } 1893 1894 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before) 1895 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42 1896 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect 1897 /// CHECK-DAG: <<CMP:i\d+>> Compare [<<Const42>>,<<Result>>] 1898 1899 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after) 1900 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42 1901 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect 1902 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Result>>,<<Const42>>] 1903 1904 public static int $noinline$intReverseConditionNaN(int i) { 1905 return (42 != Math.sqrt(i)) ? 13 : 54; 1906 } 1907 1908 public static int $noinline$runSmaliTest(String name, boolean input) { 1909 try { 1910 Class<?> c = Class.forName("SmaliTests"); 1911 Method m = c.getMethod(name, boolean.class); 1912 return (Integer) m.invoke(null, input); 1913 } catch (Exception ex) { 1914 throw new Error(ex); 1915 } 1916 } 1917 1918 public static boolean $noinline$runSmaliTestBoolean(String name, boolean input) { 1919 try { 1920 Class<?> c = Class.forName("SmaliTests"); 1921 Method m = c.getMethod(name, boolean.class); 1922 return (Boolean) m.invoke(null, input); 1923 } catch (Exception ex) { 1924 throw new Error(ex); 1925 } 1926 } 1927 1928 public static int $noinline$runSmaliTestInt(String name, int arg) { 1929 try { 1930 Class<?> c = Class.forName("SmaliTests"); 1931 Method m = c.getMethod(name, int.class); 1932 return (Integer) m.invoke(null, arg); 1933 } catch (Exception ex) { 1934 throw new Error(ex); 1935 } 1936 } 1937 1938 public static long $noinline$runSmaliTestLong(String name, long arg) { 1939 try { 1940 Class<?> c = Class.forName("SmaliTests"); 1941 Method m = c.getMethod(name, long.class); 1942 return (Long) m.invoke(null, arg); 1943 } catch (Exception ex) { 1944 throw new Error(ex); 1945 } 1946 } 1947 1948 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before) 1949 /// CHECK: <<Value:i\d+>> ParameterValue 1950 /// CHECK: <<Shift:i\d+>> ParameterValue 1951 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31 1952 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>] 1953 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<And>>] 1954 /// CHECK-DAG: Return [<<Shl>>] 1955 1956 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after) 1957 /// CHECK: <<Value:i\d+>> ParameterValue 1958 /// CHECK: <<Shift:i\d+>> ParameterValue 1959 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<Shift>>] 1960 /// CHECK-DAG: Return [<<Shl>>] 1961 1962 public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) { 1963 return value << (shift & 31); 1964 } 1965 1966 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before) 1967 /// CHECK: <<Value:j\d+>> ParameterValue 1968 /// CHECK: <<Shift:i\d+>> ParameterValue 1969 /// CHECK-DAG: <<Const63:i\d+>> IntConstant 63 1970 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const63>>] 1971 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<And>>] 1972 /// CHECK-DAG: Return [<<Shr>>] 1973 1974 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after) 1975 /// CHECK: <<Value:j\d+>> ParameterValue 1976 /// CHECK: <<Shift:i\d+>> ParameterValue 1977 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<Shift>>] 1978 /// CHECK-DAG: Return [<<Shr>>] 1979 1980 public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) { 1981 return value >> (shift & 63); 1982 } 1983 1984 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before) 1985 /// CHECK: <<Value:i\d+>> ParameterValue 1986 /// CHECK: <<Shift:i\d+>> ParameterValue 1987 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 1988 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const255>>] 1989 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<And>>] 1990 /// CHECK-DAG: Return [<<UShr>>] 1991 1992 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after) 1993 /// CHECK: <<Value:i\d+>> ParameterValue 1994 /// CHECK: <<Shift:i\d+>> ParameterValue 1995 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<Shift>>] 1996 /// CHECK-DAG: Return [<<UShr>>] 1997 1998 public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) { 1999 return value >>> (shift & 0xff); 2000 } 2001 2002 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before) 2003 /// CHECK: <<Value:j\d+>> ParameterValue 2004 /// CHECK: <<Shift:i\d+>> ParameterValue 2005 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 2006 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>] 2007 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>] 2008 /// CHECK-DAG: Return [<<Shl>>] 2009 2010 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after) 2011 /// CHECK: <<Value:j\d+>> ParameterValue 2012 /// CHECK: <<Shift:i\d+>> ParameterValue 2013 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 2014 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>] 2015 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>] 2016 /// CHECK-DAG: Return [<<Shl>>] 2017 2018 public static long $noinline$longSmallerShiftMasking(long value, int shift) { 2019 return value << (shift & 3); 2020 } 2021 2022 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before) 2023 /// CHECK: <<Value:i\d+>> ParameterValue 2024 /// CHECK: <<Shift:i\d+>> ParameterValue 2025 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31 2026 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>] 2027 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<And>>] 2028 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>] 2029 /// CHECK-DAG: Return [<<Add>>] 2030 2031 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after) 2032 /// CHECK: <<Value:i\d+>> ParameterValue 2033 /// CHECK: <<Shift:i\d+>> ParameterValue 2034 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31 2035 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>] 2036 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<Shift>>] 2037 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>] 2038 /// CHECK-DAG: Return [<<Add>>] 2039 2040 public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) { 2041 int temp = shift & 31; 2042 return (value >> temp) + temp; 2043 } 2044 2045 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (before) 2046 /// CHECK: <<Value:i\d+>> ParameterValue 2047 /// CHECK: <<Shift:i\d+>> ParameterValue 2048 /// CHECK-DAG: <<Const32:i\d+>> IntConstant 32 2049 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64 2050 /// CHECK-DAG: <<Const96:i\d+>> IntConstant 96 2051 /// CHECK-DAG: <<Const128:i\d+>> IntConstant 128 2052 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const32>>] 2053 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const64>>] 2054 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const96>>] 2055 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const128>>] 2056 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<Shift>>] 2057 /// CHECK-DAG: Shl [<<Value>>,<<Or>>] 2058 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>] 2059 /// CHECK-DAG: UShr [<<Value>>,<<Add>>] 2060 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>] 2061 /// CHECK-DAG: Shr [<<Value>>,<<Conv>>] 2062 2063 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (after) 2064 /// CHECK: <<Value:i\d+>> ParameterValue 2065 /// CHECK: <<Shift:i\d+>> ParameterValue 2066 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>] 2067 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>] 2068 /// CHECK-DAG: UShr [<<Value>>,<<Shift>>] 2069 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>] 2070 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>] 2071 2072 public static int $noinline$intUnnecessaryShiftModifications(int value, int shift) { 2073 int c128 = 128; 2074 return (value << (shift | 32)) + 2075 (value >> (shift ^ 64)) + 2076 (value >>> (shift + 96)) + 2077 (value << (shift - c128)) + // Needs a named constant to generate Sub. 2078 (value >> ((byte) shift)); 2079 } 2080 2081 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (before) 2082 /// CHECK: <<Value:i\d+>> ParameterValue 2083 /// CHECK: <<Shift:i\d+>> ParameterValue 2084 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 2085 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65 2086 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97 2087 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129 2088 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>] 2089 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>] 2090 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>] 2091 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>] 2092 /// CHECK-DAG: Shl [<<Value>>,<<Or>>] 2093 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>] 2094 /// CHECK-DAG: UShr [<<Value>>,<<Add>>] 2095 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>] 2096 2097 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (after) 2098 /// CHECK: <<Value:i\d+>> ParameterValue 2099 /// CHECK: <<Shift:i\d+>> ParameterValue 2100 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 2101 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65 2102 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97 2103 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129 2104 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>] 2105 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>] 2106 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>] 2107 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>] 2108 /// CHECK-DAG: Shl [<<Value>>,<<Or>>] 2109 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>] 2110 /// CHECK-DAG: UShr [<<Value>>,<<Add>>] 2111 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>] 2112 2113 public static int $noinline$intNecessaryShiftModifications(int value, int shift) { 2114 int c129 = 129; 2115 return (value << (shift | 33)) + 2116 (value >> (shift ^ 65)) + 2117 (value >>> (shift + 97)) + 2118 (value << (shift - c129)); // Needs a named constant to generate Sub. 2119 } 2120 2121 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before) 2122 /// CHECK: <<X:i\d+>> ParameterValue 2123 /// CHECK: <<Y:i\d+>> ParameterValue 2124 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>] 2125 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<X>>] 2126 /// CHECK-DAG: Return [<<Res>>] 2127 2128 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after) 2129 /// CHECK: <<X:i\d+>> ParameterValue 2130 /// CHECK: <<Y:i\d+>> ParameterValue 2131 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>] 2132 /// CHECK-DAG: Return [<<Y>>] 2133 2134 public static int $noinline$intAddSubSimplifyArg1(int x, int y) { 2135 int sum = x + y; 2136 return sum - x; 2137 } 2138 2139 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before) 2140 /// CHECK: <<X:i\d+>> ParameterValue 2141 /// CHECK: <<Y:i\d+>> ParameterValue 2142 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>] 2143 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<Y>>] 2144 /// CHECK-DAG: Return [<<Res>>] 2145 2146 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after) 2147 /// CHECK: <<X:i\d+>> ParameterValue 2148 /// CHECK: <<Y:i\d+>> ParameterValue 2149 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>] 2150 /// CHECK-DAG: Return [<<X>>] 2151 2152 public static int $noinline$intAddSubSimplifyArg2(int x, int y) { 2153 int sum = x + y; 2154 return sum - y; 2155 } 2156 2157 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (before) 2158 /// CHECK: <<X:i\d+>> ParameterValue 2159 /// CHECK: <<Y:i\d+>> ParameterValue 2160 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>] 2161 /// CHECK-DAG: <<Res:i\d+>> Add [<<Sub>>,<<Y>>] 2162 /// CHECK-DAG: Return [<<Res>>] 2163 2164 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (after) 2165 /// CHECK: <<X:i\d+>> ParameterValue 2166 /// CHECK: <<Y:i\d+>> ParameterValue 2167 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>] 2168 /// CHECK-DAG: Return [<<X>>] 2169 2170 public static int $noinline$intSubAddSimplifyLeft(int x, int y) { 2171 int sub = x - y; 2172 return sub + y; 2173 } 2174 2175 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before) 2176 /// CHECK: <<X:i\d+>> ParameterValue 2177 /// CHECK: <<Y:i\d+>> ParameterValue 2178 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>] 2179 /// CHECK-DAG: <<Res:i\d+>> Add [<<Y>>,<<Sub>>] 2180 /// CHECK-DAG: Return [<<Res>>] 2181 2182 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after) 2183 /// CHECK: <<X:i\d+>> ParameterValue 2184 /// CHECK: <<Y:i\d+>> ParameterValue 2185 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>] 2186 /// CHECK-DAG: Return [<<X>>] 2187 2188 public static int $noinline$intSubAddSimplifyRight(int x, int y) { 2189 int sub = x - y; 2190 return y + sub; 2191 } 2192 2193 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before) 2194 /// CHECK: <<X:f\d+>> ParameterValue 2195 /// CHECK: <<Y:f\d+>> ParameterValue 2196 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>] 2197 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>] 2198 /// CHECK-DAG: Return [<<Res>>] 2199 2200 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after) 2201 /// CHECK: <<X:f\d+>> ParameterValue 2202 /// CHECK: <<Y:f\d+>> ParameterValue 2203 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>] 2204 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>] 2205 /// CHECK-DAG: Return [<<Res>>] 2206 2207 public static float $noinline$floatAddSubSimplifyArg1(float x, float y) { 2208 float sum = x + y; 2209 return sum - x; 2210 } 2211 2212 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before) 2213 /// CHECK: <<X:f\d+>> ParameterValue 2214 /// CHECK: <<Y:f\d+>> ParameterValue 2215 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>] 2216 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>] 2217 /// CHECK-DAG: Return [<<Res>>] 2218 2219 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after) 2220 /// CHECK: <<X:f\d+>> ParameterValue 2221 /// CHECK: <<Y:f\d+>> ParameterValue 2222 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>] 2223 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>] 2224 /// CHECK-DAG: Return [<<Res>>] 2225 2226 public static float $noinline$floatAddSubSimplifyArg2(float x, float y) { 2227 float sum = x + y; 2228 return sum - y; 2229 } 2230 2231 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before) 2232 /// CHECK: <<X:f\d+>> ParameterValue 2233 /// CHECK: <<Y:f\d+>> ParameterValue 2234 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>] 2235 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>] 2236 /// CHECK-DAG: Return [<<Res>>] 2237 2238 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after) 2239 /// CHECK: <<X:f\d+>> ParameterValue 2240 /// CHECK: <<Y:f\d+>> ParameterValue 2241 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>] 2242 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>] 2243 /// CHECK-DAG: Return [<<Res>>] 2244 2245 public static float $noinline$floatSubAddSimplifyLeft(float x, float y) { 2246 float sub = x - y; 2247 return sub + y; 2248 } 2249 2250 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before) 2251 /// CHECK: <<X:f\d+>> ParameterValue 2252 /// CHECK: <<Y:f\d+>> ParameterValue 2253 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>] 2254 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>] 2255 /// CHECK-DAG: Return [<<Res>>] 2256 2257 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after) 2258 /// CHECK: <<X:f\d+>> ParameterValue 2259 /// CHECK: <<Y:f\d+>> ParameterValue 2260 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>] 2261 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>] 2262 /// CHECK-DAG: Return [<<Res>>] 2263 2264 public static float $noinline$floatSubAddSimplifyRight(float x, float y) { 2265 float sub = x - y; 2266 return y + sub; 2267 } 2268 2269 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (before) 2270 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2271 /// CHECK-DAG: <<Get:b\d+>> InstanceFieldGet 2272 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>] 2273 /// CHECK-DAG: Return [<<And>>] 2274 2275 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (after) 2276 /// CHECK-DAG: <<Get:a\d+>> InstanceFieldGet 2277 /// CHECK-DAG: Return [<<Get>>] 2278 2279 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (after) 2280 /// CHECK-NOT: And 2281 /// CHECK-NOT: TypeConversion 2282 public static int $noinline$getUint8FromInstanceByteField(Main m) { 2283 return m.instanceByteField & 0xff; 2284 } 2285 2286 /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (before) 2287 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2288 /// CHECK-DAG: <<Get:b\d+>> StaticFieldGet 2289 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>] 2290 /// CHECK-DAG: Return [<<And>>] 2291 2292 /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (after) 2293 /// CHECK-DAG: <<Get:a\d+>> StaticFieldGet 2294 /// CHECK-DAG: Return [<<Get>>] 2295 2296 /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (after) 2297 /// CHECK-NOT: And 2298 /// CHECK-NOT: TypeConversion 2299 public static int $noinline$getUint8FromStaticByteField() { 2300 return staticByteField & 0xff; 2301 } 2302 2303 /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (before) 2304 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2305 /// CHECK-DAG: <<Get:b\d+>> ArrayGet 2306 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>] 2307 /// CHECK-DAG: Return [<<And>>] 2308 2309 /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (after) 2310 /// CHECK-DAG: <<Get:a\d+>> ArrayGet 2311 /// CHECK-DAG: Return [<<Get>>] 2312 2313 /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (after) 2314 /// CHECK-NOT: And 2315 /// CHECK-NOT: TypeConversion 2316 public static int $noinline$getUint8FromByteArray(byte[] a) { 2317 return a[0] & 0xff; 2318 } 2319 2320 /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (before) 2321 /// CHECK-DAG: <<Cst65535:i\d+>> IntConstant 65535 2322 /// CHECK-DAG: <<Get:s\d+>> InstanceFieldGet 2323 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst65535>>] 2324 /// CHECK-DAG: Return [<<And>>] 2325 2326 /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (after) 2327 /// CHECK-DAG: <<Get:c\d+>> InstanceFieldGet 2328 /// CHECK-DAG: Return [<<Get>>] 2329 2330 /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (after) 2331 /// CHECK-NOT: And 2332 /// CHECK-NOT: TypeConversion 2333 public static int $noinline$getUint16FromInstanceShortField(Main m) { 2334 return m.instanceShortField & 0xffff; 2335 } 2336 2337 /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (before) 2338 /// CHECK-DAG: <<Cst65535:i\d+>> IntConstant 65535 2339 /// CHECK-DAG: <<Get:s\d+>> StaticFieldGet 2340 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst65535>>] 2341 /// CHECK-DAG: Return [<<And>>] 2342 2343 /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (after) 2344 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet 2345 /// CHECK-DAG: Return [<<Get>>] 2346 2347 /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (after) 2348 /// CHECK-NOT: And 2349 /// CHECK-NOT: TypeConversion 2350 public static int $noinline$getUint16FromStaticShortField() { 2351 return staticShortField & 0xffff; 2352 } 2353 2354 /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (before) 2355 /// CHECK-DAG: <<Cst65535:i\d+>> IntConstant 65535 2356 /// CHECK-DAG: <<Get:s\d+>> ArrayGet 2357 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst65535>>] 2358 /// CHECK-DAG: Return [<<And>>] 2359 2360 /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (after) 2361 /// CHECK-DAG: <<Get:c\d+>> ArrayGet 2362 /// CHECK-DAG: Return [<<Get>>] 2363 2364 /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (after) 2365 /// CHECK-NOT: And 2366 /// CHECK-NOT: TypeConversion 2367 public static int $noinline$getUint16FromShortArray(short[] a) { 2368 return a[0] & 0xffff; 2369 } 2370 2371 /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (before) 2372 /// CHECK-DAG: <<Get:c\d+>> InstanceFieldGet 2373 /// CHECK-DAG: <<Conv:s\d+>> TypeConversion [<<Get>>] 2374 /// CHECK-DAG: Return [<<Conv>>] 2375 2376 /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (after) 2377 /// CHECK-DAG: <<Get:s\d+>> InstanceFieldGet 2378 /// CHECK-DAG: Return [<<Get>>] 2379 2380 /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (after) 2381 /// CHECK-NOT: And 2382 /// CHECK-NOT: TypeConversion 2383 public static int $noinline$getInt16FromInstanceCharField(Main m) { 2384 return (short) m.instanceCharField; 2385 } 2386 2387 /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (before) 2388 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet 2389 /// CHECK-DAG: <<Conv:s\d+>> TypeConversion [<<Get>>] 2390 /// CHECK-DAG: Return [<<Conv>>] 2391 2392 /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (after) 2393 /// CHECK-DAG: <<Get:s\d+>> StaticFieldGet 2394 /// CHECK-DAG: Return [<<Get>>] 2395 2396 /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (after) 2397 /// CHECK-NOT: And 2398 /// CHECK-NOT: TypeConversion 2399 public static int $noinline$getInt16FromStaticCharField() { 2400 return (short) staticCharField; 2401 } 2402 2403 /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (before) 2404 /// CHECK-DAG: <<Get:c\d+>> ArrayGet 2405 /// CHECK-DAG: <<Conv:s\d+>> TypeConversion [<<Get>>] 2406 /// CHECK-DAG: Return [<<Conv>>] 2407 2408 /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (after) 2409 /// CHECK-DAG: <<Get:s\d+>> ArrayGet 2410 /// CHECK-DAG: Return [<<Get>>] 2411 2412 /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (after) 2413 /// CHECK-NOT: And 2414 /// CHECK-NOT: TypeConversion 2415 public static int $noinline$getInt16FromCharArray(char[] a) { 2416 return (short) a[0]; 2417 } 2418 2419 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier (before) 2420 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2421 /// CHECK-DAG: <<Get:b\d+>> StaticFieldGet 2422 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>] 2423 /// CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect [<<And>>{{(,[ij]\d+)?}}] 2424 /// CHECK-DAG: Return [<<Invoke>>] 2425 2426 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier (after) 2427 /// CHECK-DAG: <<Get:a\d+>> StaticFieldGet 2428 /// CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect [<<Get>>{{(,[ij]\d+)?}}] 2429 /// CHECK-DAG: Return [<<Invoke>>] 2430 2431 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier$after_inlining (before) 2432 /// CHECK-DAG: <<Get:a\d+>> StaticFieldGet 2433 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<Get>>] 2434 /// CHECK-DAG: Return [<<Conv>>] 2435 2436 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier$after_inlining (after) 2437 /// CHECK-DAG: <<Get:b\d+>> StaticFieldGet 2438 /// CHECK-DAG: Return [<<Get>>] 2439 public static int $noinline$byteToUint8AndBack() { 2440 return $inline$toByte(staticByteField & 0xff); 2441 } 2442 2443 public static int $inline$toByte(int value) { 2444 return (byte) value; 2445 } 2446 2447 /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (before) 2448 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2449 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet 2450 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>] 2451 /// CHECK-DAG: Return [<<And>>] 2452 2453 /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (after) 2454 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2455 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet 2456 /// CHECK-DAG: <<Cnv:a\d+>> TypeConversion [<<Get>>] 2457 /// CHECK-DAG: Return [<<Cnv>>] 2458 2459 /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (after) 2460 /// CHECK-NOT: {{a\d+}} StaticFieldGet 2461 public static int $noinline$getStaticCharFieldAnd0xff() { 2462 return staticCharField & 0xff; 2463 } 2464 2465 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (before) 2466 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8 2467 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2468 /// CHECK-DAG: <<Get:b\d+>> InstanceFieldGet 2469 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>] 2470 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Get>>,<<Const8>>] 2471 /// CHECK-DAG: <<Add:i\d+>> Add [<<And>>,<<Shl>>] 2472 /// CHECK-DAG: Return [<<Add>>] 2473 2474 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (after) 2475 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8 2476 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2477 /// CHECK-DAG: <<Get:b\d+>> InstanceFieldGet 2478 /// CHECK-DAG: <<Cnv:a\d+>> TypeConversion [<<Get>>] 2479 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Get>>,<<Const8>>] 2480 /// CHECK-DAG: <<Add:i\d+>> Add [<<Cnv>>,<<Shl>>] 2481 /// CHECK-DAG: Return [<<Add>>] 2482 2483 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (after) 2484 /// CHECK-NOT: {{a\d+}} InstanceFieldGet 2485 public static int $noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main m) { 2486 byte b = m.instanceByteField; 2487 int v1 = b & 0xff; 2488 int v2 = (b << 8); 2489 return v1 + v2; 2490 } 2491 2492 /// CHECK-START: int Main.$noinline$intAnd0xffToChar(int) instruction_simplifier (before) 2493 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 2494 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2495 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const255>>] 2496 /// CHECK-DAG: <<Conv:c\d+>> TypeConversion [<<And>>] 2497 /// CHECK-DAG: Return [<<Conv>>] 2498 2499 /// CHECK-START: int Main.$noinline$intAnd0xffToChar(int) instruction_simplifier (after) 2500 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 2501 /// CHECK-DAG: <<Conv:a\d+>> TypeConversion [<<Arg>>] 2502 /// CHECK-DAG: Return [<<Conv>>] 2503 public static int $noinline$intAnd0xffToChar(int value) { 2504 return (char) (value & 0xff); 2505 } 2506 2507 /// CHECK-START: int Main.$noinline$intAnd0x1ffToChar(int) instruction_simplifier (before) 2508 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 2509 /// CHECK-DAG: <<Const511:i\d+>> IntConstant 511 2510 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const511>>] 2511 /// CHECK-DAG: <<Conv:c\d+>> TypeConversion [<<And>>] 2512 /// CHECK-DAG: Return [<<Conv>>] 2513 2514 // TODO: Simplify this. Unlike the $noinline$intAnd0xffToChar(), the TypeConversion 2515 // to `char` is not eliminated despite the result of the And being within the `char` range. 2516 2517 // CHECK-START: int Main.$noinline$intAnd0x1ffToChar(int) instruction_simplifier (after) 2518 // CHECK-DAG: <<Arg:i\d+>> ParameterValue 2519 // CHECK-DAG: <<Const511:i\d+>> IntConstant 511 2520 // CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const511>>] 2521 // CHECK-DAG: Return [<<And>>] 2522 public static int $noinline$intAnd0x1ffToChar(int value) { 2523 return (char) (value & 0x1ff); 2524 } 2525 2526 /// CHECK-START: int Main.$noinline$getInstanceCharFieldAnd0x1ffff(Main) instruction_simplifier (before) 2527 /// CHECK-DAG: <<Cst1ffff:i\d+>> IntConstant 131071 2528 /// CHECK-DAG: <<Get:c\d+>> InstanceFieldGet 2529 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst1ffff>>] 2530 /// CHECK-DAG: Return [<<And>>] 2531 2532 /// CHECK-START: int Main.$noinline$getInstanceCharFieldAnd0x1ffff(Main) instruction_simplifier (after) 2533 /// CHECK-DAG: <<Get:c\d+>> InstanceFieldGet 2534 /// CHECK-DAG: Return [<<Get>>] 2535 public static int $noinline$getInstanceCharFieldAnd0x1ffff(Main m) { 2536 return m.instanceCharField & 0x1ffff; 2537 } 2538 2539 /// CHECK-START: int Main.$noinline$bug68142795Byte(byte) instruction_simplifier (before) 2540 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 2541 /// CHECK-DAG: <<Const:i\d+>> IntConstant 255 2542 /// CHECK-DAG: <<And1:i\d+>> And [<<Arg>>,<<Const>>] 2543 /// CHECK-DAG: <<And2:i\d+>> And [<<And1>>,<<Const>>] 2544 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<And2>>] 2545 /// CHECK-DAG: Return [<<Conv>>] 2546 2547 /// CHECK-START: int Main.$noinline$bug68142795Byte(byte) instruction_simplifier (after) 2548 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 2549 /// CHECK-DAG: Return [<<Arg>>] 2550 public static int $noinline$bug68142795Byte(byte b) { 2551 return (byte)(0xff & (b & 0xff)); 2552 } 2553 2554 /// CHECK-START: int Main.$noinline$bug68142795Short(short) instruction_simplifier (before) 2555 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 2556 /// CHECK-DAG: <<Const:i\d+>> IntConstant 65535 2557 /// CHECK-DAG: <<And1:i\d+>> And [<<Arg>>,<<Const>>] 2558 /// CHECK-DAG: <<And2:i\d+>> And [<<And1>>,<<Const>>] 2559 /// CHECK-DAG: <<Conv:s\d+>> TypeConversion [<<And2>>] 2560 /// CHECK-DAG: Return [<<Conv>>] 2561 2562 /// CHECK-START: int Main.$noinline$bug68142795Short(short) instruction_simplifier (after) 2563 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue 2564 /// CHECK-DAG: Return [<<Arg>>] 2565 public static int $noinline$bug68142795Short(short s) { 2566 return (short)(0xffff & (s & 0xffff)); 2567 } 2568 2569 /// CHECK-START: int Main.$noinline$bug68142795Boolean(boolean) instruction_simplifier$after_inlining (before) 2570 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 2571 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 2572 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 2573 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255 2574 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const0>>,<<Const1>>,<<Arg>>] 2575 /// CHECK-DAG: <<And:i\d+>> And [<<Const255>>,<<Select>>] 2576 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<And>>] 2577 /// CHECK-DAG: Return [<<Conv>>] 2578 2579 /// CHECK-START: int Main.$noinline$bug68142795Boolean(boolean) instruction_simplifier$after_inlining (after) 2580 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue 2581 /// CHECK-DAG: Return [<<Arg>>] 2582 public static int $noinline$bug68142795Boolean(boolean b) { 2583 int v = b ? 1 : 0; // Should be simplified to "b" after inlining. 2584 return (byte)($inline$get255() & v); 2585 } 2586 2587 /// CHECK-START: int Main.$noinline$bug68142795Elaborate(byte) instruction_simplifier (before) 2588 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 2589 /// CHECK-DAG: <<Int255:i\d+>> IntConstant 255 2590 /// CHECK-DAG: <<Long255:j\d+>> LongConstant 255 2591 /// CHECK-DAG: <<And1:i\d+>> And [<<Arg>>,<<Int255>>] 2592 /// CHECK-DAG: <<Conv1:j\d+>> TypeConversion [<<And1>>] 2593 /// CHECK-DAG: <<And2:j\d+>> And [<<Conv1>>,<<Long255>>] 2594 /// CHECK-DAG: <<Conv2:i\d+>> TypeConversion [<<And2>>] 2595 /// CHECK-DAG: <<Conv3:b\d+>> TypeConversion [<<Conv2>>] 2596 /// CHECK-DAG: Return [<<Conv3>>] 2597 2598 /// CHECK-START: int Main.$noinline$bug68142795Elaborate(byte) instruction_simplifier (after) 2599 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue 2600 /// CHECK-DAG: Return [<<Arg>>] 2601 public static int $noinline$bug68142795Elaborate(byte b) { 2602 return (byte)((int)(((long)(b & 0xff)) & 255L)); 2603 } 2604 2605 public static void main(String[] args) { 2606 int arg = 123456; 2607 float floatArg = 123456.125f; 2608 2609 assertLongEquals(arg, $noinline$Add0(arg)); 2610 assertIntEquals(5, $noinline$AddAddSubAddConst(1)); 2611 assertIntEquals(arg, $noinline$AndAllOnes(arg)); 2612 assertLongEquals(arg, $noinline$Div1(arg)); 2613 assertIntEquals(-arg, $noinline$DivN1(arg)); 2614 assertLongEquals(arg, $noinline$Mul1(arg)); 2615 assertIntEquals(-arg, $noinline$MulN1(arg)); 2616 assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg)); 2617 assertLongEquals(2640, $noinline$MulMulMulConst(2)); 2618 assertIntEquals(arg, $noinline$Or0(arg)); 2619 assertLongEquals(arg, $noinline$OrSame(arg)); 2620 assertIntEquals(arg, $noinline$Shl0(arg)); 2621 assertLongEquals(arg, $noinline$Shr0(arg)); 2622 assertLongEquals(arg, $noinline$Shr64(arg)); 2623 assertLongEquals(arg, $noinline$Sub0(arg)); 2624 assertIntEquals(-arg, $noinline$SubAliasNeg(arg)); 2625 assertIntEquals(9, $noinline$SubAddConst1(2)); 2626 assertIntEquals(-2, $noinline$SubAddConst2(3)); 2627 assertLongEquals(3, $noinline$SubSubConst(4)); 2628 assertLongEquals(arg, $noinline$UShr0(arg)); 2629 assertIntEquals(arg, $noinline$Xor0(arg)); 2630 assertIntEquals(~arg, $noinline$XorAllOnes(arg)); 2631 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1)); 2632 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1)); 2633 assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1)); 2634 assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1)); 2635 assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1)); 2636 assertLongEquals(arg, $noinline$NegNeg1(arg)); 2637 assertIntEquals(0, $noinline$NegNeg2(arg)); 2638 assertLongEquals(arg, $noinline$NegNeg3(arg)); 2639 assertIntEquals(1, $noinline$NegSub1(arg, arg + 1)); 2640 assertIntEquals(1, $noinline$NegSub2(arg, arg + 1)); 2641 assertLongEquals(arg, $noinline$NotNot1(arg)); 2642 assertLongEquals(arg, $noinline$runSmaliTestLong("$noinline$NotNot1", arg)); 2643 assertIntEquals(-1, $noinline$NotNot2(arg)); 2644 assertIntEquals(-1, $noinline$runSmaliTestInt("$noinline$NotNot2", arg)); 2645 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1)); 2646 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1)); 2647 assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1)); 2648 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true)); 2649 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true)); 2650 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false)); 2651 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false)); 2652 assertBooleanEquals(true, $noinline$NotNotBool(true)); 2653 assertBooleanEquals(true, $noinline$runSmaliTestBoolean("$noinline$NotNotBool", true)); 2654 assertBooleanEquals(false, $noinline$NotNotBool(false)); 2655 assertBooleanEquals(false, $noinline$runSmaliTestBoolean("$noinline$NotNotBool", false)); 2656 assertFloatEquals(50.0f, $noinline$Div2(100.0f)); 2657 assertDoubleEquals(75.0, $noinline$Div2(150.0)); 2658 assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f)); 2659 assertDoubleEquals(-600.0, $noinline$DivMP25(150.0)); 2660 assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567)); 2661 assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L)); 2662 assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567)); 2663 assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L)); 2664 assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567)); 2665 assertIntEquals(0x60, $noinline$Shr25And127(0xc1234567)); 2666 assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L)); 2667 assertLongEquals(0x60L, $noinline$Shr57And127(0xc123456787654321L)); 2668 assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567)); 2669 assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L)); 2670 assertIntEquals(0, $noinline$mulPow2Plus1(0)); 2671 assertIntEquals(9, $noinline$mulPow2Plus1(1)); 2672 assertIntEquals(18, $noinline$mulPow2Plus1(2)); 2673 assertIntEquals(900, $noinline$mulPow2Plus1(100)); 2674 assertIntEquals(111105, $noinline$mulPow2Plus1(12345)); 2675 assertLongEquals(0, $noinline$mulPow2Minus1(0)); 2676 assertLongEquals(31, $noinline$mulPow2Minus1(1)); 2677 assertLongEquals(62, $noinline$mulPow2Minus1(2)); 2678 assertLongEquals(3100, $noinline$mulPow2Minus1(100)); 2679 assertLongEquals(382695, $noinline$mulPow2Minus1(12345)); 2680 2681 booleanField = false; 2682 assertIntEquals($noinline$booleanFieldNotEqualOne(), 54); 2683 assertIntEquals($noinline$booleanFieldEqualZero(), 54); 2684 booleanField = true; 2685 assertIntEquals(13, $noinline$booleanFieldNotEqualOne()); 2686 assertIntEquals(13, $noinline$booleanFieldEqualZero()); 2687 assertIntEquals(54, $noinline$intConditionNotEqualOne(6)); 2688 assertIntEquals(13, $noinline$intConditionNotEqualOne(43)); 2689 assertIntEquals(54, $noinline$intConditionEqualZero(6)); 2690 assertIntEquals(13, $noinline$intConditionEqualZero(43)); 2691 assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f)); 2692 assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f)); 2693 assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0)); 2694 assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0)); 2695 2696 assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567)); 2697 assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE)); 2698 assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE)); 2699 assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321)); 2700 assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12)); 2701 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE)); 2702 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE)); 2703 assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f)); 2704 assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f)); 2705 assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123)); 2706 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE)); 2707 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE)); 2708 assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234)); 2709 assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE)); 2710 assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE)); 2711 assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f)); 2712 assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1))); 2713 assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1))); 2714 assertIntEquals(-54321, $noinline$intToFloatToInt(-54321)); 2715 assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L)); 2716 assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE)); 2717 assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE)); 2718 assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L)); 2719 assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L)); 2720 assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE)); 2721 assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE)); 2722 assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678)); 2723 assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE)); 2724 assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE)); 2725 assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678)); 2726 assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE)); 2727 assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE)); 2728 assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234)); 2729 assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0)); 2730 assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE)); 2731 assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE)); 2732 assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025)); 2733 assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023)); 2734 assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1)); 2735 2736 assertLongEquals(0x55411410L, $noinline$intAndSmallLongConstant(0x55555555)); 2737 assertLongEquals(0xffffffffaa028aa2L, $noinline$intAndSmallLongConstant(0xaaaaaaaa)); 2738 assertLongEquals(0x44101440L, $noinline$intAndLargeLongConstant(0x55555555)); 2739 assertLongEquals(0x208a002aaL, $noinline$intAndLargeLongConstant(0xaaaaaaaa)); 2740 assertLongEquals(7L, $noinline$intShr28And15L(0x76543210)); 2741 2742 assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L)); 2743 assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE)); 2744 assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE)); 2745 assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234)); 2746 assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE)); 2747 assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE)); 2748 assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321)); 2749 assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888)); 2750 assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE)); 2751 assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE)); 2752 2753 assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0)); 2754 assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1)); 2755 assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2)); 2756 assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345)); 2757 assertDoubleEquals((double)Short.MAX_VALUE, 2758 $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE)); 2759 assertDoubleEquals((double)Short.MIN_VALUE, 2760 $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE)); 2761 2762 assertIntEquals(13, $noinline$intReverseCondition(41)); 2763 assertIntEquals(13, $noinline$intReverseConditionNaN(-5)); 2764 2765 for (String condition : new String[] { "Equal", "NotEqual" }) { 2766 for (String constant : new String[] { "True", "False" }) { 2767 for (String side : new String[] { "Rhs", "Lhs" }) { 2768 String name = condition + constant + side; 2769 assertIntEquals(5, $noinline$runSmaliTest(name, true)); 2770 assertIntEquals(3, $noinline$runSmaliTest(name, false)); 2771 } 2772 } 2773 } 2774 2775 assertIntEquals(0, $noinline$runSmaliTestInt("AddSubConst", 1)); 2776 assertIntEquals(3, $noinline$runSmaliTestInt("SubAddConst", 2)); 2777 assertIntEquals(-16, $noinline$runSmaliTestInt("SubSubConst1", 3)); 2778 assertIntEquals(-5, $noinline$runSmaliTestInt("SubSubConst2", 4)); 2779 assertIntEquals(26, $noinline$runSmaliTestInt("SubSubConst3", 5)); 2780 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3)); 2781 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32)); 2782 assertLongEquals(0xffffffffffffeaf3L, 2783 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50)); 2784 assertLongEquals(0xffffffffffffeaf3L, 2785 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64)); 2786 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10)); 2787 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128)); 2788 assertLongEquals(0xaf37bc048d159e24L, 2789 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2)); 2790 assertLongEquals(0xaf37bc048d159e24L, 2791 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256)); 2792 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13)); 2793 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512)); 2794 assertIntEquals(0x5f49eb48, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 2)); 2795 assertIntEquals(0xbd4c29b0, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 3)); 2796 assertIntEquals(0xc0fed1ca, $noinline$intNecessaryShiftModifications(0xabcdef01, 2)); 2797 assertIntEquals(0x03578ebc, $noinline$intNecessaryShiftModifications(0xabcdef01, 3)); 2798 2799 assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321)); 2800 assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321)); 2801 assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321)); 2802 assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321)); 2803 assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f)); 2804 assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f)); 2805 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f)); 2806 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f)); 2807 2808 Main m = new Main(); 2809 m.instanceByteField = -1; 2810 assertIntEquals(0xff, $noinline$getUint8FromInstanceByteField(m)); 2811 staticByteField = -2; 2812 assertIntEquals(0xfe, $noinline$getUint8FromStaticByteField()); 2813 assertIntEquals(0xfd, $noinline$getUint8FromByteArray(new byte[] { -3 })); 2814 m.instanceShortField = -4; 2815 assertIntEquals(0xfffc, $noinline$getUint16FromInstanceShortField(m)); 2816 staticShortField = -5; 2817 assertIntEquals(0xfffb, $noinline$getUint16FromStaticShortField()); 2818 assertIntEquals(0xfffa, $noinline$getUint16FromShortArray(new short[] { -6 })); 2819 m.instanceCharField = 0xfff9; 2820 assertIntEquals(-7, $noinline$getInt16FromInstanceCharField(m)); 2821 staticCharField = 0xfff8; 2822 assertIntEquals(-8, $noinline$getInt16FromStaticCharField()); 2823 assertIntEquals(-9, $noinline$getInt16FromCharArray(new char[] { 0xfff7 })); 2824 2825 staticCharField = 0xfff6; 2826 assertIntEquals(0xf6, $noinline$getStaticCharFieldAnd0xff()); 2827 2828 staticByteField = -11; 2829 assertIntEquals(-11, $noinline$byteToUint8AndBack()); 2830 2831 m.instanceByteField = -12; 2832 assertIntEquals(0xfffff4f4, $noinline$getUint8FromInstanceByteFieldWithAnotherUse(m)); 2833 2834 assertIntEquals(0x21, $noinline$intAnd0xffToChar(0x87654321)); 2835 assertIntEquals(0x121, $noinline$intAnd0x1ffToChar(0x87654321)); 2836 2837 m.instanceCharField = 'x'; 2838 assertIntEquals('x', $noinline$getInstanceCharFieldAnd0x1ffff(m)); 2839 2840 assertIntEquals(0x7f, $noinline$bug68142795Byte((byte) 0x7f)); 2841 assertIntEquals((byte) 0x80, $noinline$bug68142795Byte((byte) 0x80)); 2842 assertIntEquals(0x7fff, $noinline$bug68142795Short((short) 0x7fff)); 2843 assertIntEquals((short) 0x8000, $noinline$bug68142795Short((short) 0x8000)); 2844 assertIntEquals(0, $noinline$bug68142795Boolean(false)); 2845 assertIntEquals(1, $noinline$bug68142795Boolean(true)); 2846 assertIntEquals(0x7f, $noinline$bug68142795Elaborate((byte) 0x7f)); 2847 assertIntEquals((byte) 0x80, $noinline$bug68142795Elaborate((byte) 0x80)); 2848 } 2849 2850 private static boolean $inline$true() { return true; } 2851 private static boolean $inline$false() { return false; } 2852 private static int $inline$get255() { return 255; } 2853 2854 public static boolean booleanField; 2855 2856 public static byte staticByteField; 2857 public static char staticCharField; 2858 public static short staticShortField; 2859 2860 public byte instanceByteField; 2861 public char instanceCharField; 2862 public short instanceShortField; 2863 } 2864