1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 public class Main { 18 19 static boolean doThrow = false; 20 21 /// CHECK-START: int Main.BoolCond_IntVarVar(boolean, int, int) register (after) 22 /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}] 23 24 /// CHECK-START-ARM64: int Main.BoolCond_IntVarVar(boolean, int, int) disassembly (after) 25 /// CHECK: Select 26 /// CHECK-NEXT: cmp 27 /// CHECK-NEXT: csel ne 28 29 /// CHECK-START-X86_64: int Main.BoolCond_IntVarVar(boolean, int, int) disassembly (after) 30 /// CHECK: <<Cond:z\d+>> ParameterValue 31 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 32 /// CHECK: cmovnz/ne 33 34 /// CHECK-START-X86: int Main.BoolCond_IntVarVar(boolean, int, int) disassembly (after) 35 /// CHECK: <<Cond:z\d+>> ParameterValue 36 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 37 /// CHECK: cmovnz/ne 38 39 public static int BoolCond_IntVarVar(boolean cond, int x, int y) { 40 if (doThrow) { 41 // Try defeating inlining. 42 throw new Error(); 43 } 44 return cond ? x : y; 45 } 46 47 /// CHECK-START: int Main.BoolCond_IntVarCst(boolean, int) register (after) 48 /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}] 49 50 /// CHECK-START-ARM64: int Main.BoolCond_IntVarCst(boolean, int) disassembly (after) 51 /// CHECK: Select 52 /// CHECK-NEXT: cmp 53 /// CHECK-NEXT: csinc ne 54 55 /// CHECK-START-X86_64: int Main.BoolCond_IntVarCst(boolean, int) disassembly (after) 56 /// CHECK: <<Cond:z\d+>> ParameterValue 57 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 58 /// CHECK: cmovnz/ne 59 60 /// CHECK-START-X86: int Main.BoolCond_IntVarCst(boolean, int) disassembly (after) 61 /// CHECK: <<Cond:z\d+>> ParameterValue 62 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 63 /// CHECK: cmovnz/ne 64 65 public static int BoolCond_IntVarCst(boolean cond, int x) { 66 if (doThrow) { 67 // Try defeating inlining. 68 throw new Error(); 69 } 70 return cond ? x : 1; 71 } 72 73 /// CHECK-START: int Main.BoolCond_IntCstVar(boolean, int) register (after) 74 /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}] 75 76 /// CHECK-START-ARM64: int Main.BoolCond_IntCstVar(boolean, int) disassembly (after) 77 /// CHECK: Select 78 /// CHECK-NEXT: cmp 79 /// CHECK-NEXT: csinc eq 80 81 /// CHECK-START-X86_64: int Main.BoolCond_IntCstVar(boolean, int) disassembly (after) 82 /// CHECK: <<Cond:z\d+>> ParameterValue 83 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 84 /// CHECK: cmovnz/ne 85 86 /// CHECK-START-X86: int Main.BoolCond_IntCstVar(boolean, int) disassembly (after) 87 /// CHECK: <<Cond:z\d+>> ParameterValue 88 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 89 /// CHECK: cmovnz/ne 90 91 public static int BoolCond_IntCstVar(boolean cond, int y) { 92 if (doThrow) { 93 // Try defeating inlining. 94 throw new Error(); 95 } 96 return cond ? 1 : y; 97 } 98 99 /// CHECK-START: long Main.BoolCond_LongVarVar(boolean, long, long) register (after) 100 /// CHECK: Select [{{j\d+}},{{j\d+}},{{z\d+}}] 101 102 /// CHECK-START-ARM64: long Main.BoolCond_LongVarVar(boolean, long, long) disassembly (after) 103 /// CHECK: Select 104 /// CHECK-NEXT: cmp 105 /// CHECK-NEXT: csel ne 106 107 /// CHECK-START-X86_64: long Main.BoolCond_LongVarVar(boolean, long, long) disassembly (after) 108 /// CHECK: <<Cond:z\d+>> ParameterValue 109 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 110 /// CHECK: cmovnz/neq 111 112 /// CHECK-START-X86: long Main.BoolCond_LongVarVar(boolean, long, long) disassembly (after) 113 /// CHECK: <<Cond:z\d+>> ParameterValue 114 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 115 /// CHECK: cmovnz/ne 116 /// CHECK-NEXT: cmovnz/ne 117 118 public static long BoolCond_LongVarVar(boolean cond, long x, long y) { 119 if (doThrow) { 120 // Try defeating inlining. 121 throw new Error(); 122 } 123 return cond ? x : y; 124 } 125 126 /// CHECK-START: long Main.BoolCond_LongVarCst(boolean, long) register (after) 127 /// CHECK: Select [{{j\d+}},{{j\d+}},{{z\d+}}] 128 129 /// CHECK-START-ARM64: long Main.BoolCond_LongVarCst(boolean, long) disassembly (after) 130 /// CHECK: Select 131 /// CHECK-NEXT: cmp 132 /// CHECK-NEXT: csinc ne 133 134 /// CHECK-START-X86_64: long Main.BoolCond_LongVarCst(boolean, long) disassembly (after) 135 /// CHECK: <<Cond:z\d+>> ParameterValue 136 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 137 /// CHECK: cmovnz/neq 138 139 /// CHECK-START-X86: long Main.BoolCond_LongVarCst(boolean, long) disassembly (after) 140 /// CHECK: <<Cond:z\d+>> ParameterValue 141 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 142 /// CHECK: cmovnz/ne 143 /// CHECK-NEXT: cmovnz/ne 144 145 public static long BoolCond_LongVarCst(boolean cond, long x) { 146 if (doThrow) { 147 // Try defeating inlining. 148 throw new Error(); 149 } 150 return cond ? x : 1L; 151 } 152 153 /// CHECK-START: long Main.BoolCond_LongCstVar(boolean, long) register (after) 154 /// CHECK: Select [{{j\d+}},{{j\d+}},{{z\d+}}] 155 156 /// CHECK-START-ARM64: long Main.BoolCond_LongCstVar(boolean, long) disassembly (after) 157 /// CHECK: Select 158 /// CHECK-NEXT: cmp 159 /// CHECK-NEXT: csinc eq 160 161 /// CHECK-START-X86_64: long Main.BoolCond_LongCstVar(boolean, long) disassembly (after) 162 /// CHECK: <<Cond:z\d+>> ParameterValue 163 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 164 /// CHECK: cmovnz/neq 165 166 /// CHECK-START-X86: long Main.BoolCond_LongCstVar(boolean, long) disassembly (after) 167 /// CHECK: <<Cond:z\d+>> ParameterValue 168 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 169 /// CHECK: cmovnz/ne 170 /// CHECK-NEXT: cmovnz/ne 171 172 public static long BoolCond_LongCstVar(boolean cond, long y) { 173 if (doThrow) { 174 // Try defeating inlining. 175 throw new Error(); 176 } 177 return cond ? 1L : y; 178 } 179 180 /// CHECK-START: float Main.BoolCond_FloatVarVar(boolean, float, float) register (after) 181 /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}] 182 183 /// CHECK-START-ARM64: float Main.BoolCond_FloatVarVar(boolean, float, float) disassembly (after) 184 /// CHECK: Select 185 /// CHECK-NEXT: cmp 186 /// CHECK-NEXT: fcsel ne 187 188 public static float BoolCond_FloatVarVar(boolean cond, float x, float y) { 189 if (doThrow) { 190 // Try defeating inlining. 191 throw new Error(); 192 } 193 return cond ? x : y; 194 } 195 196 /// CHECK-START: float Main.BoolCond_FloatVarCst(boolean, float) register (after) 197 /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}] 198 199 /// CHECK-START-ARM64: float Main.BoolCond_FloatVarCst(boolean, float) disassembly (after) 200 /// CHECK: Select 201 /// CHECK-NEXT: cmp 202 /// CHECK-NEXT: fcsel ne 203 204 public static float BoolCond_FloatVarCst(boolean cond, float x) { 205 if (doThrow) { 206 // Try defeating inlining. 207 throw new Error(); 208 } 209 return cond ? x : 1.0f; 210 } 211 212 /// CHECK-START: float Main.BoolCond_FloatCstVar(boolean, float) register (after) 213 /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}] 214 215 /// CHECK-START-ARM64: float Main.BoolCond_FloatCstVar(boolean, float) disassembly (after) 216 /// CHECK: Select 217 /// CHECK-NEXT: cmp 218 /// CHECK-NEXT: fcsel ne 219 220 public static float BoolCond_FloatCstVar(boolean cond, float y) { 221 if (doThrow) { 222 // Try defeating inlining. 223 throw new Error(); 224 } 225 return cond ? 1.0f : y; 226 } 227 228 /// CHECK-START: int Main.IntNonmatCond_IntVarVar(int, int, int, int) register (after) 229 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 230 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] 231 232 /// CHECK-START-ARM64: int Main.IntNonmatCond_IntVarVar(int, int, int, int) disassembly (after) 233 /// CHECK: Select 234 /// CHECK-NEXT: cmp 235 /// CHECK-NEXT: csel le 236 237 /// CHECK-START-X86_64: int Main.IntNonmatCond_IntVarVar(int, int, int, int) disassembly (after) 238 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 239 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] 240 /// CHECK: cmovle/ng 241 242 /// CHECK-START-X86: int Main.IntNonmatCond_IntVarVar(int, int, int, int) disassembly (after) 243 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 244 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] 245 /// CHECK: cmovle/ng 246 247 public static int IntNonmatCond_IntVarVar(int a, int b, int x, int y) { 248 if (doThrow) { 249 // Try defeating inlining. 250 throw new Error(); 251 } 252 return a > b ? x : y; 253 } 254 255 /// CHECK-START: int Main.IntMatCond_IntVarVar(int, int, int, int) register (after) 256 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 257 /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},{{z\d+}}] 258 /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>] 259 260 /// CHECK-START-ARM64: int Main.IntMatCond_IntVarVar(int, int, int, int) disassembly (after) 261 /// CHECK: LessThanOrEqual 262 /// CHECK-NEXT: cmp 263 /// CHECK-NEXT: cset le 264 /// CHECK: Select 265 /// CHECK-NEXT: csel le 266 267 /// CHECK-START-X86_64: int Main.IntMatCond_IntVarVar(int, int, int, int) disassembly (after) 268 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 269 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 270 /// CHECK: cmovle/ng 271 272 /// CHECK-START-X86: int Main.IntMatCond_IntVarVar(int, int, int, int) disassembly (after) 273 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 274 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 275 /// CHECK: cmovle/ng 276 277 public static int IntMatCond_IntVarVar(int a, int b, int x, int y) { 278 if (doThrow) { 279 // Try defeating inlining. 280 throw new Error(); 281 } 282 int result = (a > b ? x : y); 283 return result + (a > b ? 0 : 1); 284 } 285 286 /// CHECK-START: long Main.IntNonmatCond_LongVarVar(int, int, long, long) register (after) 287 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 288 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>] 289 290 /// CHECK-START-ARM64: long Main.IntNonmatCond_LongVarVar(int, int, long, long) disassembly (after) 291 /// CHECK: Select 292 /// CHECK-NEXT: cmp 293 /// CHECK-NEXT: csel le 294 295 /// CHECK-START-X86_64: long Main.IntNonmatCond_LongVarVar(int, int, long, long) disassembly (after) 296 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 297 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>] 298 /// CHECK: cmovle/ngq 299 300 /// CHECK-START-X86: long Main.IntNonmatCond_LongVarVar(int, int, long, long) disassembly (after) 301 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 302 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>] 303 /// CHECK: cmovle/ng 304 /// CHECK-NEXT: cmovle/ng 305 306 public static long IntNonmatCond_LongVarVar(int a, int b, long x, long y) { 307 if (doThrow) { 308 // Try defeating inlining. 309 throw new Error(); 310 } 311 return a > b ? x : y; 312 } 313 314 /// CHECK-START: long Main.IntMatCond_LongVarVar(int, int, long, long) register (after) 315 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 316 /// CHECK: <<Sel1:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>] 317 /// CHECK: <<Sel2:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>] 318 /// CHECK: Add [<<Sel2>>,<<Sel1>>] 319 320 /// CHECK-START-ARM64: long Main.IntMatCond_LongVarVar(int, int, long, long) disassembly (after) 321 /// CHECK: LessThanOrEqual 322 /// CHECK-NEXT: cmp 323 /// CHECK-NEXT: cset le 324 /// CHECK: Select 325 /// CHECK-NEXT: csel le 326 327 /// CHECK-START-X86_64: long Main.IntMatCond_LongVarVar(int, int, long, long) disassembly (after) 328 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 329 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 330 /// CHECK: cmovle/ngq 331 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 332 /// CHECK: cmovnz/neq 333 334 /// CHECK-START-X86: long Main.IntMatCond_LongVarVar(int, int, long, long) disassembly (after) 335 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] 336 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 337 /// CHECK-NEXT: cmovle/ng 338 /// CHECK-NEXT: cmovle/ng 339 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 340 /// CHECK: cmovnz/ne 341 /// CHECK-NEXT: cmovnz/ne 342 343 public static long IntMatCond_LongVarVar(int a, int b, long x, long y) { 344 if (doThrow) { 345 // Try defeating inlining. 346 throw new Error(); 347 } 348 long result = (a > b ? x : y); 349 return result + (a > b ? 0L : 1L); 350 } 351 352 /// CHECK-START: long Main.LongNonmatCond_LongVarVar(long, long, long, long) register (after) 353 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}] 354 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 355 356 /// CHECK-START-ARM64: long Main.LongNonmatCond_LongVarVar(long, long, long, long) disassembly (after) 357 /// CHECK: Select 358 /// CHECK-NEXT: cmp 359 /// CHECK-NEXT: csel le 360 361 /// CHECK-START-X86_64: long Main.LongNonmatCond_LongVarVar(long, long, long, long) disassembly (after) 362 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}] 363 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 364 /// CHECK: cmovle/ngq 365 366 public static long LongNonmatCond_LongVarVar(long a, long b, long x, long y) { 367 if (doThrow) { 368 // Try defeating inlining. 369 throw new Error(); 370 } 371 return a > b ? x : y; 372 } 373 374 /// CHECK-START-ARM: long Main.$noinline$LongEqNonmatCond_LongVarVar(long, long, long, long) disassembly (after) 375 /// CHECK: Select 376 /// CHECK-NEXT: cmp {{r\d+}}, {{r\d+}} 377 /// CHECK-NEXT: it eq 378 /// CHECK-NEXT: cmpeq {{r\d+}}, {{r\d+}} 379 /// CHECK-NEXT: it eq 380 381 public static long $noinline$LongEqNonmatCond_LongVarVar(long a, long b, long x, long y) { 382 return a == b ? x : y; 383 } 384 385 /// CHECK-START-ARM: long Main.$noinline$LongNonmatCondCst_LongVarVar(long, long, long) disassembly (after) 386 /// CHECK: Select 387 /// CHECK-NEXT: mov ip, #52720 388 /// CHECK-NEXT: movt ip, #35243 389 /// CHECK-NEXT: cmp {{r\d+}}, ip 390 /// CHECK-NEXT: sbcs ip, {{r\d+}}, #{{\d+}} 391 /// CHECK-NEXT: it ge 392 393 public static long $noinline$LongNonmatCondCst_LongVarVar(long a, long x, long y) { 394 return a > 0x89ABCDEFL ? x : y; 395 } 396 397 /// CHECK-START-ARM: long Main.$noinline$LongNonmatCondCst_LongVarVar2(long, long, long) disassembly (after) 398 /// CHECK: Select 399 /// CHECK-NEXT: mov ip, #{{\d+}} 400 /// CHECK-NEXT: movt ip, #{{\d+}} 401 /// CHECK-NEXT: cmp {{r\d+}}, ip 402 403 public static long $noinline$LongNonmatCondCst_LongVarVar2(long a, long x, long y) { 404 return a > 0x0123456789ABCDEFL ? x : y; 405 } 406 407 /// CHECK-START-ARM: long Main.$noinline$LongNonmatCondCst_LongVarVar3(long, long, long) disassembly (after) 408 /// CHECK: Select 409 /// CHECK-NEXT: cmp {{r\d+}}, {{r\d+}} 410 /// CHECK-NOT: sbcs 411 /// CHECK-NOT: cmp 412 413 public static long $noinline$LongNonmatCondCst_LongVarVar3(long a, long x, long y) { 414 return a > 0x7FFFFFFFFFFFFFFFL ? x : y; 415 } 416 417 /// CHECK-START: long Main.LongMatCond_LongVarVar(long, long, long, long) register (after) 418 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}] 419 /// CHECK: <<Sel1:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>] 420 /// CHECK: <<Sel2:j\d+>> Select [{{j\d+}},{{j\d+}},<<Cond>>] 421 /// CHECK: Add [<<Sel2>>,<<Sel1>>] 422 423 /// CHECK-START-ARM64: long Main.LongMatCond_LongVarVar(long, long, long, long) disassembly (after) 424 /// CHECK: LessThanOrEqual 425 /// CHECK-NEXT: cmp 426 /// CHECK-NEXT: cset le 427 /// CHECK: Select 428 /// CHECK-NEXT: csel le 429 430 /// CHECK-START-X86_64: long Main.LongMatCond_LongVarVar(long, long, long, long) disassembly (after) 431 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}] 432 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 433 /// CHECK: cmovle/ngq 434 /// CHECK: Select [{{j\d+}},{{j\d+}},<<Cond>>] 435 /// CHECK: cmovnz/neq 436 437 public static long LongMatCond_LongVarVar(long a, long b, long x, long y) { 438 if (doThrow) { 439 // Try defeating inlining. 440 throw new Error(); 441 } 442 long result = (a > b ? x : y); 443 return result + (a > b ? 0L : 1L); 444 } 445 446 /// CHECK-START: int Main.FloatLtNonmatCond_IntVarVar(float, float, int, int) register (after) 447 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{f\d+}},{{f\d+}}] 448 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] 449 450 /// CHECK-START-ARM64: int Main.FloatLtNonmatCond_IntVarVar(float, float, int, int) disassembly (after) 451 /// CHECK: LessThanOrEqual 452 /// CHECK: Select 453 /// CHECK-NEXT: fcmp 454 /// CHECK-NEXT: csel le 455 456 public static int FloatLtNonmatCond_IntVarVar(float a, float b, int x, int y) { 457 if (doThrow) { 458 // Try defeating inlining. 459 throw new Error(); 460 } 461 return a > b ? x : y; 462 } 463 464 /// CHECK-START: int Main.FloatGtNonmatCond_IntVarVar(float, float, int, int) register (after) 465 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}] 466 /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] 467 468 /// CHECK-START-ARM64: int Main.FloatGtNonmatCond_IntVarVar(float, float, int, int) disassembly (after) 469 /// CHECK: GreaterThanOrEqual 470 /// CHECK: Select 471 /// CHECK-NEXT: fcmp 472 /// CHECK-NEXT: csel hs 473 474 public static int FloatGtNonmatCond_IntVarVar(float a, float b, int x, int y) { 475 if (doThrow) { 476 // Try defeating inlining. 477 throw new Error(); 478 } 479 return a < b ? x : y; 480 } 481 482 /// CHECK-START: float Main.FloatGtNonmatCond_FloatVarVar(float, float, float, float) register (after) 483 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}] 484 /// CHECK-NEXT: Select [{{f\d+}},{{f\d+}},<<Cond>>] 485 486 /// CHECK-START-ARM64: float Main.FloatGtNonmatCond_FloatVarVar(float, float, float, float) disassembly (after) 487 /// CHECK: GreaterThanOrEqual 488 /// CHECK: Select 489 /// CHECK-NEXT: fcmp 490 /// CHECK-NEXT: fcsel hs 491 492 public static float FloatGtNonmatCond_FloatVarVar(float a, float b, float x, float y) { 493 if (doThrow) { 494 // Try defeating inlining. 495 throw new Error(); 496 } 497 return a < b ? x : y; 498 } 499 500 /// CHECK-START: int Main.FloatLtMatCond_IntVarVar(float, float, int, int) register (after) 501 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{f\d+}},{{f\d+}}] 502 /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},<<Cond>>] 503 /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>] 504 505 /// CHECK-START-ARM64: int Main.FloatLtMatCond_IntVarVar(float, float, int, int) disassembly (after) 506 /// CHECK: LessThanOrEqual 507 /// CHECK-NEXT: fcmp 508 /// CHECK-NEXT: cset le 509 /// CHECK: Select 510 /// CHECK-NEXT: csel le 511 512 public static int FloatLtMatCond_IntVarVar(float a, float b, int x, int y) { 513 if (doThrow) { 514 // Try defeating inlining. 515 throw new Error(); 516 } 517 int result = (a > b ? x : y); 518 return result + (a > b ? 0 : 1); 519 } 520 521 /// CHECK-START: int Main.FloatGtMatCond_IntVarVar(float, float, int, int) register (after) 522 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}] 523 /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},<<Cond>>] 524 /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>] 525 526 /// CHECK-START-ARM64: int Main.FloatGtMatCond_IntVarVar(float, float, int, int) disassembly (after) 527 /// CHECK: GreaterThanOrEqual 528 /// CHECK-NEXT: fcmp 529 /// CHECK-NEXT: cset hs 530 /// CHECK: Select 531 /// CHECK-NEXT: csel hs 532 533 public static int FloatGtMatCond_IntVarVar(float a, float b, int x, int y) { 534 if (doThrow) { 535 // Try defeating inlining. 536 throw new Error(); 537 } 538 int result = (a < b ? x : y); 539 return result + (a < b ? 0 : 1); 540 } 541 542 /// CHECK-START: float Main.FloatGtMatCond_FloatVarVar(float, float, float, float) register (after) 543 /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual 544 /// CHECK-NEXT: <<Sel:f\d+>> Select [{{f\d+}},{{f\d+}},<<Cond>>] 545 /// CHECK-NEXT: TypeConversion [<<Cond>>] 546 547 /// CHECK-START-ARM64: float Main.FloatGtMatCond_FloatVarVar(float, float, float, float) disassembly (after) 548 /// CHECK: GreaterThanOrEqual 549 /// CHECK-NEXT: fcmp 550 /// CHECK-NEXT: cset hs 551 /// CHECK: Select 552 /// CHECK-NEXT: fcsel hs 553 554 public static float FloatGtMatCond_FloatVarVar(float a, float b, float x, float y) { 555 if (doThrow) { 556 // Try defeating inlining. 557 throw new Error(); 558 } 559 float result = (a < b ? x : y); 560 return result + (a < b ? 0 : 1); 561 } 562 563 /// CHECK-START: int Main.BoolCond_0_m1(boolean) register (after) 564 /// CHECK: <<Cond:z\d+>> ParameterValue 565 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 566 567 /// CHECK-START-ARM64: int Main.BoolCond_0_m1(boolean) disassembly (after) 568 /// CHECK: <<Cond:z\d+>> ParameterValue 569 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 570 /// CHECK-NEXT: cmp {{w\d+}}, #0x0 (0) 571 /// CHECK-NEXT: csetm {{w\d+}}, eq 572 573 /// CHECK-START-X86_64: int Main.BoolCond_0_m1(boolean) disassembly (after) 574 /// CHECK: <<Cond:z\d+>> ParameterValue 575 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 576 /// CHECK: cmovnz/ne 577 578 /// CHECK-START-X86: int Main.BoolCond_0_m1(boolean) disassembly (after) 579 /// CHECK: <<Cond:z\d+>> ParameterValue 580 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 581 /// CHECK: cmovnz/ne 582 583 public static int BoolCond_0_m1(boolean cond) { 584 if (doThrow) { 585 // Try defeating inlining. 586 throw new Error(); 587 } 588 return cond ? 0 : -1; 589 } 590 591 /// CHECK-START: int Main.BoolCond_m1_0(boolean) register (after) 592 /// CHECK: <<Cond:z\d+>> ParameterValue 593 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 594 595 /// CHECK-START-ARM64: int Main.BoolCond_m1_0(boolean) disassembly (after) 596 /// CHECK: <<Cond:z\d+>> ParameterValue 597 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 598 /// CHECK-NEXT: cmp {{w\d+}}, #0x0 (0) 599 /// CHECK-NEXT: csetm {{w\d+}}, ne 600 601 /// CHECK-START-X86_64: int Main.BoolCond_m1_0(boolean) disassembly (after) 602 /// CHECK: <<Cond:z\d+>> ParameterValue 603 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 604 /// CHECK: cmovnz/ne 605 606 /// CHECK-START-X86: int Main.BoolCond_m1_0(boolean) disassembly (after) 607 /// CHECK: <<Cond:z\d+>> ParameterValue 608 /// CHECK: Select [{{i\d+}},{{i\d+}},<<Cond>>] 609 /// CHECK: cmovnz/ne 610 611 public static int BoolCond_m1_0(boolean cond) { 612 if (doThrow) { 613 // Try defeating inlining. 614 throw new Error(); 615 } 616 return cond ? -1 : 0; 617 } 618 619 public static void assertEqual(int expected, int actual) { 620 if (expected != actual) { 621 throw new Error("Assertion failed: " + expected + " != " + actual); 622 } 623 } 624 625 public static void assertEqual(float expected, float actual) { 626 if (expected != actual) { 627 throw new Error("Assertion failed: " + expected + " != " + actual); 628 } 629 } 630 631 public static void main(String[] args) { 632 assertEqual(5, BoolCond_IntVarVar(true, 5, 7)); 633 assertEqual(7, BoolCond_IntVarVar(false, 5, 7)); 634 assertEqual(5, BoolCond_IntVarCst(true, 5)); 635 assertEqual(1, BoolCond_IntVarCst(false, 5)); 636 assertEqual(1, BoolCond_IntCstVar(true, 7)); 637 assertEqual(7, BoolCond_IntCstVar(false, 7)); 638 639 assertEqual(5L, BoolCond_LongVarVar(true, 5L, 7L)); 640 assertEqual(7L, BoolCond_LongVarVar(false, 5L, 7L)); 641 assertEqual(5L, BoolCond_LongVarCst(true, 5L)); 642 assertEqual(1L, BoolCond_LongVarCst(false, 5L)); 643 assertEqual(1L, BoolCond_LongCstVar(true, 7L)); 644 assertEqual(7L, BoolCond_LongCstVar(false, 7L)); 645 646 assertEqual(5, BoolCond_FloatVarVar(true, 5, 7)); 647 assertEqual(7, BoolCond_FloatVarVar(false, 5, 7)); 648 assertEqual(5, BoolCond_FloatVarCst(true, 5)); 649 assertEqual(1, BoolCond_FloatVarCst(false, 5)); 650 assertEqual(1, BoolCond_FloatCstVar(true, 7)); 651 assertEqual(7, BoolCond_FloatCstVar(false, 7)); 652 653 assertEqual(5, IntNonmatCond_IntVarVar(3, 2, 5, 7)); 654 assertEqual(7, IntNonmatCond_IntVarVar(2, 3, 5, 7)); 655 assertEqual(5, IntMatCond_IntVarVar(3, 2, 5, 7)); 656 assertEqual(8, IntMatCond_IntVarVar(2, 3, 5, 7)); 657 658 assertEqual(0xAAAAAAAA55555555L, 659 LongNonmatCond_LongVarVar(3L, 2L, 0xAAAAAAAA55555555L, 0x8888888877777777L)); 660 assertEqual(0x8888888877777777L, 661 LongNonmatCond_LongVarVar(2L, 2L, 0xAAAAAAAA55555555L, 0x8888888877777777L)); 662 assertEqual(0x8888888877777777L, 663 LongNonmatCond_LongVarVar(2L, 3L, 0xAAAAAAAA55555555L, 0x8888888877777777L)); 664 assertEqual(0xAAAAAAAA55555555L, LongNonmatCond_LongVarVar(0x0000000100000000L, 665 0x00000000FFFFFFFFL, 666 0xAAAAAAAA55555555L, 667 0x8888888877777777L)); 668 assertEqual(0x8888888877777777L, LongNonmatCond_LongVarVar(0x00000000FFFFFFFFL, 669 0x0000000100000000L, 670 0xAAAAAAAA55555555L, 671 0x8888888877777777L)); 672 673 assertEqual(0x8888888877777777L, $noinline$LongEqNonmatCond_LongVarVar(2L, 674 3L, 675 0xAAAAAAAA55555555L, 676 0x8888888877777777L)); 677 assertEqual(0xAAAAAAAA55555555L, $noinline$LongEqNonmatCond_LongVarVar(2L, 678 2L, 679 0xAAAAAAAA55555555L, 680 0x8888888877777777L)); 681 assertEqual(0x8888888877777777L, $noinline$LongEqNonmatCond_LongVarVar(0x10000000000L, 682 0L, 683 0xAAAAAAAA55555555L, 684 0x8888888877777777L)); 685 686 assertEqual(5L, $noinline$LongNonmatCondCst_LongVarVar2(0x7FFFFFFFFFFFFFFFL, 5L, 7L)); 687 assertEqual(7L, $noinline$LongNonmatCondCst_LongVarVar2(2L, 5L, 7L)); 688 689 assertEqual(7L, $noinline$LongNonmatCondCst_LongVarVar3(2L, 5L, 7L)); 690 691 assertEqual(5, FloatLtNonmatCond_IntVarVar(3, 2, 5, 7)); 692 assertEqual(7, FloatLtNonmatCond_IntVarVar(2, 3, 5, 7)); 693 assertEqual(7, FloatLtNonmatCond_IntVarVar(Float.NaN, 2, 5, 7)); 694 assertEqual(7, FloatLtNonmatCond_IntVarVar(2, Float.NaN, 5, 7)); 695 696 assertEqual(5, FloatGtNonmatCond_IntVarVar(2, 3, 5, 7)); 697 assertEqual(7, FloatGtNonmatCond_IntVarVar(3, 2, 5, 7)); 698 assertEqual(7, FloatGtNonmatCond_IntVarVar(Float.NaN, 2, 5, 7)); 699 assertEqual(7, FloatGtNonmatCond_IntVarVar(2, Float.NaN, 5, 7)); 700 701 assertEqual(5, FloatGtNonmatCond_FloatVarVar(2, 3, 5, 7)); 702 assertEqual(7, FloatGtNonmatCond_FloatVarVar(3, 2, 5, 7)); 703 assertEqual(7, FloatGtNonmatCond_FloatVarVar(Float.NaN, 2, 5, 7)); 704 assertEqual(7, FloatGtNonmatCond_FloatVarVar(2, Float.NaN, 5, 7)); 705 706 assertEqual(5, FloatLtMatCond_IntVarVar(3, 2, 5, 7)); 707 assertEqual(8, FloatLtMatCond_IntVarVar(2, 3, 5, 7)); 708 assertEqual(8, FloatLtMatCond_IntVarVar(Float.NaN, 2, 5, 7)); 709 assertEqual(8, FloatLtMatCond_IntVarVar(2, Float.NaN, 5, 7)); 710 711 assertEqual(5, FloatGtMatCond_IntVarVar(2, 3, 5, 7)); 712 assertEqual(8, FloatGtMatCond_IntVarVar(3, 2, 5, 7)); 713 assertEqual(8, FloatGtMatCond_IntVarVar(Float.NaN, 2, 5, 7)); 714 assertEqual(8, FloatGtMatCond_IntVarVar(2, Float.NaN, 5, 7)); 715 716 assertEqual(5, FloatGtMatCond_FloatVarVar(2, 3, 5, 7)); 717 assertEqual(8, FloatGtMatCond_FloatVarVar(3, 2, 5, 7)); 718 assertEqual(8, FloatGtMatCond_FloatVarVar(Float.NaN, 2, 5, 7)); 719 assertEqual(8, FloatGtMatCond_FloatVarVar(2, Float.NaN, 5, 7)); 720 721 assertEqual(0, BoolCond_0_m1(true)); 722 assertEqual(-1, BoolCond_0_m1(false)); 723 assertEqual(-1, BoolCond_m1_0(true)); 724 assertEqual(0, BoolCond_m1_0(false)); 725 } 726 } 727