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