blob: edb31e6d123dba4f4149b201c526d5c3aaae82d0 [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
48 public long $noinline$longSelect_Constant(long param) {
49 if (doThrow) { throw new Error(); }
50 long val_true = longB;
51 long val_false = longC;
52 return (param > 3L) ? val_true : val_false;
53 }
54
55 public static void main(String[] args) {
56 Main m = new Main();
57 assertLongEquals(5L, m.$noinline$longSelect(4L));
58 assertLongEquals(7L, m.$noinline$longSelect(2L));
59 assertLongEquals(5L, m.$noinline$longSelect_Constant(4L));
60 assertLongEquals(7L, m.$noinline$longSelect_Constant(2L));
61 }
62
63 public static void assertLongEquals(long expected, long actual) {
64 if (expected != actual) {
65 throw new Error(expected + " != " + actual);
66 }
67 }
68
69 public boolean doThrow = false;
70
71 public long longA = 3L;
72 public long longB = 5L;
73 public long longC = 7L;
74}