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