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 868 /** 869 * Exercise constant folding on logical or. 870 */ 871 872 /// CHECK-START: long Main.OrIntLong() constant_folding (before) 873 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 874 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 875 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] 876 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const3L>>] 877 /// CHECK-DAG: Return [<<Or>>] 878 879 /// CHECK-START: long Main.OrIntLong() constant_folding (after) 880 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11 881 /// CHECK-DAG: Return [<<Const11>>] 882 883 /// CHECK-START: long Main.OrIntLong() constant_folding (after) 884 /// CHECK-NOT: Or 885 OrIntLong()886 public static long OrIntLong() { 887 int lhs = 10; 888 long rhs = 3; 889 return lhs | rhs; 890 } 891 892 /// CHECK-START: long Main.OrLongInt() constant_folding (before) 893 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 894 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 895 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] 896 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const10L>>] 897 /// CHECK-DAG: Return [<<Or>>] 898 899 /// CHECK-START: long Main.OrLongInt() constant_folding (after) 900 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11 901 /// CHECK-DAG: Return [<<Const11>>] 902 903 /// CHECK-START: long Main.OrLongInt() constant_folding (after) 904 /// CHECK-NOT: Or 905 OrLongInt()906 public static long OrLongInt() { 907 long lhs = 10; 908 int rhs = 3; 909 return lhs | rhs; 910 } 911 912 913 /** 914 * Exercise constant folding on logical exclusive or. 915 */ 916 917 /// CHECK-START: long Main.XorIntLong() constant_folding (before) 918 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 919 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 920 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] 921 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const3L>>] 922 /// CHECK-DAG: Return [<<Xor>>] 923 924 /// CHECK-START: long Main.XorIntLong() constant_folding (after) 925 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9 926 /// CHECK-DAG: Return [<<Const9>>] 927 928 /// CHECK-START: long Main.XorIntLong() constant_folding (after) 929 /// CHECK-NOT: Xor 930 XorIntLong()931 public static long XorIntLong() { 932 int lhs = 10; 933 long rhs = 3; 934 return lhs ^ rhs; 935 } 936 937 /// CHECK-START: long Main.XorLongInt() constant_folding (before) 938 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 939 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 940 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] 941 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const10L>>] 942 /// CHECK-DAG: Return [<<Xor>>] 943 944 /// CHECK-START: long Main.XorLongInt() constant_folding (after) 945 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9 946 /// CHECK-DAG: Return [<<Const9>>] 947 948 /// CHECK-START: long Main.XorLongInt() constant_folding (after) 949 /// CHECK-NOT: Xor 950 XorLongInt()951 public static long XorLongInt() { 952 long lhs = 10; 953 int rhs = 3; 954 return lhs ^ rhs; 955 } 956 957 958 /** 959 * Exercise constant folding on constant (static) condition. 960 */ 961 962 /// CHECK-START: int Main.StaticCondition() constant_folding (before) 963 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 964 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 965 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<Const7>>,<<Const2>>] 966 /// CHECK-DAG: If [<<Cond>>] 967 968 /// CHECK-START: int Main.StaticCondition() constant_folding (after) 969 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 970 /// CHECK-DAG: If [<<Const1>>] 971 972 /// CHECK-START: int Main.StaticCondition() constant_folding (after) 973 /// CHECK-NOT: GreaterThanOrEqual 974 StaticCondition()975 public static int StaticCondition() { 976 int a, b, c; 977 a = 7; 978 b = 2; 979 if (a < b) 980 c = a + b; 981 else 982 c = a - b; 983 return c; 984 } 985 986 987 /** 988 * Exercise constant folding on constant (static) condition for null references. 989 */ 990 991 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (before) 992 /// CHECK-DAG: <<Null:l\d+>> NullConstant 993 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Null>>,<<Null>>] 994 /// CHECK-DAG: If [<<Cond>>] 995 996 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after) 997 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 998 /// CHECK-DAG: If [<<Const0>>] 999 1000 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after) 1001 /// CHECK-NOT: NotEqual 1002 1003 /// CHECK-START: int Main.StaticConditionNulls() dead_code_elimination$after_inlining (before) 1004 /// CHECK-DAG: <<Phi:i\d+>> Phi 1005 /// CHECK-DAG: Return [<<Phi>>] 1006 // 1007 /// CHECK-START: int Main.StaticConditionNulls() dead_code_elimination$after_inlining (after) 1008 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 1009 /// CHECK-DAG: Return [<<Const5>>] 1010 getNull()1011 private static Object getNull() { 1012 return null; 1013 } 1014 StaticConditionNulls()1015 public static int StaticConditionNulls() { 1016 Object a = getNull(); 1017 Object b = getNull(); 1018 return (a == b) ? 5 : 2; 1019 } 1020 1021 1022 /** 1023 * Exercise constant folding on a program with condition 1024 * (i.e. jumps) leading to the creation of many blocks. 1025 * 1026 * The intent of this test is to ensure that all constant expressions 1027 * are actually evaluated at compile-time, thanks to the reverse 1028 * (forward) post-order traversal of the the dominator tree. 1029 */ 1030 1031 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (before) 1032 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 1033 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 1034 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const5>>,<<Const2>>] 1035 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const2>>] 1036 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Add>>,<<Sub>>] 1037 /// CHECK-DAG: Return [<<Phi>>] 1038 1039 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after) 1040 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 1041 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 1042 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const7>>,<<Const3>>] 1043 /// CHECK-DAG: Return [<<Phi>>] 1044 1045 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after) 1046 /// CHECK-NOT: Add 1047 /// CHECK-NOT: Sub 1048 JumpsAndConditionals(boolean cond)1049 public static int JumpsAndConditionals(boolean cond) { 1050 int a, b, c; 1051 a = 5; 1052 b = 2; 1053 if (cond) 1054 c = a + b; 1055 else 1056 c = a - b; 1057 return c; 1058 } 1059 1060 1061 /** 1062 * Test optimizations of arithmetic identities yielding a constant result. 1063 */ 1064 1065 /// CHECK-START: int Main.And0(int) constant_folding (before) 1066 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1067 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1068 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const0>>] 1069 /// CHECK-DAG: Return [<<And>>] 1070 1071 /// CHECK-START: int Main.And0(int) constant_folding (after) 1072 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1073 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1074 /// CHECK-DAG: Return [<<Const0>>] 1075 1076 /// CHECK-START: int Main.And0(int) constant_folding (after) 1077 /// CHECK-NOT: And 1078 And0(int arg)1079 public static int And0(int arg) { 1080 return arg & 0; 1081 } 1082 1083 /// CHECK-START: long Main.Mul0(long) constant_folding (before) 1084 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1085 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1086 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const0>>,<<Arg>>] 1087 /// CHECK-DAG: Return [<<Mul>>] 1088 1089 /// CHECK-START: long Main.Mul0(long) constant_folding (after) 1090 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1091 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1092 /// CHECK-DAG: Return [<<Const0>>] 1093 1094 /// CHECK-START: long Main.Mul0(long) constant_folding (after) 1095 /// CHECK-NOT: Mul 1096 Mul0(long arg)1097 public static long Mul0(long arg) { 1098 return arg * 0; 1099 } 1100 1101 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before) 1102 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1103 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 1104 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<ConstF>>] 1105 /// CHECK-DAG: Return [<<Or>>] 1106 1107 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after) 1108 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 1109 /// CHECK-DAG: Return [<<ConstF>>] 1110 1111 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after) 1112 /// CHECK-NOT: Or 1113 OrAllOnes(int arg)1114 public static int OrAllOnes(int arg) { 1115 return arg | -1; 1116 } 1117 1118 /// CHECK-START: long Main.Rem0(long) constant_folding (before) 1119 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1120 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1121 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Arg>>] 1122 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const0>>,<<DivZeroCheck>>] 1123 /// CHECK-DAG: Return [<<Rem>>] 1124 1125 /// CHECK-START: long Main.Rem0(long) constant_folding (after) 1126 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1127 /// CHECK-DAG: Return [<<Const0>>] 1128 1129 /// CHECK-START: long Main.Rem0(long) constant_folding (after) 1130 /// CHECK-NOT: Rem 1131 Rem0(long arg)1132 public static long Rem0(long arg) { 1133 return 0 % arg; 1134 } 1135 1136 /// CHECK-START: int Main.Rem1(int) constant_folding (before) 1137 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1138 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1139 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<Const1>>] 1140 /// CHECK-DAG: Return [<<Rem>>] 1141 1142 /// CHECK-START: int Main.Rem1(int) constant_folding (after) 1143 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1144 /// CHECK-DAG: Return [<<Const0>>] 1145 1146 /// CHECK-START: int Main.Rem1(int) constant_folding (after) 1147 /// CHECK-NOT: Rem 1148 Rem1(int arg)1149 public static int Rem1(int arg) { 1150 return arg % 1; 1151 } 1152 1153 /// CHECK-START: int Main.RemN1(int) constant_folding (before) 1154 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1155 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1 1156 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<ConstN1>>] 1157 /// CHECK-DAG: Return [<<Rem>>] 1158 1159 /// CHECK-START: int Main.RemN1(int) constant_folding (after) 1160 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1161 /// CHECK-DAG: Return [<<Const0>>] 1162 1163 /// CHECK-START: int Main.RemN1(int) constant_folding (after) 1164 /// CHECK-NOT: Rem 1165 RemN1(int arg)1166 public static int RemN1(int arg) { 1167 return arg % -1; 1168 } 1169 1170 /// CHECK-START: long Main.Rem1(long) constant_folding (before) 1171 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1172 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1 1173 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Const1>>] 1174 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>] 1175 /// CHECK-DAG: Return [<<Rem>>] 1176 1177 /// CHECK-START: long Main.Rem1(long) constant_folding (after) 1178 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1179 /// CHECK-DAG: Return [<<Const0>>] 1180 1181 /// CHECK-START: long Main.Rem1(long) constant_folding (after) 1182 /// CHECK-NOT: Rem 1183 Rem1(long arg)1184 public static long Rem1(long arg) { 1185 return arg % 1; 1186 } 1187 1188 /// CHECK-START: long Main.RemN1(long) constant_folding (before) 1189 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1190 /// CHECK-DAG: <<ConstN1:j\d+>> LongConstant -1 1191 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<ConstN1>>] 1192 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>] 1193 /// CHECK-DAG: Return [<<Rem>>] 1194 1195 /// CHECK-START: long Main.RemN1(long) constant_folding (after) 1196 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1197 /// CHECK-DAG: Return [<<Const0>>] 1198 1199 /// CHECK-START: long Main.RemN1(long) constant_folding (after) 1200 /// CHECK-NOT: Rem 1201 RemN1(long arg)1202 public static long RemN1(long arg) { 1203 return arg % -1; 1204 } 1205 1206 /// CHECK-START: int Main.Shl0(int) constant_folding (before) 1207 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1208 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1209 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const0>>,<<Arg>>] 1210 /// CHECK-DAG: Return [<<Shl>>] 1211 1212 /// CHECK-START: int Main.Shl0(int) constant_folding (after) 1213 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1214 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1215 /// CHECK-DAG: Return [<<Const0>>] 1216 1217 /// CHECK-START: int Main.Shl0(int) constant_folding (after) 1218 /// CHECK-NOT: Shl 1219 Shl0(int arg)1220 public static int Shl0(int arg) { 1221 return 0 << arg; 1222 } 1223 1224 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (before) 1225 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1226 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0 1227 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const0L>>,<<Arg>>] 1228 /// CHECK-DAG: Return [<<Shl>>] 1229 1230 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after) 1231 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1232 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0 1233 /// CHECK-DAG: Return [<<Const0L>>] 1234 1235 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after) 1236 /// CHECK-NOT: Shl 1237 ShlLong0WithInt(int arg)1238 public static long ShlLong0WithInt(int arg) { 1239 long long_zero = 0; 1240 return long_zero << arg; 1241 } 1242 1243 /// CHECK-START: long Main.Shr0(int) constant_folding (before) 1244 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1245 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1246 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const0>>,<<Arg>>] 1247 /// CHECK-DAG: Return [<<Shr>>] 1248 1249 /// CHECK-START: long Main.Shr0(int) constant_folding (after) 1250 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1251 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1252 /// CHECK-DAG: Return [<<Const0>>] 1253 1254 /// CHECK-START: long Main.Shr0(int) constant_folding (after) 1255 /// CHECK-NOT: Shr 1256 Shr0(int arg)1257 public static long Shr0(int arg) { 1258 return (long)0 >> arg; 1259 } 1260 1261 /// CHECK-START: long Main.SubSameLong(long) constant_folding (before) 1262 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1263 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Arg>>] 1264 /// CHECK-DAG: Return [<<Sub>>] 1265 1266 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after) 1267 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue 1268 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1269 /// CHECK-DAG: Return [<<Const0>>] 1270 1271 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after) 1272 /// CHECK-NOT: Sub 1273 SubSameLong(long arg)1274 public static long SubSameLong(long arg) { 1275 return arg - arg; 1276 } 1277 1278 /// CHECK-START: int Main.UShr0(int) constant_folding (before) 1279 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1280 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1281 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Const0>>,<<Arg>>] 1282 /// CHECK-DAG: Return [<<UShr>>] 1283 1284 /// CHECK-START: int Main.UShr0(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.UShr0(int) constant_folding (after) 1290 /// CHECK-NOT: UShr 1291 UShr0(int arg)1292 public static int UShr0(int arg) { 1293 return 0 >>> arg; 1294 } 1295 1296 /// CHECK-START: int Main.XorSameInt(int) constant_folding (before) 1297 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue 1298 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Arg>>] 1299 /// CHECK-DAG: Return [<<Xor>>] 1300 1301 /// CHECK-START: int Main.XorSameInt(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.XorSameInt(int) constant_folding (after) 1307 /// CHECK-NOT: Xor 1308 XorSameInt(int arg)1309 public static int XorSameInt(int arg) { 1310 return arg ^ arg; 1311 } 1312 1313 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before) 1314 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue 1315 /// CHECK-DAG: <<ConstNan:f\d+>> FloatConstant nan 1316 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1317 /// CHECK-DAG: IntConstant 1 1318 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>] 1319 /// CHECK-DAG: <<Le:z\d+>> LessThanOrEqual [<<Cmp>>,<<Const0>>] 1320 /// CHECK-DAG: If [<<Le>>] 1321 1322 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after) 1323 /// CHECK-DAG: ParameterValue 1324 /// CHECK-DAG: FloatConstant nan 1325 /// CHECK-DAG: IntConstant 0 1326 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1327 /// CHECK-DAG: If [<<Const1>>] 1328 1329 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after) 1330 /// CHECK-NOT: Compare 1331 /// CHECK-NOT: LessThanOrEqual 1332 CmpFloatGreaterThanNaN(float arg)1333 public static boolean CmpFloatGreaterThanNaN(float arg) { 1334 return arg > Float.NaN; 1335 } 1336 1337 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before) 1338 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue 1339 /// CHECK-DAG: <<ConstNan:d\d+>> DoubleConstant nan 1340 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1341 /// CHECK-DAG: IntConstant 1 1342 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>] 1343 /// CHECK-DAG: <<Ge:z\d+>> GreaterThanOrEqual [<<Cmp>>,<<Const0>>] 1344 /// CHECK-DAG: If [<<Ge>>] 1345 1346 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after) 1347 /// CHECK-DAG: ParameterValue 1348 /// CHECK-DAG: DoubleConstant nan 1349 /// CHECK-DAG: IntConstant 0 1350 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 1351 /// CHECK-DAG: If [<<Const1>>] 1352 1353 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after) 1354 /// CHECK-NOT: Compare 1355 /// CHECK-NOT: GreaterThanOrEqual 1356 CmpDoubleLessThanNaN(double arg)1357 public static boolean CmpDoubleLessThanNaN(double arg) { 1358 return arg < Double.NaN; 1359 } 1360 1361 1362 /** 1363 * Exercise constant folding on type conversions. 1364 */ 1365 1366 /// CHECK-START: int Main.ReturnInt33() constant_folding (before) 1367 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33 1368 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>] 1369 /// CHECK-DAG: Return [<<Convert>>] 1370 1371 /// CHECK-START: int Main.ReturnInt33() constant_folding (after) 1372 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1373 /// CHECK-DAG: Return [<<Const33>>] 1374 1375 /// CHECK-START: int Main.ReturnInt33() constant_folding (after) 1376 /// CHECK-NOT: TypeConversion 1377 ReturnInt33()1378 public static int ReturnInt33() { 1379 long imm = 33L; 1380 return (int) imm; 1381 } 1382 1383 /// CHECK-START: int Main.ReturnIntMax() constant_folding (before) 1384 /// CHECK-DAG: <<ConstMax:f\d+>> FloatConstant 1e+34 1385 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstMax>>] 1386 /// CHECK-DAG: Return [<<Convert>>] 1387 1388 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after) 1389 /// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647 1390 /// CHECK-DAG: Return [<<ConstMax>>] 1391 1392 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after) 1393 /// CHECK-NOT: TypeConversion 1394 ReturnIntMax()1395 public static int ReturnIntMax() { 1396 float imm = 1.0e34f; 1397 return (int) imm; 1398 } 1399 1400 /// CHECK-START: int Main.ReturnInt0() constant_folding (before) 1401 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan 1402 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstNaN>>] 1403 /// CHECK-DAG: Return [<<Convert>>] 1404 1405 /// CHECK-START: int Main.ReturnInt0() constant_folding (after) 1406 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 1407 /// CHECK-DAG: Return [<<Const0>>] 1408 1409 /// CHECK-START: int Main.ReturnInt0() constant_folding (after) 1410 /// CHECK-NOT: TypeConversion 1411 ReturnInt0()1412 public static int ReturnInt0() { 1413 double imm = Double.NaN; 1414 return (int) imm; 1415 } 1416 1417 /// CHECK-START: long Main.ReturnLong33() constant_folding (before) 1418 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1419 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const33>>] 1420 /// CHECK-DAG: Return [<<Convert>>] 1421 1422 /// CHECK-START: long Main.ReturnLong33() constant_folding (after) 1423 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33 1424 /// CHECK-DAG: Return [<<Const33>>] 1425 1426 /// CHECK-START: long Main.ReturnLong33() constant_folding (after) 1427 /// CHECK-NOT: TypeConversion 1428 ReturnLong33()1429 public static long ReturnLong33() { 1430 int imm = 33; 1431 return (long) imm; 1432 } 1433 1434 /// CHECK-START: long Main.ReturnLong34() constant_folding (before) 1435 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34 1436 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const34>>] 1437 /// CHECK-DAG: Return [<<Convert>>] 1438 1439 /// CHECK-START: long Main.ReturnLong34() constant_folding (after) 1440 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 1441 /// CHECK-DAG: Return [<<Const34>>] 1442 1443 /// CHECK-START: long Main.ReturnLong34() constant_folding (after) 1444 /// CHECK-NOT: TypeConversion 1445 ReturnLong34()1446 public static long ReturnLong34() { 1447 float imm = 34.0f; 1448 return (long) imm; 1449 } 1450 1451 /// CHECK-START: long Main.ReturnLong0() constant_folding (before) 1452 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan 1453 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<ConstNaN>>] 1454 /// CHECK-DAG: Return [<<Convert>>] 1455 1456 /// CHECK-START: long Main.ReturnLong0() constant_folding (after) 1457 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 1458 /// CHECK-DAG: Return [<<Const0>>] 1459 1460 /// CHECK-START: long Main.ReturnLong0() constant_folding (after) 1461 /// CHECK-NOT: TypeConversion 1462 ReturnLong0()1463 public static long ReturnLong0() { 1464 double imm = -Double.NaN; 1465 return (long) imm; 1466 } 1467 1468 /// CHECK-START: float Main.ReturnFloat33() constant_folding (before) 1469 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1470 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const33>>] 1471 /// CHECK-DAG: Return [<<Convert>>] 1472 1473 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after) 1474 /// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33 1475 /// CHECK-DAG: Return [<<Const33>>] 1476 1477 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after) 1478 /// CHECK-NOT: TypeConversion 1479 ReturnFloat33()1480 public static float ReturnFloat33() { 1481 int imm = 33; 1482 return (float) imm; 1483 } 1484 1485 /// CHECK-START: float Main.ReturnFloat34() constant_folding (before) 1486 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 1487 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const34>>] 1488 /// CHECK-DAG: Return [<<Convert>>] 1489 1490 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after) 1491 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34 1492 /// CHECK-DAG: Return [<<Const34>>] 1493 1494 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after) 1495 /// CHECK-NOT: TypeConversion 1496 ReturnFloat34()1497 public static float ReturnFloat34() { 1498 long imm = 34L; 1499 return (float) imm; 1500 } 1501 1502 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (before) 1503 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25 1504 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const>>] 1505 /// CHECK-DAG: Return [<<Convert>>] 1506 1507 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after) 1508 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25 1509 /// CHECK-DAG: Return [<<Const>>] 1510 1511 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after) 1512 /// CHECK-NOT: TypeConversion 1513 ReturnFloat99P25()1514 public static float ReturnFloat99P25() { 1515 double imm = 99.25; 1516 return (float) imm; 1517 } 1518 1519 /// CHECK-START: double Main.ReturnDouble33() constant_folding (before) 1520 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 1521 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const33>>] 1522 /// CHECK-DAG: Return [<<Convert>>] 1523 1524 /// CHECK-START: double Main.ReturnDouble33() constant_folding (after) 1525 /// CHECK-DAG: <<Const33:d\d+>> DoubleConstant 33 1526 /// CHECK-DAG: Return [<<Const33>>] 1527 ReturnDouble33()1528 public static double ReturnDouble33() { 1529 int imm = 33; 1530 return (double) imm; 1531 } 1532 1533 /// CHECK-START: double Main.ReturnDouble34() constant_folding (before) 1534 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 1535 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const34>>] 1536 /// CHECK-DAG: Return [<<Convert>>] 1537 1538 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after) 1539 /// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34 1540 /// CHECK-DAG: Return [<<Const34>>] 1541 1542 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after) 1543 /// CHECK-NOT: TypeConversion 1544 ReturnDouble34()1545 public static double ReturnDouble34() { 1546 long imm = 34L; 1547 return (double) imm; 1548 } 1549 1550 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (before) 1551 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25 1552 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const>>] 1553 /// CHECK-DAG: Return [<<Convert>>] 1554 1555 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after) 1556 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25 1557 /// CHECK-DAG: Return [<<Const>>] 1558 1559 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after) 1560 /// CHECK-NOT: TypeConversion 1561 ReturnDouble99P25()1562 public static double ReturnDouble99P25() { 1563 float imm = 99.25f; 1564 return (double) imm; 1565 } 1566 1567 main(String[] args)1568 public static void main(String[] args) throws Exception { 1569 assertIntEquals(-42, IntNegation()); 1570 assertLongEquals(-42L, LongNegation()); 1571 assertFloatEquals(-42F, FloatNegation()); 1572 assertDoubleEquals(-42D, DoubleNegation()); 1573 1574 assertIntEquals(3, IntAddition1()); 1575 assertIntEquals(14, IntAddition2()); 1576 assertIntEquals(14, smaliIntAddition2()); 1577 assertIntEquals(14, smaliIntAddition2AddAndMove()); 1578 assertLongEquals(3L, LongAddition()); 1579 assertFloatEquals(3F, FloatAddition()); 1580 assertDoubleEquals(3D, DoubleAddition()); 1581 1582 assertIntEquals(4, IntSubtraction()); 1583 assertLongEquals(4L, LongSubtraction()); 1584 assertFloatEquals(4F, FloatSubtraction()); 1585 assertDoubleEquals(4D, DoubleSubtraction()); 1586 1587 assertIntEquals(21, IntMultiplication()); 1588 assertLongEquals(21L, LongMultiplication()); 1589 assertFloatEquals(21F, FloatMultiplication()); 1590 assertDoubleEquals(21D, DoubleMultiplication()); 1591 1592 assertIntEquals(2, IntDivision()); 1593 assertLongEquals(2L, LongDivision()); 1594 assertFloatEquals(3.2F, FloatDivision()); 1595 assertDoubleEquals(3.2D, DoubleDivision()); 1596 1597 assertIntEquals(2, IntRemainder()); 1598 assertLongEquals(2L, LongRemainder()); 1599 assertFloatEquals(0.5F, FloatRemainder()); 1600 assertDoubleEquals(0.5D, DoubleRemainder()); 1601 1602 assertIntEquals(4, ShlIntLong()); 1603 assertLongEquals(12L, ShlLongInt()); 1604 1605 assertIntEquals(1, ShrIntLong()); 1606 assertLongEquals(2L, ShrLongInt()); 1607 1608 assertIntEquals(1073741822, UShrIntLong()); 1609 assertLongEquals(4611686018427387901L, UShrLongInt()); 1610 1611 assertLongEquals(2, AndIntLong()); 1612 assertLongEquals(2, AndLongInt()); 1613 1614 assertLongEquals(11, OrIntLong()); 1615 assertLongEquals(11, OrLongInt()); 1616 1617 assertLongEquals(9, XorIntLong()); 1618 assertLongEquals(9, XorLongInt()); 1619 1620 assertIntEquals(5, StaticCondition()); 1621 assertIntEquals(5, StaticConditionNulls()); 1622 1623 assertIntEquals(7, JumpsAndConditionals(true)); 1624 assertIntEquals(3, JumpsAndConditionals(false)); 1625 assertIntEquals(7, smaliJumpsAndConditionals(true)); 1626 assertIntEquals(3, smaliJumpsAndConditionals(false)); 1627 1628 int arbitrary = 123456; // Value chosen arbitrarily. 1629 1630 assertIntEquals(0, And0(arbitrary)); 1631 assertLongEquals(0, Mul0(arbitrary)); 1632 assertIntEquals(-1, OrAllOnes(arbitrary)); 1633 assertLongEquals(0, Rem0(arbitrary)); 1634 assertIntEquals(0, Rem1(arbitrary)); 1635 assertIntEquals(0, Rem1(0)); 1636 assertIntEquals(0, Rem1(-1)); 1637 assertIntEquals(0, Rem1(Integer.MAX_VALUE)); 1638 assertIntEquals(0, Rem1(Integer.MIN_VALUE)); 1639 assertIntEquals(0, RemN1(arbitrary)); 1640 assertIntEquals(0, RemN1(0)); 1641 assertIntEquals(0, RemN1(-1)); 1642 assertIntEquals(0, RemN1(Integer.MAX_VALUE)); 1643 assertIntEquals(0, RemN1(Integer.MIN_VALUE)); 1644 assertIntEquals(0, RemN1(arbitrary)); 1645 assertLongEquals(0, Rem1((long)arbitrary)); 1646 assertLongEquals(0, Rem1(0L)); 1647 assertLongEquals(0, Rem1(-1L)); 1648 assertLongEquals(0, Rem1(Long.MAX_VALUE)); 1649 assertLongEquals(0, Rem1(Long.MIN_VALUE)); 1650 assertLongEquals(0, RemN1(arbitrary)); 1651 assertLongEquals(0, RemN1(0L)); 1652 assertLongEquals(0, RemN1(-1L)); 1653 assertLongEquals(0, RemN1(Long.MAX_VALUE)); 1654 assertLongEquals(0, RemN1(Long.MIN_VALUE)); 1655 assertIntEquals(0, Shl0(arbitrary)); 1656 assertLongEquals(0, ShlLong0WithInt(arbitrary)); 1657 assertLongEquals(0, Shr0(arbitrary)); 1658 assertLongEquals(0, SubSameLong(arbitrary)); 1659 assertIntEquals(0, UShr0(arbitrary)); 1660 assertIntEquals(0, XorSameInt(arbitrary)); 1661 1662 assertFalse(CmpFloatGreaterThanNaN(arbitrary)); 1663 assertFalse(CmpDoubleLessThanNaN(arbitrary)); 1664 1665 Main main = new Main(); 1666 assertIntEquals(1, main.smaliCmpLongConstants()); 1667 assertIntEquals(-1, main.smaliCmpGtFloatConstants()); 1668 assertIntEquals(-1, main.smaliCmpLtFloatConstants()); 1669 assertIntEquals(-1, main.smaliCmpGtDoubleConstants()); 1670 assertIntEquals(-1, main.smaliCmpLtDoubleConstants()); 1671 1672 assertIntEquals(0, main.smaliCmpLongSameConstant()); 1673 assertIntEquals(0, main.smaliCmpGtFloatSameConstant()); 1674 assertIntEquals(0, main.smaliCmpLtFloatSameConstant()); 1675 assertIntEquals(0, main.smaliCmpGtDoubleSameConstant()); 1676 assertIntEquals(0, main.smaliCmpLtDoubleSameConstant()); 1677 1678 assertIntEquals(1, main.smaliCmpGtFloatConstantWithNaN()); 1679 assertIntEquals(-1, main.smaliCmpLtFloatConstantWithNaN()); 1680 assertIntEquals(1, main.smaliCmpGtDoubleConstantWithNaN()); 1681 assertIntEquals(-1, main.smaliCmpLtDoubleConstantWithNaN()); 1682 1683 assertIntEquals(33, ReturnInt33()); 1684 assertIntEquals(2147483647, ReturnIntMax()); 1685 assertIntEquals(0, ReturnInt0()); 1686 1687 assertLongEquals(33, ReturnLong33()); 1688 assertLongEquals(34, ReturnLong34()); 1689 assertLongEquals(0, ReturnLong0()); 1690 1691 assertFloatEquals(33, ReturnFloat33()); 1692 assertFloatEquals(34, ReturnFloat34()); 1693 assertFloatEquals(99.25f, ReturnFloat99P25()); 1694 1695 assertDoubleEquals(33, ReturnDouble33()); 1696 assertDoubleEquals(34, ReturnDouble34()); 1697 assertDoubleEquals(99.25, ReturnDouble99P25()); 1698 } 1699 Main()1700 Main() throws ClassNotFoundException { 1701 testCmp = Class.forName("TestCmp"); 1702 } 1703 1704 private Class<?> testCmp; 1705 } 1706