blob: 3a1b3fcf85a63879a96f24ec87b3ce766dd38cff [file] [log] [blame]
David Brazdil74eb1b22015-12-14 11:44:01 +00001/*
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
17public 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
23 // Condition must be materialized on X86 because it would need too many
24 // registers otherwise.
25 /// CHECK-START-X86: long Main.$noinline$longSelect(long) disassembly (after)
26 /// CHECK: LessThanOrEqual
27 /// CHECK-NEXT: cmp
28 /// CHECK: Select
29
30 public long $noinline$longSelect(long param) {
31 if (doThrow) { throw new Error(); }
32 long val_true = longB;
33 long val_false = longC;
34 return (param > longA) ? val_true : val_false;
35 }
36
37 /// CHECK-START: long Main.$noinline$longSelect_Constant(long) register (before)
38 /// CHECK: <<Const:j\d+>> LongConstant
39 /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{j\d+}},<<Const>>]
40 /// CHECK-NEXT: Select [{{j\d+}},{{j\d+}},<<Cond>>]
41
42 // Condition can be non-materialized on X86 because the condition does not
43 // request 4 registers any more.
44 /// CHECK-START-X86: long Main.$noinline$longSelect_Constant(long) disassembly (after)
45 /// CHECK: LessThanOrEqual
46 /// CHECK-NEXT: Select
47
Mark Mendell7c0b44f2016-02-01 10:08:35 -050048 // Check that we generate CMOV for long on x86_64.
49 /// CHECK-START-X86_64: long Main.$noinline$longSelect_Constant(long) disassembly (after)
50 /// CHECK: LessThanOrEqual
51 /// CHECK-NEXT: Select
52 /// CHECK: cmpq
53 /// CHECK: cmovle/ngq
54
David Brazdil74eb1b22015-12-14 11:44:01 +000055 public long $noinline$longSelect_Constant(long param) {
56 if (doThrow) { throw new Error(); }
57 long val_true = longB;
58 long val_false = longC;
59 return (param > 3L) ? val_true : val_false;
60 }
61
Mark Mendell7c0b44f2016-02-01 10:08:35 -050062 // Check that we generate CMOV for int on x86_64.
63 /// CHECK-START-X86_64: int Main.$noinline$intSelect_Constant(int) disassembly (after)
64 /// CHECK: LessThan
65 /// CHECK-NEXT: Select
66 /// CHECK: cmp
67 /// CHECK: cmovl/nge
68
69 public int $noinline$intSelect_Constant(int param) {
70 if (doThrow) { throw new Error(); }
71 int val_true = intB;
72 int val_false = intC;
73 return (param >= 3) ? val_true : val_false;
74 }
75
David Brazdil74eb1b22015-12-14 11:44:01 +000076 public static void main(String[] args) {
77 Main m = new Main();
78 assertLongEquals(5L, m.$noinline$longSelect(4L));
79 assertLongEquals(7L, m.$noinline$longSelect(2L));
80 assertLongEquals(5L, m.$noinline$longSelect_Constant(4L));
81 assertLongEquals(7L, m.$noinline$longSelect_Constant(2L));
Mark Mendell7c0b44f2016-02-01 10:08:35 -050082 assertIntEquals(5, m.$noinline$intSelect_Constant(4));
83 assertIntEquals(7, m.$noinline$intSelect_Constant(2));
84 }
85
86 public static void assertIntEquals(int expected, int actual) {
87 if (expected != actual) {
88 throw new Error(expected + " != " + actual);
89 }
David Brazdil74eb1b22015-12-14 11:44:01 +000090 }
91
92 public static void assertLongEquals(long expected, long actual) {
93 if (expected != actual) {
94 throw new Error(expected + " != " + actual);
95 }
96 }
97
98 public boolean doThrow = false;
99
100 public long longA = 3L;
101 public long longB = 5L;
102 public long longC = 7L;
Mark Mendell7c0b44f2016-02-01 10:08:35 -0500103 public int intB = 5;
104 public int intC = 7;
David Brazdil74eb1b22015-12-14 11:44:01 +0000105}