1 /* 2 * Copyright (C) 2016 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 /// CHECK-START: long Main.$noinline$longSelect(long) register (before) 20 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},{{j\d+}}] 21 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>] 22 $noinline$longSelect(long param)23 public long $noinline$longSelect(long param) { 24 long val_true = longB; 25 long val_false = longC; 26 return (param > longA) ? val_true : val_false; 27 } 28 29 /// CHECK-START: long Main.$noinline$longSelect_Constant(long) register (before) 30 /// CHECK: <<Const:j\d+>> LongConstant 31 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},<<Const>>] 32 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>] 33 34 // Condition can be non-materialized on X86 because the condition does not 35 // request 4 registers any more. 36 /// CHECK-START-X86: long Main.$noinline$longSelect_Constant(long) disassembly (after) 37 /// CHECK: LessThanOrEqual 38 /// CHECK-NEXT: Select 39 40 // Check that we generate CMOV for long on x86_64. 41 /// CHECK-START-X86_64: long Main.$noinline$longSelect_Constant(long) disassembly (after) 42 /// CHECK: LessThanOrEqual 43 /// CHECK-NEXT: Select 44 /// CHECK: cmpq 45 /// CHECK: cmovle/ngq 46 $noinline$longSelect_Constant(long param)47 public long $noinline$longSelect_Constant(long param) { 48 long val_true = longB; 49 long val_false = longC; 50 return (param > 3L) ? val_true : val_false; 51 } 52 53 // Check that we generate CMOV for int on x86_64. 54 /// CHECK-START-X86_64: int Main.$noinline$intSelect_Constant(int) disassembly (after) 55 /// CHECK: LessThan 56 /// CHECK-NEXT: Select 57 /// CHECK: cmp 58 /// CHECK: cmovl/nge 59 $noinline$intSelect_Constant(int param)60 public int $noinline$intSelect_Constant(int param) { 61 int val_true = intB; 62 int val_false = intC; 63 return (param >= 3) ? val_true : val_false; 64 } 65 main(String[] args)66 public static void main(String[] args) { 67 Main m = new Main(); 68 assertLongEquals(5L, m.$noinline$longSelect(4L)); 69 assertLongEquals(7L, m.$noinline$longSelect(2L)); 70 assertLongEquals(5L, m.$noinline$longSelect_Constant(4L)); 71 assertLongEquals(7L, m.$noinline$longSelect_Constant(2L)); 72 assertIntEquals(5, m.$noinline$intSelect_Constant(4)); 73 assertIntEquals(7, m.$noinline$intSelect_Constant(2)); 74 } 75 assertIntEquals(int expected, int actual)76 public static void assertIntEquals(int expected, int actual) { 77 if (expected != actual) { 78 throw new Error(expected + " != " + actual); 79 } 80 } 81 assertLongEquals(long expected, long actual)82 public static void assertLongEquals(long expected, long actual) { 83 if (expected != actual) { 84 throw new Error(expected + " != " + actual); 85 } 86 } 87 88 public long longA = 3L; 89 public long longB = 5L; 90 public long longC = 7L; 91 public int intB = 5; 92 public int intC = 7; 93 } 94