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