1 /* 2 * Copyright (C) 2014 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 // Workaround for b/18051191. 22 class InnerClass {} 23 assertFalse(boolean condition)24 public static void assertFalse(boolean condition) { 25 if (condition) { 26 throw new Error(); 27 } 28 } 29 assertTrue(boolean condition)30 public static void assertTrue(boolean condition) { 31 if (!condition) { 32 throw new Error(); 33 } 34 } 35 assertIntEquals(int expected, int result)36 public static void assertIntEquals(int expected, int result) { 37 if (expected != result) { 38 throw new Error("Expected: " + expected + ", found: " + result); 39 } 40 } 41 assertLongEquals(long expected, long result)42 public static void assertLongEquals(long expected, long result) { 43 if (expected != result) { 44 throw new Error("Expected: " + expected + ", found: " + result); 45 } 46 } 47 assertFloatEquals(float expected, float result)48 public static void assertFloatEquals(float expected, float result) { 49 if (expected != result) { 50 throw new Error("Expected: " + expected + ", found: " + result); 51 } 52 } 53 assertDoubleEquals(double expected, double result)54 public static void assertDoubleEquals(double expected, double result) { 55 if (expected != result) { 56 throw new Error("Expected: " + expected + ", found: " + result); 57 } 58 } 59 $inline$int(int x)60 private static int $inline$int(int x) { 61 return x; 62 } 63 $inline$long(long x)64 private static long $inline$long(long x) { 65 return x; 66 } 67 $inline$float(float x)68 private static float $inline$float(float x) { 69 return x; 70 } 71 $inline$double(double x)72 private static double $inline$double(double x) { 73 return x; 74 } 75 76 // Wrappers around methods located in file TestCmp.smali. 77 smaliCmpLongConstants()78 public int smaliCmpLongConstants() throws Exception { 79 Method m = testCmp.getMethod("$opt$CmpLongConstants"); 80 return (Integer)m.invoke(null); 81 } smaliCmpGtFloatConstants()82 public int smaliCmpGtFloatConstants() throws Exception { 83 Method m = testCmp.getMethod("$opt$CmpGtFloatConstants"); 84 return (Integer)m.invoke(null); 85 } smaliCmpLtFloatConstants()86 public int smaliCmpLtFloatConstants() throws Exception { 87 Method m = testCmp.getMethod("$opt$CmpLtFloatConstants"); 88 return (Integer)m.invoke(null); 89 } smaliCmpGtDoubleConstants()90 public int smaliCmpGtDoubleConstants() throws Exception { 91 Method m = testCmp.getMethod("$opt$CmpGtDoubleConstants"); 92 return (Integer)m.invoke(null); 93 } smaliCmpLtDoubleConstants()94 public int smaliCmpLtDoubleConstants() throws Exception { 95 Method m = testCmp.getMethod("$opt$CmpLtDoubleConstants"); 96 return (Integer)m.invoke(null); 97 } 98 smaliCmpLongSameConstant()99 public int smaliCmpLongSameConstant() throws Exception { 100 Method m = testCmp.getMethod("$opt$CmpLongSameConstant"); 101 return (Integer)m.invoke(null); 102 } smaliCmpGtFloatSameConstant()103 public int smaliCmpGtFloatSameConstant() throws Exception { 104 Method m = testCmp.getMethod("$opt$CmpGtFloatSameConstant"); 105 return (Integer)m.invoke(null); 106 } smaliCmpLtFloatSameConstant()107 public int smaliCmpLtFloatSameConstant() throws Exception { 108 Method m = testCmp.getMethod("$opt$CmpLtFloatSameConstant"); 109 return (Integer)m.invoke(null); 110 } smaliCmpGtDoubleSameConstant()111 public int smaliCmpGtDoubleSameConstant() throws Exception { 112 Method m = testCmp.getMethod("$opt$CmpGtDoubleSameConstant"); 113 return (Integer)m.invoke(null); 114 } smaliCmpLtDoubleSameConstant()115 public int smaliCmpLtDoubleSameConstant() throws Exception { 116 Method m = testCmp.getMethod("$opt$CmpLtDoubleSameConstant"); 117 return (Integer)m.invoke(null); 118 } 119 smaliCmpGtFloatConstantWithNaN()120 public int smaliCmpGtFloatConstantWithNaN() throws Exception { 121 Method m = testCmp.getMethod("$opt$CmpGtFloatConstantWithNaN"); 122 return (Integer)m.invoke(null); 123 } smaliCmpLtFloatConstantWithNaN()124 public int smaliCmpLtFloatConstantWithNaN() throws Exception { 125 Method m = testCmp.getMethod("$opt$CmpLtFloatConstantWithNaN"); 126 return (Integer)m.invoke(null); 127 } smaliCmpGtDoubleConstantWithNaN()128 public int smaliCmpGtDoubleConstantWithNaN() throws Exception { 129 Method m = testCmp.getMethod("$opt$CmpGtDoubleConstantWithNaN"); 130 return (Integer)m.invoke(null); 131 } smaliCmpLtDoubleConstantWithNaN()132 public int smaliCmpLtDoubleConstantWithNaN() throws Exception { 133 Method m = testCmp.getMethod("$opt$CmpLtDoubleConstantWithNaN"); 134 return (Integer)m.invoke(null); 135 } 136 137 138 /** 139 * Exercise constant folding on negation. 140 */ 141 142 /// CHECK-START: int Main.IntNegation() constant_folding (before) 143 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 144 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Const42>>] 145 /// CHECK-DAG: Return [<<Neg>>] 146 147 /// CHECK-START: int Main.IntNegation() constant_folding (after) 148 /// CHECK-DAG: <<ConstN42:i\d+>> IntConstant -42 149 /// CHECK-DAG: Return [<<ConstN42>>] 150 151 /// CHECK-START: int Main.IntNegation() constant_folding (after) 152 /// CHECK-NOT: Neg 153 IntNegation()154 public static int IntNegation() { 155 int x, y; 156 x = 42; 157 y = -x; 158 return y; 159 } 160 161 /// CHECK-START: long Main.LongNegation() constant_folding (before) 162 /// CHECK-DAG: <<Const42:j\d+>> LongConstant 42 163 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Const42>>] 164 /// CHECK-DAG: Return [<<Neg>>] 165 166 /// CHECK-START: long Main.LongNegation() constant_folding (after) 167 /// CHECK-DAG: <<ConstN42:j\d+>> LongConstant -42 168 /// CHECK-DAG: Return [<<ConstN42>>] 169 170 /// CHECK-START: long Main.LongNegation() constant_folding (after) 171 /// CHECK-NOT: Neg 172 LongNegation()173 public static long LongNegation() { 174 long x, y; 175 x = 42L; 176 y = -x; 177 return y; 178 } 179 180 /// CHECK-START: float Main.FloatNegation() constant_folding (before) 181 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42 182 /// CHECK-DAG: <<Neg:f\d+>> Neg [<<Const42>>] 183 /// CHECK-DAG: Return [<<Neg>>] 184 185 /// CHECK-START: float Main.FloatNegation() constant_folding (after) 186 /// CHECK-DAG: <<ConstN42:f\d+>> FloatConstant -42 187 /// CHECK-DAG: Return [<<ConstN42>>] 188 189 /// CHECK-START: float Main.FloatNegation() constant_folding (after) 190 /// CHECK-NOT: Neg 191 FloatNegation()192 public static float FloatNegation() { 193 float x, y; 194 x = 42F; 195 y = -x; 196 return y; 197 } 198 199 /// CHECK-START: double Main.DoubleNegation() constant_folding (before) 200 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42 201 /// CHECK-DAG: <<Neg:d\d+>> Neg [<<Const42>>] 202 /// CHECK-DAG: Return [<<Neg>>] 203 204 /// CHECK-START: double Main.DoubleNegation() constant_folding (after) 205 /// CHECK-DAG: <<ConstN42:d\d+>> DoubleConstant -42 206 /// CHECK-DAG: Return [<<ConstN42>>] 207 208 /// CHECK-START: double Main.DoubleNegation() constant_folding (after) 209 /// CHECK-NOT: Neg 210 DoubleNegation()211 public static double DoubleNegation() { 212 double x, y; 213 x = 42D; 214 y = -x; 215 return y; 216 } 217 218 /** 219 * Exercise constant folding on addition. 220 */ 221 222 /// CHECK-START: int Main.IntAddition1() constant_folding$after_inlining (before) 223 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 224 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 225 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const1>>,<<Const2>>] 226 /// CHECK-DAG: Return [<<Add>>] 227 228 /// CHECK-START: int Main.IntAddition1() constant_folding$after_inlining (after) 229 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 230 /// CHECK-DAG: Return [<<Const3>>] 231 232 /// CHECK-START: int Main.IntAddition1() constant_folding$after_inlining (after) 233 /// CHECK-NOT: Add 234 IntAddition1()235 public static int IntAddition1() { 236 int a, b, c; 237 a = $inline$int(1); 238 b = $inline$int(2); 239 c = a + b; 240 return c; 241 } 242 243 /// CHECK-START: int Main.IntAddition2() constant_folding$after_inlining (before) 244 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 245 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 246 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 247 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6 248 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Const1>>,<<Const2>>] 249 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Const5>>,<<Const6>>] 250 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add1>>,<<Add2>>] 251 /// CHECK-DAG: Return [<<Add3>>] 252 253 /// CHECK-START: int Main.IntAddition2() constant_folding$after_inlining (after) 254 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14 255 /// CHECK-DAG: Return [<<Const14>>] 256 257 /// CHECK-START: int Main.IntAddition2() constant_folding$after_inlining (after) 258 /// CHECK-NOT: Add 259 IntAddition2()260 public static int IntAddition2() { 261 int a, b, c; 262 a = $inline$int(1); 263 b = $inline$int(2); 264 a += b; 265 b = $inline$int(5); 266 c = $inline$int(6); 267 b += c; 268 c = a + b; 269 return c; 270 } 271 272 /// CHECK-START: long Main.LongAddition() constant_folding$after_inlining (before) 273 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1 274 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 275 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>] 276 /// CHECK-DAG: Return [<<Add>>] 277 278 /// CHECK-START: long Main.LongAddition() constant_folding$after_inlining (after) 279 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 280 /// CHECK-DAG: Return [<<Const3>>] 281 282 /// CHECK-START: long Main.LongAddition() constant_folding$after_inlining (after) 283 /// CHECK-NOT: Add 284 LongAddition()285 public static long LongAddition() { 286 long a, b, c; 287 a = $inline$long(1L); 288 b = $inline$long(2L); 289 c = a + b; 290 return c; 291 } 292 293 /// CHECK-START: float Main.FloatAddition() constant_folding$after_inlining (before) 294 /// CHECK-DAG: <<Const1:f\d+>> FloatConstant 1 295 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2 296 /// CHECK-DAG: <<Add:f\d+>> Add [<<Const1>>,<<Const2>>] 297 /// CHECK-DAG: Return [<<Add>>] 298 299 /// CHECK-START: float Main.FloatAddition() constant_folding$after_inlining (after) 300 /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3 301 /// CHECK-DAG: Return [<<Const3>>] 302 303 /// CHECK-START: float Main.FloatAddition() constant_folding$after_inlining (after) 304 /// CHECK-NOT: Add 305 FloatAddition()306 public static float FloatAddition() { 307 float a, b, c; 308 a = $inline$float(1F); 309 b = $inline$float(2F); 310 c = a + b; 311 return c; 312 } 313 314 /// CHECK-START: double Main.DoubleAddition() constant_folding$after_inlining (before) 315 /// CHECK-DAG: <<Const1:d\d+>> DoubleConstant 1 316 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2 317 /// CHECK-DAG: <<Add:d\d+>> Add [<<Const1>>,<<Const2>>] 318 /// CHECK-DAG: Return [<<Add>>] 319 320 /// CHECK-START: double Main.DoubleAddition() constant_folding$after_inlining (after) 321 /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3 322 /// CHECK-DAG: Return [<<Const3>>] 323 324 /// CHECK-START: double Main.DoubleAddition() constant_folding$after_inlining (after) 325 /// CHECK-NOT: Add 326 DoubleAddition()327 public static double DoubleAddition() { 328 double a, b, c; 329 a = $inline$double(1D); 330 b = $inline$double(2D); 331 c = a + b; 332 return c; 333 } 334 335 336 /** 337 * Exercise constant folding on subtraction. 338 */ 339 340 /// CHECK-START: int Main.IntSubtraction() constant_folding$after_inlining (before) 341 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6 342 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 343 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const6>>,<<Const2>>] 344 /// CHECK-DAG: Return [<<Sub>>] 345 346 /// CHECK-START: int Main.IntSubtraction() constant_folding$after_inlining (after) 347 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4 348 /// CHECK-DAG: Return [<<Const4>>] 349 350 /// CHECK-START: int Main.IntSubtraction() constant_folding$after_inlining (after) 351 /// CHECK-NOT: Sub 352 IntSubtraction()353 public static int IntSubtraction() { 354 int a, b, c; 355 a = $inline$int(6); 356 b = $inline$int(2); 357 c = a - b; 358 return c; 359 } 360 361 /// CHECK-START: long Main.LongSubtraction() constant_folding$after_inlining (before) 362 /// CHECK-DAG: <<Const6:j\d+>> LongConstant 6 363 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 364 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const6>>,<<Const2>>] 365 /// CHECK-DAG: Return [<<Sub>>] 366 367 /// CHECK-START: long Main.LongSubtraction() constant_folding$after_inlining (after) 368 /// CHECK-DAG: <<Const4:j\d+>> LongConstant 4 369 /// CHECK-DAG: Return [<<Const4>>] 370 371 /// CHECK-START: long Main.LongSubtraction() constant_folding$after_inlining (after) 372 /// CHECK-NOT: Sub 373 LongSubtraction()374 public static long LongSubtraction() { 375 long a, b, c; 376 a = $inline$long(6L); 377 b = $inline$long(2L); 378 c = a - b; 379 return c; 380 } 381 382 /// CHECK-START: float Main.FloatSubtraction() constant_folding$after_inlining (before) 383 /// CHECK-DAG: <<Const6:f\d+>> FloatConstant 6 384 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2 385 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<Const6>>,<<Const2>>] 386 /// CHECK-DAG: Return [<<Sub>>] 387 388 /// CHECK-START: float Main.FloatSubtraction() constant_folding$after_inlining (after) 389 /// CHECK-DAG: <<Const4:f\d+>> FloatConstant 4 390 /// CHECK-DAG: Return [<<Const4>>] 391 392 /// CHECK-START: float Main.FloatSubtraction() constant_folding$after_inlining (after) 393 /// CHECK-NOT: Sub 394 FloatSubtraction()395 public static float FloatSubtraction() { 396 float a, b, c; 397 a = $inline$float(6F); 398 b = $inline$float(2F); 399 c = a - b; 400 return c; 401 } 402 403 /// CHECK-START: double Main.DoubleSubtraction() constant_folding$after_inlining (before) 404 /// CHECK-DAG: <<Const6:d\d+>> DoubleConstant 6 405 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2 406 /// CHECK-DAG: <<Sub:d\d+>> Sub [<<Const6>>,<<Const2>>] 407 /// CHECK-DAG: Return [<<Sub>>] 408 409 /// CHECK-START: double Main.DoubleSubtraction() constant_folding$after_inlining (after) 410 /// CHECK-DAG: <<Const4:d\d+>> DoubleConstant 4 411 /// CHECK-DAG: Return [<<Const4>>] 412 413 /// CHECK-START: double Main.DoubleSubtraction() constant_folding$after_inlining (after) 414 /// CHECK-NOT: Sub 415 DoubleSubtraction()416 public static double DoubleSubtraction() { 417 double a, b, c; 418 a = $inline$double(6D); 419 b = $inline$double(2D); 420 c = a - b; 421 return c; 422 } 423 424 425 /** 426 * Exercise constant folding on multiplication. 427 */ 428 429 /// CHECK-START: int Main.IntMultiplication() constant_folding$after_inlining (before) 430 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 431 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 432 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Const7>>,<<Const3>>] 433 /// CHECK-DAG: Return [<<Mul>>] 434 435 /// CHECK-START: int Main.IntMultiplication() constant_folding$after_inlining (after) 436 /// CHECK-DAG: <<Const21:i\d+>> IntConstant 21 437 /// CHECK-DAG: Return [<<Const21>>] 438 439 /// CHECK-START: int Main.IntMultiplication() constant_folding$after_inlining (after) 440 /// CHECK-NOT: Mul 441 IntMultiplication()442 public static int IntMultiplication() { 443 int a, b, c; 444 a = $inline$int(7); 445 b = $inline$int(3); 446 c = a * b; 447 return c; 448 } 449 450 /// CHECK-START: long Main.LongMultiplication() constant_folding$after_inlining (before) 451 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7 452 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 453 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const7>>,<<Const3>>] 454 /// CHECK-DAG: Return [<<Mul>>] 455 456 /// CHECK-START: long Main.LongMultiplication() constant_folding$after_inlining (after) 457 /// CHECK-DAG: <<Const21:j\d+>> LongConstant 21 458 /// CHECK-DAG: Return [<<Const21>>] 459 460 /// CHECK-START: long Main.LongMultiplication() constant_folding$after_inlining (after) 461 /// CHECK-NOT: Mul 462 LongMultiplication()463 public static long LongMultiplication() { 464 long a, b, c; 465 a = $inline$long(7L); 466 b = $inline$long(3L); 467 c = a * b; 468 return c; 469 } 470 471 /// CHECK-START: float Main.FloatMultiplication() constant_folding$after_inlining (before) 472 /// CHECK-DAG: <<Const7:f\d+>> FloatConstant 7 473 /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3 474 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Const7>>,<<Const3>>] 475 /// CHECK-DAG: Return [<<Mul>>] 476 477 /// CHECK-START: float Main.FloatMultiplication() constant_folding$after_inlining (after) 478 /// CHECK-DAG: <<Const21:f\d+>> FloatConstant 21 479 /// CHECK-DAG: Return [<<Const21>>] 480 481 /// CHECK-START: float Main.FloatMultiplication() constant_folding$after_inlining (after) 482 /// CHECK-NOT: Mul 483 FloatMultiplication()484 public static float FloatMultiplication() { 485 float a, b, c; 486 a = $inline$float(7F); 487 b = $inline$float(3F); 488 c = a * b; 489 return c; 490 } 491 492 /// CHECK-START: double Main.DoubleMultiplication() constant_folding$after_inlining (before) 493 /// CHECK-DAG: <<Const7:d\d+>> DoubleConstant 7 494 /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3 495 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Const7>>,<<Const3>>] 496 /// CHECK-DAG: Return [<<Mul>>] 497 498 /// CHECK-START: double Main.DoubleMultiplication() constant_folding$after_inlining (after) 499 /// CHECK-DAG: <<Const21:d\d+>> DoubleConstant 21 500 /// CHECK-DAG: Return [<<Const21>>] 501 502 /// CHECK-START: double Main.DoubleMultiplication() constant_folding$after_inlining (after) 503 /// CHECK-NOT: Mul 504 DoubleMultiplication()505 public static double DoubleMultiplication() { 506 double a, b, c; 507 a = $inline$double(7D); 508 b = $inline$double(3D); 509 c = a * b; 510 return c; 511 } 512 513 514 /** 515 * Exercise constant folding on division. 516 */ 517 518 /// CHECK-START: int Main.IntDivision() constant_folding$after_inlining (before) 519 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8 520 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 521 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>] 522 /// CHECK-DAG: <<Div:i\d+>> Div [<<Const8>>,<<Div0Chk>>] 523 /// CHECK-DAG: Return [<<Div>>] 524 525 /// CHECK-START: int Main.IntDivision() constant_folding$after_inlining (after) 526 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 527 /// CHECK-DAG: Return [<<Const2>>] 528 529 /// CHECK-START: int Main.IntDivision() constant_folding$after_inlining (after) 530 /// CHECK-NOT: DivZeroCheck 531 /// CHECK-NOT: Div 532 IntDivision()533 public static int IntDivision() { 534 int a, b, c; 535 a = $inline$int(8); 536 b = $inline$int(3); 537 c = a / b; 538 return c; 539 } 540 541 /// CHECK-START: long Main.LongDivision() constant_folding$after_inlining (before) 542 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8 543 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 544 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>] 545 /// CHECK-DAG: <<Div:j\d+>> Div [<<Const8>>,<<Div0Chk>>] 546 /// CHECK-DAG: Return [<<Div>>] 547 548 /// CHECK-START: long Main.LongDivision() constant_folding$after_inlining (after) 549 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 550 /// CHECK-DAG: Return [<<Const2>>] 551 552 /// CHECK-START: long Main.LongDivision() constant_folding$after_inlining (after) 553 /// CHECK-NOT: DivZeroCheck 554 /// CHECK-NOT: Div 555 LongDivision()556 public static long LongDivision() { 557 long a, b, c; 558 a = $inline$long(8L); 559 b = $inline$long(3L); 560 c = a / b; 561 return c; 562 } 563 564 /// CHECK-START: float Main.FloatDivision() constant_folding$after_inlining (before) 565 /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8 566 /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5 567 /// CHECK-DAG: <<Div:f\d+>> Div [<<Const8>>,<<Const2P5>>] 568 /// CHECK-DAG: Return [<<Div>>] 569 570 /// CHECK-START: float Main.FloatDivision() constant_folding$after_inlining (after) 571 /// CHECK-DAG: <<Const3P2:f\d+>> FloatConstant 3.2 572 /// CHECK-DAG: Return [<<Const3P2>>] 573 574 /// CHECK-START: float Main.FloatDivision() constant_folding$after_inlining (after) 575 /// CHECK-NOT: Div 576 FloatDivision()577 public static float FloatDivision() { 578 float a, b, c; 579 a = $inline$float(8F); 580 b = $inline$float(2.5F); 581 c = a / b; 582 return c; 583 } 584 585 /// CHECK-START: double Main.DoubleDivision() constant_folding$after_inlining (before) 586 /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8 587 /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5 588 /// CHECK-DAG: <<Div:d\d+>> Div [<<Const8>>,<<Const2P5>>] 589 /// CHECK-DAG: Return [<<Div>>] 590 591 /// CHECK-START: double Main.DoubleDivision() constant_folding$after_inlining (after) 592 /// CHECK-DAG: <<Const3P2:d\d+>> DoubleConstant 3.2 593 /// CHECK-DAG: Return [<<Const3P2>>] 594 595 /// CHECK-START: double Main.DoubleDivision() constant_folding$after_inlining (after) 596 /// CHECK-NOT: Div 597 DoubleDivision()598 public static double DoubleDivision() { 599 double a, b, c; 600 a = $inline$double(8D); 601 b = $inline$double(2.5D); 602 c = a / b; 603 return c; 604 } 605 606 607 /** 608 * Exercise constant folding on remainder. 609 */ 610 611 /// CHECK-START: int Main.IntRemainder() constant_folding$after_inlining (before) 612 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8 613 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 614 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>] 615 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Const8>>,<<Div0Chk>>] 616 /// CHECK-DAG: Return [<<Rem>>] 617 618 /// CHECK-START: int Main.IntRemainder() constant_folding$after_inlining (after) 619 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 620 /// CHECK-DAG: Return [<<Const2>>] 621 622 /// CHECK-START: int Main.IntRemainder() constant_folding$after_inlining (after) 623 /// CHECK-NOT: DivZeroCheck 624 /// CHECK-NOT: Rem 625 IntRemainder()626 public static int IntRemainder() { 627 int a, b, c; 628 a = $inline$int(8); 629 b = $inline$int(3); 630 c = a % b; 631 return c; 632 } 633 634 /// CHECK-START: long Main.LongRemainder() constant_folding$after_inlining (before) 635 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8 636 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 637 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>] 638 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const8>>,<<Div0Chk>>] 639 /// CHECK-DAG: Return [<<Rem>>] 640 641 /// CHECK-START: long Main.LongRemainder() constant_folding$after_inlining (after) 642 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 643 /// CHECK-DAG: Return [<<Const2>>] 644 645 /// CHECK-START: long Main.LongRemainder() constant_folding$after_inlining (after) 646 /// CHECK-NOT: DivZeroCheck 647 /// CHECK-NOT: Rem 648 LongRemainder()649 public static long LongRemainder() { 650 long a, b, c; 651 a = $inline$long(8L); 652 b = $inline$long(3L); 653 c = a % b; 654 return c; 655 } 656 657 /// CHECK-START: float Main.FloatRemainder() constant_folding$after_inlining (before) 658 /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8 659 /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5 660 /// CHECK-DAG: <<Rem:f\d+>> Rem [<<Const8>>,<<Const2P5>>] 661 /// CHECK-DAG: Return [<<Rem>>] 662 663 /// CHECK-START: float Main.FloatRemainder() constant_folding$after_inlining (after) 664 /// CHECK-DAG: <<Const0P5:f\d+>> FloatConstant 0.5 665 /// CHECK-DAG: Return [<<Const0P5>>] 666 667 /// CHECK-START: float Main.FloatRemainder() constant_folding$after_inlining (after) 668 /// CHECK-NOT: Rem 669 FloatRemainder()670 public static float FloatRemainder() { 671 float a, b, c; 672 a = $inline$float(8F); 673 b = $inline$float(2.5F); 674 c = a % b; 675 return c; 676 } 677 678 /// CHECK-START: double Main.DoubleRemainder() constant_folding$after_inlining (before) 679 /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8 680 /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5 681 /// CHECK-DAG: <<Rem:d\d+>> Rem [<<Const8>>,<<Const2P5>>] 682 /// CHECK-DAG: Return [<<Rem>>] 683 684 /// CHECK-START: double Main.DoubleRemainder() constant_folding$after_inlining (after) 685 /// CHECK-DAG: <<Const0P5:d\d+>> DoubleConstant 0.5 686 /// CHECK-DAG: Return [<<Const0P5>>] 687 688 /// CHECK-START: double Main.DoubleRemainder() constant_folding$after_inlining (after) 689 /// CHECK-NOT: Rem 690 DoubleRemainder()691 public static double DoubleRemainder() { 692 double a, b, c; 693 a = $inline$double(8D); 694 b = $inline$double(2.5D); 695 c = a % b; 696 return c; 697 } 698 699 700 /** 701 * Exercise constant folding on left shift. 702 */ 703 704 /// CHECK-START: int Main.ShlIntLong() constant_folding$after_inlining (before) 705 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 706 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 707 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>] 708 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const1>>,<<TypeConv>>] 709 /// CHECK-DAG: Return [<<Shl>>] 710 711 /// CHECK-START: int Main.ShlIntLong() constant_folding$after_inlining (after) 712 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4 713 /// CHECK-DAG: Return [<<Const4>>] 714 715 /// CHECK-START: int Main.ShlIntLong() constant_folding$after_inlining (after) 716 /// CHECK-NOT: Shl 717 ShlIntLong()718 public static int ShlIntLong() { 719 int lhs = $inline$int(1); 720 long rhs = $inline$long(2L); 721 return lhs << rhs; 722 } 723 724 /// CHECK-START: long Main.ShlLongInt() constant_folding$after_inlining (before) 725 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 726 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 727 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const3L>>,<<Const2>>] 728 /// CHECK-DAG: Return [<<Shl>>] 729 730 /// CHECK-START: long Main.ShlLongInt() constant_folding$after_inlining (after) 731 /// CHECK-DAG: <<Const12L:j\d+>> LongConstant 12 732 /// CHECK-DAG: Return [<<Const12L>>] 733 734 /// CHECK-START: long Main.ShlLongInt() constant_folding$after_inlining (after) 735 /// CHECK-NOT: Shl 736 ShlLongInt()737 public static long ShlLongInt() { 738 long lhs = $inline$long(3L); 739 int rhs = $inline$int(2); 740 return lhs << rhs; 741 } 742 743 744 /** 745 * Exercise constant folding on right shift. 746 */ 747 748 /// CHECK-START: int Main.ShrIntLong() constant_folding$after_inlining (before) 749 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 750 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 751 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>] 752 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Const7>>,<<TypeConv>>] 753 /// CHECK-DAG: Return [<<Shr>>] 754 755 /// CHECK-START: int Main.ShrIntLong() constant_folding$after_inlining (after) 756 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 757 /// CHECK-DAG: Return [<<Const1>>] 758 759 /// CHECK-START: int Main.ShrIntLong() constant_folding$after_inlining (after) 760 /// CHECK-NOT: Shr 761 ShrIntLong()762 public static int ShrIntLong() { 763 int lhs = $inline$int(7); 764 long rhs = $inline$long(2L); 765 return lhs >> rhs; 766 } 767 768 /// CHECK-START: long Main.ShrLongInt() constant_folding$after_inlining (before) 769 /// CHECK-DAG: <<Const9L:j\d+>> LongConstant 9 770 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 771 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const9L>>,<<Const2>>] 772 /// CHECK-DAG: Return [<<Shr>>] 773 774 /// CHECK-START: long Main.ShrLongInt() constant_folding$after_inlining (after) 775 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 776 /// CHECK-DAG: Return [<<Const2L>>] 777 778 /// CHECK-START: long Main.ShrLongInt() constant_folding$after_inlining (after) 779 /// CHECK-NOT: Shr 780 ShrLongInt()781 public static long ShrLongInt() { 782 long lhs = $inline$long(9); 783 int rhs = $inline$int(2); 784 return lhs >> rhs; 785 } 786 787 788 /** 789 * Exercise constant folding on unsigned right shift. 790 */ 791 792 /// CHECK-START: int Main.UShrIntLong() constant_folding$after_inlining (before) 793 /// CHECK-DAG: <<ConstM7:i\d+>> IntConstant -7 794 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 795 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>] 796 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<ConstM7>>,<<TypeConv>>] 797 /// CHECK-DAG: Return [<<UShr>>] 798 799 /// CHECK-START: int Main.UShrIntLong() constant_folding$after_inlining (after) 800 /// CHECK-DAG: <<ConstRes:i\d+>> IntConstant 1073741822 801 /// CHECK-DAG: Return [<<ConstRes>>] 802 803 /// CHECK-START: int Main.UShrIntLong() constant_folding$after_inlining (after) 804 /// CHECK-NOT: UShr 805 UShrIntLong()806 public static int UShrIntLong() { 807 int lhs = $inline$int(-7); 808 long rhs = $inline$long(2L); 809 return lhs >>> rhs; 810 } 811 812 /// CHECK-START: long Main.UShrLongInt() constant_folding$after_inlining (before) 813 /// CHECK-DAG: <<ConstM9L:j\d+>> LongConstant -9 814 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 815 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<ConstM9L>>,<<Const2>>] 816 /// CHECK-DAG: Return [<<UShr>>] 817 818 /// CHECK-START: long Main.UShrLongInt() constant_folding$after_inlining (after) 819 /// CHECK-DAG: <<ConstRes:j\d+>> LongConstant 4611686018427387901 820 /// CHECK-DAG: Return [<<ConstRes>>] 821 822 /// CHECK-START: long Main.UShrLongInt() constant_folding$after_inlining (after) 823 /// CHECK-NOT: UShr 824 UShrLongInt()825 public static long UShrLongInt() { 826 long lhs = $inline$long(-9); 827 int rhs = $inline$int(2); 828 return lhs >>> rhs; 829 } 830 831 832 /** 833 * Exercise constant folding on logical and. 834 */ 835 836 /// CHECK-START: long Main.AndIntLong() constant_folding$after_inlining (before) 837 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 838 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 839 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] 840 /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const3L>>] 841 /// CHECK-DAG: Return [<<And>>] 842 843 /// CHECK-START: long Main.AndIntLong() constant_folding$after_inlining (after) 844 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 845 /// CHECK-DAG: Return [<<Const2>>] 846 847 /// CHECK-START: long Main.AndIntLong() constant_folding$after_inlining (after) 848 /// CHECK-NOT: And 849 AndIntLong()850 public static long AndIntLong() { 851 int lhs = $inline$int(10); 852 long rhs = $inline$long(3L); 853 return lhs & rhs; 854 } 855 856 /// CHECK-START: long Main.AndLongInt() constant_folding$after_inlining (before) 857 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 858 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 859 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] 860 /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const10L>>] 861 /// CHECK-DAG: Return [<<And>>] 862 863 /// CHECK-START: long Main.AndLongInt() constant_folding$after_inlining (after) 864 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 865 /// CHECK-DAG: Return [<<Const2>>] 866 867 /// CHECK-START: long Main.AndLongInt() constant_folding$after_inlining (after) 868 /// CHECK-NOT: And 869 AndLongInt()870 public static long AndLongInt() { 871 long lhs = $inline$long(10L); 872 int rhs = $inline$int(3); 873 return lhs & rhs; 874 } 875 876 877 /** 878 * Exercise constant folding on logical or. 879 */ 880 881 /// CHECK-START: long Main.OrIntLong() constant_folding$after_inlining (before) 882 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 883 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 884 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] 885 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const3L>>] 886 /// CHECK-DAG: Return [<<Or>>] 887 888 /// CHECK-START: long Main.OrIntLong() constant_folding$after_inlining (after) 889 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11 890 /// CHECK-DAG: Return [<<Const11>>] 891 892 /// CHECK-START: long Main.OrIntLong() constant_folding$after_inlining (after) 893 /// CHECK-NOT: Or 894 OrIntLong()895 public static long OrIntLong() { 896 int lhs = $inline$int(10); 897 long rhs = $inline$long(3L); 898 return lhs | rhs; 899 } 900 901 /// CHECK-START: long Main.OrLongInt() constant_folding$after_inlining (before) 902 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 903 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 904 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] 905 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const10L>>] 906 /// CHECK-DAG: Return [<<Or>>] 907 908 /// CHECK-START: long Main.OrLongInt() constant_folding$after_inlining (after) 909 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11 910 /// CHECK-DAG: Return [<<Const11>>] 911 912 /// CHECK-START: long Main.OrLongInt() constant_folding$after_inlining (after) 913 /// CHECK-NOT: Or 914 OrLongInt()915 public static long OrLongInt() { 916 long lhs = $inline$long(10L); 917 int rhs = $inline$int(3); 918 return lhs | rhs; 919 } 920 921 922 /** 923 * Exercise constant folding on logical exclusive or. 924 */ 925 926 /// CHECK-START: long Main.XorIntLong() constant_folding$after_inlining (before) 927 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 928 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 929 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] 930 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const3L>>] 931 /// CHECK-DAG: Return [<<Xor>>] 932 933 /// CHECK-START: long Main.XorIntLong() constant_folding$after_inlining (after) 934 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9 935 /// CHECK-DAG: Return [<<Const9>>] 936 937 /// CHECK-START: long Main.XorIntLong() constant_folding$after_inlining (after) 938 /// CHECK-NOT: Xor 939 XorIntLong()940 public static long XorIntLong() { 941 int lhs = $inline$int(10); 942 long rhs = $inline$long(3L); 943 return lhs ^ rhs; 944 } 945 946 /// CHECK-START: long Main.XorLongInt() constant_folding$after_inlining (before) 947 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 948 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 949 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] 950 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const10L>>] 951 /// CHECK-DAG: Return [<<Xor>>] 952 953 /// CHECK-START: long Main.XorLongInt() constant_folding$after_inlining (after) 954 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9 955 /// CHECK-DAG: Return [<<Const9>>] 956 957 /// CHECK-START: long Main.XorLongInt() constant_folding$after_inlining (after) 958 /// CHECK-NOT: Xor 959 XorLongInt()960 public static long XorLongInt() { 961 long lhs = $inline$long(10L); 962 int rhs = $inline$int(3); 963 return lhs ^ rhs; 964 } 965 966 967 /** 968 * Exercise constant folding on constant (static) condition. 969 */ 970 971 /// CHECK-START: int Main.StaticCondition() constant_folding$after_inlining (before) 972 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 973 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 974 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<Const7>>,<<Const2>>] 975 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Cond>>] 976 977 /// CHECK-START: int Main.StaticCondition() constant_folding$after_inlining (after) 978 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 979 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Const1>>] 980 981 /// CHECK-START: int Main.StaticCondition() constant_folding$after_inlining (after) 982 /// CHECK-NOT: GreaterThanOrEqual 983 StaticCondition()984 public static int StaticCondition() { 985 int a, b, c; 986 a = $inline$int(7); 987 b = $inline$int(2); 988 if (a < b) 989 c = a + b; 990 else 991 c = a - b; 992 return c; 993 } 994 995 996 /** 997 * Exercise constant folding on constant (static) condition for null references. 998 */ 999 1000 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (before) 1001 /// CHECK-DAG: <<Null:l\d+>> NullConstant 1002 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Null>>,<<Null>>] 1003 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Cond>>] 1004 1005 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after) 1006 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1007 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Const0>>] 1008 1009 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after) 1010 /// CHECK-NOT: NotEqual 1011 getNull()1012 private static Object getNull() { 1013 return null; 1014 } 1015 StaticConditionNulls()1016 public static int StaticConditionNulls() { 1017 Object a = getNull(); 1018 Object b = getNull(); 1019 return (a == b) ? 5 : 2; 1020 } 1021 1022 1023 /** 1024 * Exercise constant folding on a program with condition 1025 * (i.e. jumps) leading to the creation of many blocks. 1026 * 1027 * The intent of this test is to ensure that all constant expressions 1028 * are actually evaluated at compile-time, thanks to the reverse 1029 * (forward) post-order traversal of the the dominator tree. 1030 */ 1031 1032 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding$after_inlining (before) 1033 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue 1034 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 1035 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 1036 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const5>>,<<Const2>>] 1037 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const2>>] 1038 /// CHECK-DAG: <<Phi:i\d+>> Select [<<Sub>>,<<Add>>,<<Cond>>] 1039 /// CHECK-DAG: Return [<<Phi>>] 1040 1041 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding$after_inlining (after) 1042 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue 1043 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 1044 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 1045 /// CHECK-DAG: <<Phi:i\d+>> Select [<<Const3>>,<<Const7>>,<<Cond>>] 1046 /// CHECK-DAG: Return [<<Phi>>] 1047 1048 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding$after_inlining (after) 1049 /// CHECK-NOT: Add 1050 /// CHECK-NOT: Sub 1051 JumpsAndConditionals(boolean cond)1052 public static int JumpsAndConditionals(boolean cond) { 1053 int a, b, c; 1054 a = $inline$int(5); 1055 b = $inline$int(2); 1056 if (cond) 1057 c = a + b; 1058 else 1059 c = a - b; 1060 return c; 1061 } 1062 1063 1064 /** 1065 * Test optimizations of arithmetic identities yielding a constant result. 1066 */ 1067 1068 /// CHECK-START: int Main.And0(int) constant_folding (before) 1069 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1070 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1071 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const0>>] 1072 /// CHECK-DAG: Return [<<And>>] 1073 1074 /// CHECK-START: int Main.And0(int) constant_folding (after) 1075 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1076 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1077 /// CHECK-DAG: Return [<<Const0>>] 1078 1079 /// CHECK-START: int Main.And0(int) constant_folding (after) 1080 /// CHECK-NOT: And 1081 And0(int arg)1082 public static int And0(int arg) { 1083 return arg & 0; 1084 } 1085 1086 /// CHECK-START: long Main.Mul0(long) constant_folding (before) 1087 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1088 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1089 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const0>>,<<Arg>>] 1090 /// CHECK-DAG: Return [<<Mul>>] 1091 1092 /// CHECK-START: long Main.Mul0(long) constant_folding (after) 1093 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1094 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1095 /// CHECK-DAG: Return [<<Const0>>] 1096 1097 /// CHECK-START: long Main.Mul0(long) constant_folding (after) 1098 /// CHECK-NOT: Mul 1099 Mul0(long arg)1100 public static long Mul0(long arg) { 1101 return arg * 0; 1102 } 1103 1104 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before) 1105 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1106 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 1107 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<ConstF>>] 1108 /// CHECK-DAG: Return [<<Or>>] 1109 1110 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after) 1111 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 1112 /// CHECK-DAG: Return [<<ConstF>>] 1113 1114 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after) 1115 /// CHECK-NOT: Or 1116 OrAllOnes(int arg)1117 public static int OrAllOnes(int arg) { 1118 return arg | -1; 1119 } 1120 1121 /// CHECK-START: long Main.Rem0(long) constant_folding (before) 1122 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1123 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1124 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Arg>>] 1125 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const0>>,<<DivZeroCheck>>] 1126 /// CHECK-DAG: Return [<<Rem>>] 1127 1128 /// CHECK-START: long Main.Rem0(long) constant_folding (after) 1129 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1130 /// CHECK-DAG: Return [<<Const0>>] 1131 1132 /// CHECK-START: long Main.Rem0(long) constant_folding (after) 1133 /// CHECK-NOT: Rem 1134 Rem0(long arg)1135 public static long Rem0(long arg) { 1136 return 0 % arg; 1137 } 1138 1139 /// CHECK-START: int Main.Rem1(int) constant_folding (before) 1140 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1141 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1142 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<Const1>>] 1143 /// CHECK-DAG: Return [<<Rem>>] 1144 1145 /// CHECK-START: int Main.Rem1(int) constant_folding (after) 1146 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1147 /// CHECK-DAG: Return [<<Const0>>] 1148 1149 /// CHECK-START: int Main.Rem1(int) constant_folding (after) 1150 /// CHECK-NOT: Rem 1151 Rem1(int arg)1152 public static int Rem1(int arg) { 1153 return arg % 1; 1154 } 1155 1156 /// CHECK-START: long Main.RemN1(long) constant_folding (before) 1157 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1158 /// CHECK-DAG: <<ConstN1:j\d+>> LongConstant -1 1159 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<ConstN1>>] 1160 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>] 1161 /// CHECK-DAG: Return [<<Rem>>] 1162 1163 /// CHECK-START: long Main.RemN1(long) constant_folding (after) 1164 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1165 /// CHECK-DAG: Return [<<Const0>>] 1166 1167 /// CHECK-START: long Main.RemN1(long) constant_folding (after) 1168 /// CHECK-NOT: Rem 1169 RemN1(long arg)1170 public static long RemN1(long arg) { 1171 return arg % -1; 1172 } 1173 1174 /// CHECK-START: int Main.Shl0(int) constant_folding (before) 1175 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1176 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1177 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const0>>,<<Arg>>] 1178 /// CHECK-DAG: Return [<<Shl>>] 1179 1180 /// CHECK-START: int Main.Shl0(int) constant_folding (after) 1181 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1182 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1183 /// CHECK-DAG: Return [<<Const0>>] 1184 1185 /// CHECK-START: int Main.Shl0(int) constant_folding (after) 1186 /// CHECK-NOT: Shl 1187 Shl0(int arg)1188 public static int Shl0(int arg) { 1189 return 0 << arg; 1190 } 1191 1192 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (before) 1193 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1194 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0 1195 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const0L>>,<<Arg>>] 1196 /// CHECK-DAG: Return [<<Shl>>] 1197 1198 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after) 1199 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1200 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0 1201 /// CHECK-DAG: Return [<<Const0L>>] 1202 1203 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after) 1204 /// CHECK-NOT: Shl 1205 ShlLong0WithInt(int arg)1206 public static long ShlLong0WithInt(int arg) { 1207 long long_zero = 0; 1208 return long_zero << arg; 1209 } 1210 1211 /// CHECK-START: long Main.Shr0(int) constant_folding (before) 1212 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1213 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1214 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const0>>,<<Arg>>] 1215 /// CHECK-DAG: Return [<<Shr>>] 1216 1217 /// CHECK-START: long Main.Shr0(int) constant_folding (after) 1218 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1219 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1220 /// CHECK-DAG: Return [<<Const0>>] 1221 1222 /// CHECK-START: long Main.Shr0(int) constant_folding (after) 1223 /// CHECK-NOT: Shr 1224 Shr0(int arg)1225 public static long Shr0(int arg) { 1226 return (long)0 >> arg; 1227 } 1228 1229 /// CHECK-START: long Main.SubSameLong(long) constant_folding (before) 1230 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1231 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Arg>>] 1232 /// CHECK-DAG: Return [<<Sub>>] 1233 1234 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after) 1235 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1236 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1237 /// CHECK-DAG: Return [<<Const0>>] 1238 1239 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after) 1240 /// CHECK-NOT: Sub 1241 SubSameLong(long arg)1242 public static long SubSameLong(long arg) { 1243 return arg - arg; 1244 } 1245 1246 /// CHECK-START: int Main.UShr0(int) constant_folding (before) 1247 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1248 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1249 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Const0>>,<<Arg>>] 1250 /// CHECK-DAG: Return [<<UShr>>] 1251 1252 /// CHECK-START: int Main.UShr0(int) constant_folding (after) 1253 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1254 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1255 /// CHECK-DAG: Return [<<Const0>>] 1256 1257 /// CHECK-START: int Main.UShr0(int) constant_folding (after) 1258 /// CHECK-NOT: UShr 1259 UShr0(int arg)1260 public static int UShr0(int arg) { 1261 return 0 >>> arg; 1262 } 1263 1264 /// CHECK-START: int Main.XorSameInt(int) constant_folding (before) 1265 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1266 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Arg>>] 1267 /// CHECK-DAG: Return [<<Xor>>] 1268 1269 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after) 1270 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1271 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1272 /// CHECK-DAG: Return [<<Const0>>] 1273 1274 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after) 1275 /// CHECK-NOT: Xor 1276 XorSameInt(int arg)1277 public static int XorSameInt(int arg) { 1278 return arg ^ arg; 1279 } 1280 1281 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before) 1282 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1283 /// CHECK-DAG: <<ConstNan:f\d+>> FloatConstant nan 1284 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1285 /// CHECK-DAG: IntConstant 1 1286 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>] 1287 /// CHECK-DAG: <<Le:z\d+>> LessThanOrEqual [<<Cmp>>,<<Const0>>] 1288 /// CHECK-DAG: If [<<Le>>] 1289 1290 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after) 1291 /// CHECK-DAG: ParameterValue 1292 /// CHECK-DAG: FloatConstant nan 1293 /// CHECK-DAG: IntConstant 0 1294 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1295 /// CHECK-DAG: If [<<Const1>>] 1296 1297 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after) 1298 /// CHECK-NOT: Compare 1299 /// CHECK-NOT: LessThanOrEqual 1300 CmpFloatGreaterThanNaN(float arg)1301 public static boolean CmpFloatGreaterThanNaN(float arg) { 1302 return arg > Float.NaN; 1303 } 1304 1305 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before) 1306 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue 1307 /// CHECK-DAG: <<ConstNan:d\d+>> DoubleConstant nan 1308 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1309 /// CHECK-DAG: IntConstant 1 1310 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>] 1311 /// CHECK-DAG: <<Ge:z\d+>> GreaterThanOrEqual [<<Cmp>>,<<Const0>>] 1312 /// CHECK-DAG: If [<<Ge>>] 1313 1314 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after) 1315 /// CHECK-DAG: ParameterValue 1316 /// CHECK-DAG: DoubleConstant nan 1317 /// CHECK-DAG: IntConstant 0 1318 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1319 /// CHECK-DAG: If [<<Const1>>] 1320 1321 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after) 1322 /// CHECK-NOT: Compare 1323 /// CHECK-NOT: GreaterThanOrEqual 1324 CmpDoubleLessThanNaN(double arg)1325 public static boolean CmpDoubleLessThanNaN(double arg) { 1326 return arg < Double.NaN; 1327 } 1328 1329 1330 /** 1331 * Test optimizations of comparisons with null yielding a constant result. 1332 */ 1333 1334 /// CHECK-START: boolean Main.ConstStringEqualsNull() constant_folding$after_inlining (before) 1335 /// CHECK-DAG: <<ConstStr:l\d+>> LoadString 1336 /// CHECK-DAG: <<Null:l\d+>> NullConstant 1337 /// CHECK-DAG: <<Eq:z\d+>> Equal [<<ConstStr>>,<<Null>>] 1338 /// CHECK-DAG: If [<<Eq>>] 1339 1340 /// CHECK-START: boolean Main.ConstStringEqualsNull() constant_folding$after_inlining (after) 1341 /// CHECK-DAG: <<False:i\d+>> IntConstant 0 1342 /// CHECK-DAG: If [<<False>>] 1343 1344 /// CHECK-START: boolean Main.ConstStringEqualsNull() constant_folding$after_inlining (after) 1345 /// CHECK-NOT: Equal 1346 ConstStringEqualsNull()1347 public static boolean ConstStringEqualsNull() { 1348 // Due to Jack emitting code using the opposite condition, use != to generate Equal. 1349 if ($inline$ConstString() != null) { 1350 return false; 1351 } else { 1352 return true; 1353 } 1354 } 1355 1356 /// CHECK-START: boolean Main.ConstStringNotEqualsNull() constant_folding$after_inlining (before) 1357 /// CHECK-DAG: <<ConstStr:l\d+>> LoadString 1358 /// CHECK-DAG: <<Null:l\d+>> NullConstant 1359 /// CHECK-DAG: <<Ne:z\d+>> NotEqual [<<ConstStr>>,<<Null>>] 1360 /// CHECK-DAG: If [<<Ne>>] 1361 1362 /// CHECK-START: boolean Main.ConstStringNotEqualsNull() constant_folding$after_inlining (after) 1363 /// CHECK-DAG: <<True:i\d+>> IntConstant 1 1364 /// CHECK-DAG: If [<<True>>] 1365 1366 /// CHECK-START: boolean Main.ConstStringNotEqualsNull() constant_folding$after_inlining (after) 1367 /// CHECK-NOT: NotEqual 1368 ConstStringNotEqualsNull()1369 public static boolean ConstStringNotEqualsNull() { 1370 // Due to Jack emitting code using the opposite condition, use == to generate NotEqual. 1371 if ($inline$ConstString() == null) { 1372 return false; 1373 } else { 1374 return true; 1375 } 1376 } 1377 $inline$ConstString()1378 public static String $inline$ConstString() { 1379 return ""; 1380 } 1381 1382 /** 1383 * Exercise constant folding on type conversions. 1384 */ 1385 1386 /// CHECK-START: int Main.ReturnInt33() constant_folding$after_inlining (before) 1387 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33 1388 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>] 1389 /// CHECK-DAG: Return [<<Convert>>] 1390 1391 /// CHECK-START: int Main.ReturnInt33() constant_folding$after_inlining (after) 1392 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1393 /// CHECK-DAG: Return [<<Const33>>] 1394 1395 /// CHECK-START: int Main.ReturnInt33() constant_folding$after_inlining (after) 1396 /// CHECK-NOT: TypeConversion 1397 ReturnInt33()1398 public static int ReturnInt33() { 1399 long imm = $inline$long(33L); 1400 return (int) imm; 1401 } 1402 1403 /// CHECK-START: int Main.ReturnIntMax() constant_folding$after_inlining (before) 1404 /// CHECK-DAG: <<ConstMax:f\d+>> FloatConstant 1e+34 1405 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstMax>>] 1406 /// CHECK-DAG: Return [<<Convert>>] 1407 1408 /// CHECK-START: int Main.ReturnIntMax() constant_folding$after_inlining (after) 1409 /// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647 1410 /// CHECK-DAG: Return [<<ConstMax>>] 1411 1412 /// CHECK-START: int Main.ReturnIntMax() constant_folding$after_inlining (after) 1413 /// CHECK-NOT: TypeConversion 1414 ReturnIntMax()1415 public static int ReturnIntMax() { 1416 float imm = $inline$float(1.0e34f); 1417 return (int) imm; 1418 } 1419 1420 /// CHECK-START: int Main.ReturnInt0() constant_folding$after_inlining (before) 1421 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan 1422 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstNaN>>] 1423 /// CHECK-DAG: Return [<<Convert>>] 1424 1425 /// CHECK-START: int Main.ReturnInt0() constant_folding$after_inlining (after) 1426 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1427 /// CHECK-DAG: Return [<<Const0>>] 1428 1429 /// CHECK-START: int Main.ReturnInt0() constant_folding$after_inlining (after) 1430 /// CHECK-NOT: TypeConversion 1431 ReturnInt0()1432 public static int ReturnInt0() { 1433 double imm = $inline$double(Double.NaN); 1434 return (int) imm; 1435 } 1436 1437 /// CHECK-START: long Main.ReturnLong33() constant_folding$after_inlining (before) 1438 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1439 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const33>>] 1440 /// CHECK-DAG: Return [<<Convert>>] 1441 1442 /// CHECK-START: long Main.ReturnLong33() constant_folding$after_inlining (after) 1443 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33 1444 /// CHECK-DAG: Return [<<Const33>>] 1445 1446 /// CHECK-START: long Main.ReturnLong33() constant_folding$after_inlining (after) 1447 /// CHECK-NOT: TypeConversion 1448 ReturnLong33()1449 public static long ReturnLong33() { 1450 int imm = $inline$int(33); 1451 return (long) imm; 1452 } 1453 1454 /// CHECK-START: long Main.ReturnLong34() constant_folding$after_inlining (before) 1455 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34 1456 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const34>>] 1457 /// CHECK-DAG: Return [<<Convert>>] 1458 1459 /// CHECK-START: long Main.ReturnLong34() constant_folding$after_inlining (after) 1460 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 1461 /// CHECK-DAG: Return [<<Const34>>] 1462 1463 /// CHECK-START: long Main.ReturnLong34() constant_folding$after_inlining (after) 1464 /// CHECK-NOT: TypeConversion 1465 ReturnLong34()1466 public static long ReturnLong34() { 1467 float imm = $inline$float(34.0f); 1468 return (long) imm; 1469 } 1470 1471 /// CHECK-START: long Main.ReturnLong0() constant_folding$after_inlining (before) 1472 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan 1473 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<ConstNaN>>] 1474 /// CHECK-DAG: Return [<<Convert>>] 1475 1476 /// CHECK-START: long Main.ReturnLong0() constant_folding$after_inlining (after) 1477 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1478 /// CHECK-DAG: Return [<<Const0>>] 1479 1480 /// CHECK-START: long Main.ReturnLong0() constant_folding$after_inlining (after) 1481 /// CHECK-NOT: TypeConversion 1482 ReturnLong0()1483 public static long ReturnLong0() { 1484 double imm = $inline$double(-Double.NaN); 1485 return (long) imm; 1486 } 1487 1488 /// CHECK-START: float Main.ReturnFloat33() constant_folding$after_inlining (before) 1489 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1490 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const33>>] 1491 /// CHECK-DAG: Return [<<Convert>>] 1492 1493 /// CHECK-START: float Main.ReturnFloat33() constant_folding$after_inlining (after) 1494 /// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33 1495 /// CHECK-DAG: Return [<<Const33>>] 1496 1497 /// CHECK-START: float Main.ReturnFloat33() constant_folding$after_inlining (after) 1498 /// CHECK-NOT: TypeConversion 1499 ReturnFloat33()1500 public static float ReturnFloat33() { 1501 int imm = $inline$int(33); 1502 return (float) imm; 1503 } 1504 1505 /// CHECK-START: float Main.ReturnFloat34() constant_folding$after_inlining (before) 1506 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 1507 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const34>>] 1508 /// CHECK-DAG: Return [<<Convert>>] 1509 1510 /// CHECK-START: float Main.ReturnFloat34() constant_folding$after_inlining (after) 1511 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34 1512 /// CHECK-DAG: Return [<<Const34>>] 1513 1514 /// CHECK-START: float Main.ReturnFloat34() constant_folding$after_inlining (after) 1515 /// CHECK-NOT: TypeConversion 1516 ReturnFloat34()1517 public static float ReturnFloat34() { 1518 long imm = $inline$long(34L); 1519 return (float) imm; 1520 } 1521 1522 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding$after_inlining (before) 1523 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25 1524 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const>>] 1525 /// CHECK-DAG: Return [<<Convert>>] 1526 1527 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding$after_inlining (after) 1528 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25 1529 /// CHECK-DAG: Return [<<Const>>] 1530 1531 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding$after_inlining (after) 1532 /// CHECK-NOT: TypeConversion 1533 ReturnFloat99P25()1534 public static float ReturnFloat99P25() { 1535 double imm = $inline$double(99.25); 1536 return (float) imm; 1537 } 1538 1539 /// CHECK-START: double Main.ReturnDouble33() constant_folding$after_inlining (before) 1540 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1541 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const33>>] 1542 /// CHECK-DAG: Return [<<Convert>>] 1543 1544 /// CHECK-START: double Main.ReturnDouble33() constant_folding$after_inlining (after) 1545 /// CHECK-DAG: <<Const33:d\d+>> DoubleConstant 33 1546 /// CHECK-DAG: Return [<<Const33>>] 1547 ReturnDouble33()1548 public static double ReturnDouble33() { 1549 int imm = $inline$int(33); 1550 return (double) imm; 1551 } 1552 1553 /// CHECK-START: double Main.ReturnDouble34() constant_folding$after_inlining (before) 1554 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 1555 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const34>>] 1556 /// CHECK-DAG: Return [<<Convert>>] 1557 1558 /// CHECK-START: double Main.ReturnDouble34() constant_folding$after_inlining (after) 1559 /// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34 1560 /// CHECK-DAG: Return [<<Const34>>] 1561 1562 /// CHECK-START: double Main.ReturnDouble34() constant_folding$after_inlining (after) 1563 /// CHECK-NOT: TypeConversion 1564 ReturnDouble34()1565 public static double ReturnDouble34() { 1566 long imm = $inline$long(34L); 1567 return (double) imm; 1568 } 1569 1570 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding$after_inlining (before) 1571 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25 1572 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const>>] 1573 /// CHECK-DAG: Return [<<Convert>>] 1574 1575 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding$after_inlining (after) 1576 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25 1577 /// CHECK-DAG: Return [<<Const>>] 1578 1579 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding$after_inlining (after) 1580 /// CHECK-NOT: TypeConversion 1581 ReturnDouble99P25()1582 public static double ReturnDouble99P25() { 1583 float imm = $inline$float(99.25f); 1584 return (double) imm; 1585 } 1586 1587 main(String[] args)1588 public static void main(String[] args) throws Exception { 1589 assertIntEquals(-42, IntNegation()); 1590 assertLongEquals(-42L, LongNegation()); 1591 assertFloatEquals(-42F, FloatNegation()); 1592 assertDoubleEquals(-42D, DoubleNegation()); 1593 1594 assertIntEquals(3, IntAddition1()); 1595 assertIntEquals(14, IntAddition2()); 1596 assertLongEquals(3L, LongAddition()); 1597 assertFloatEquals(3F, FloatAddition()); 1598 assertDoubleEquals(3D, DoubleAddition()); 1599 1600 assertIntEquals(4, IntSubtraction()); 1601 assertLongEquals(4L, LongSubtraction()); 1602 assertFloatEquals(4F, FloatSubtraction()); 1603 assertDoubleEquals(4D, DoubleSubtraction()); 1604 1605 assertIntEquals(21, IntMultiplication()); 1606 assertLongEquals(21L, LongMultiplication()); 1607 assertFloatEquals(21F, FloatMultiplication()); 1608 assertDoubleEquals(21D, DoubleMultiplication()); 1609 1610 assertIntEquals(2, IntDivision()); 1611 assertLongEquals(2L, LongDivision()); 1612 assertFloatEquals(3.2F, FloatDivision()); 1613 assertDoubleEquals(3.2D, DoubleDivision()); 1614 1615 assertIntEquals(2, IntRemainder()); 1616 assertLongEquals(2L, LongRemainder()); 1617 assertFloatEquals(0.5F, FloatRemainder()); 1618 assertDoubleEquals(0.5D, DoubleRemainder()); 1619 1620 assertIntEquals(4, ShlIntLong()); 1621 assertLongEquals(12L, ShlLongInt()); 1622 1623 assertIntEquals(1, ShrIntLong()); 1624 assertLongEquals(2L, ShrLongInt()); 1625 1626 assertIntEquals(1073741822, UShrIntLong()); 1627 assertLongEquals(4611686018427387901L, UShrLongInt()); 1628 1629 assertLongEquals(2, AndIntLong()); 1630 assertLongEquals(2, AndLongInt()); 1631 1632 assertLongEquals(11, OrIntLong()); 1633 assertLongEquals(11, OrLongInt()); 1634 1635 assertLongEquals(9, XorIntLong()); 1636 assertLongEquals(9, XorLongInt()); 1637 1638 assertIntEquals(5, StaticCondition()); 1639 assertIntEquals(5, StaticConditionNulls()); 1640 1641 assertIntEquals(7, JumpsAndConditionals(true)); 1642 assertIntEquals(3, JumpsAndConditionals(false)); 1643 1644 int arbitrary = 123456; // Value chosen arbitrarily. 1645 1646 assertIntEquals(0, And0(arbitrary)); 1647 assertLongEquals(0, Mul0(arbitrary)); 1648 assertIntEquals(-1, OrAllOnes(arbitrary)); 1649 assertLongEquals(0, Rem0(arbitrary)); 1650 assertIntEquals(0, Rem1(arbitrary)); 1651 assertLongEquals(0, RemN1(arbitrary)); 1652 assertIntEquals(0, Shl0(arbitrary)); 1653 assertLongEquals(0, ShlLong0WithInt(arbitrary)); 1654 assertLongEquals(0, Shr0(arbitrary)); 1655 assertLongEquals(0, SubSameLong(arbitrary)); 1656 assertIntEquals(0, UShr0(arbitrary)); 1657 assertIntEquals(0, XorSameInt(arbitrary)); 1658 1659 assertFalse(CmpFloatGreaterThanNaN(arbitrary)); 1660 assertFalse(CmpDoubleLessThanNaN(arbitrary)); 1661 1662 assertFalse(ConstStringEqualsNull()); 1663 assertTrue(ConstStringNotEqualsNull()); 1664 1665 Main main = new Main(); 1666 assertIntEquals(1, main.smaliCmpLongConstants()); 1667 assertIntEquals(-1, main.smaliCmpGtFloatConstants()); 1668 assertIntEquals(-1, main.smaliCmpLtFloatConstants()); 1669 assertIntEquals(-1, main.smaliCmpGtDoubleConstants()); 1670 assertIntEquals(-1, main.smaliCmpLtDoubleConstants()); 1671 1672 assertIntEquals(0, main.smaliCmpLongSameConstant()); 1673 assertIntEquals(0, main.smaliCmpGtFloatSameConstant()); 1674 assertIntEquals(0, main.smaliCmpLtFloatSameConstant()); 1675 assertIntEquals(0, main.smaliCmpGtDoubleSameConstant()); 1676 assertIntEquals(0, main.smaliCmpLtDoubleSameConstant()); 1677 1678 assertIntEquals(1, main.smaliCmpGtFloatConstantWithNaN()); 1679 assertIntEquals(-1, main.smaliCmpLtFloatConstantWithNaN()); 1680 assertIntEquals(1, main.smaliCmpGtDoubleConstantWithNaN()); 1681 assertIntEquals(-1, main.smaliCmpLtDoubleConstantWithNaN()); 1682 1683 assertIntEquals(33, ReturnInt33()); 1684 assertIntEquals(2147483647, ReturnIntMax()); 1685 assertIntEquals(0, ReturnInt0()); 1686 1687 assertLongEquals(33, ReturnLong33()); 1688 assertLongEquals(34, ReturnLong34()); 1689 assertLongEquals(0, ReturnLong0()); 1690 1691 assertFloatEquals(33, ReturnFloat33()); 1692 assertFloatEquals(34, ReturnFloat34()); 1693 assertFloatEquals(99.25f, ReturnFloat99P25()); 1694 1695 assertDoubleEquals(33, ReturnDouble33()); 1696 assertDoubleEquals(34, ReturnDouble34()); 1697 assertDoubleEquals(99.25, ReturnDouble99P25()); 1698 } 1699 Main()1700 Main() throws ClassNotFoundException { 1701 testCmp = Class.forName("TestCmp"); 1702 } 1703 1704 private Class<?> testCmp; 1705 } 1706