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