1 ; RUN: llc -mtriple=aarch64-apple-darwin -verify-machineinstrs < %s | FileCheck %s
2 ; RUN: llc -mtriple=aarch64-apple-darwin -fast-isel -fast-isel-abort=1 -verify-machineinstrs < %s | FileCheck %s
4 ; First test the different supported value types for select.
5 define zeroext i1 @select_i1(i1 zeroext %c, i1 zeroext %a, i1 zeroext %b) {
6 ; CHECK-LABEL: select_i1
7 ; CHECK: {{cmp w0, #0|tst w0, #0x1}}
8 ; CHECK-NEXT: csel {{w[0-9]+}}, w1, w2, ne
9 %1 = select i1 %c, i1 %a, i1 %b
13 define zeroext i8 @select_i8(i1 zeroext %c, i8 zeroext %a, i8 zeroext %b) {
14 ; CHECK-LABEL: select_i8
15 ; CHECK: {{cmp w0, #0|tst w0, #0x1}}
16 ; CHECK-NEXT: csel {{w[0-9]+}}, w1, w2, ne
17 %1 = select i1 %c, i8 %a, i8 %b
21 define zeroext i16 @select_i16(i1 zeroext %c, i16 zeroext %a, i16 zeroext %b) {
22 ; CHECK-LABEL: select_i16
23 ; CHECK: {{cmp w0, #0|tst w0, #0x1}}
24 ; CHECK-NEXT: csel {{w[0-9]+}}, w1, w2, ne
25 %1 = select i1 %c, i16 %a, i16 %b
29 define i32 @select_i32(i1 zeroext %c, i32 %a, i32 %b) {
30 ; CHECK-LABEL: select_i32
31 ; CHECK: {{cmp w0, #0|tst w0, #0x1}}
32 ; CHECK-NEXT: csel {{w[0-9]+}}, w1, w2, ne
33 %1 = select i1 %c, i32 %a, i32 %b
37 define i64 @select_i64(i1 zeroext %c, i64 %a, i64 %b) {
38 ; CHECK-LABEL: select_i64
39 ; CHECK: {{cmp w0, #0|tst w0, #0x1}}
40 ; CHECK-NEXT: csel {{x[0-9]+}}, x1, x2, ne
41 %1 = select i1 %c, i64 %a, i64 %b
45 define float @select_f32(i1 zeroext %c, float %a, float %b) {
46 ; CHECK-LABEL: select_f32
47 ; CHECK: {{cmp w0, #0|tst w0, #0x1}}
48 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, ne
49 %1 = select i1 %c, float %a, float %b
53 define double @select_f64(i1 zeroext %c, double %a, double %b) {
54 ; CHECK-LABEL: select_f64
55 ; CHECK: {{cmp w0, #0|tst w0, #0x1}}
56 ; CHECK-NEXT: fcsel {{d[0-9]+}}, d0, d1, ne
57 %1 = select i1 %c, double %a, double %b
61 ; Now test the folding of all compares.
62 define float @select_fcmp_false(float %x, float %a, float %b) {
63 ; CHECK-LABEL: select_fcmp_false
64 ; CHECK: mov.16b {{v[0-9]+}}, v2
65 %1 = fcmp ogt float %x, %x
66 %2 = select i1 %1, float %a, float %b
70 define float @select_fcmp_ogt(float %x, float %y, float %a, float %b) {
71 ; CHECK-LABEL: select_fcmp_ogt
73 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, gt
74 %1 = fcmp ogt float %x, %y
75 %2 = select i1 %1, float %a, float %b
79 define float @select_fcmp_oge(float %x, float %y, float %a, float %b) {
80 ; CHECK-LABEL: select_fcmp_oge
82 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, ge
83 %1 = fcmp oge float %x, %y
84 %2 = select i1 %1, float %a, float %b
88 define float @select_fcmp_olt(float %x, float %y, float %a, float %b) {
89 ; CHECK-LABEL: select_fcmp_olt
91 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, mi
92 %1 = fcmp olt float %x, %y
93 %2 = select i1 %1, float %a, float %b
97 define float @select_fcmp_ole(float %x, float %y, float %a, float %b) {
98 ; CHECK-LABEL: select_fcmp_ole
100 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, ls
101 %1 = fcmp ole float %x, %y
102 %2 = select i1 %1, float %a, float %b
106 define float @select_fcmp_one(float %x, float %y, float %a, float %b) {
107 ; CHECK-LABEL: select_fcmp_one
109 ; CHECK-NEXT: fcsel [[REG:s[0-9]+]], s2, s3, mi
110 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, [[REG]], gt
111 %1 = fcmp one float %x, %y
112 %2 = select i1 %1, float %a, float %b
116 define float @select_fcmp_ord(float %x, float %y, float %a, float %b) {
117 ; CHECK-LABEL: select_fcmp_ord
119 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, vc
120 %1 = fcmp ord float %x, %y
121 %2 = select i1 %1, float %a, float %b
125 define float @select_fcmp_uno(float %x, float %y, float %a, float %b) {
126 ; CHECK-LABEL: select_fcmp_uno
128 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, vs
129 %1 = fcmp uno float %x, %y
130 %2 = select i1 %1, float %a, float %b
134 define float @select_fcmp_ueq(float %x, float %y, float %a, float %b) {
135 ; CHECK-LABEL: select_fcmp_ueq
137 ; CHECK-NEXT: fcsel [[REG:s[0-9]+]], s2, s3, eq
138 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, [[REG]], vs
139 %1 = fcmp ueq float %x, %y
140 %2 = select i1 %1, float %a, float %b
144 define float @select_fcmp_ugt(float %x, float %y, float %a, float %b) {
145 ; CHECK-LABEL: select_fcmp_ugt
147 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, hi
148 %1 = fcmp ugt float %x, %y
149 %2 = select i1 %1, float %a, float %b
153 define float @select_fcmp_uge(float %x, float %y, float %a, float %b) {
154 ; CHECK-LABEL: select_fcmp_uge
156 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, pl
157 %1 = fcmp uge float %x, %y
158 %2 = select i1 %1, float %a, float %b
162 define float @select_fcmp_ult(float %x, float %y, float %a, float %b) {
163 ; CHECK-LABEL: select_fcmp_ult
165 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, lt
166 %1 = fcmp ult float %x, %y
167 %2 = select i1 %1, float %a, float %b
172 define float @select_fcmp_ule(float %x, float %y, float %a, float %b) {
173 ; CHECK-LABEL: select_fcmp_ule
175 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, le
176 %1 = fcmp ule float %x, %y
177 %2 = select i1 %1, float %a, float %b
181 define float @select_fcmp_une(float %x, float %y, float %a, float %b) {
182 ; CHECK-LABEL: select_fcmp_une
184 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s2, s3, ne
185 %1 = fcmp une float %x, %y
186 %2 = select i1 %1, float %a, float %b
190 define float @select_fcmp_true(float %x, float %a, float %b) {
191 ; CHECK-LABEL: select_fcmp_true
192 ; CHECK: mov.16b {{v[0-9]+}}, v1
193 %1 = fcmp ueq float %x, %x
194 %2 = select i1 %1, float %a, float %b
198 define float @select_icmp_eq(i32 %x, i32 %y, float %a, float %b) {
199 ; CHECK-LABEL: select_icmp_eq
201 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, eq
202 %1 = icmp eq i32 %x, %y
203 %2 = select i1 %1, float %a, float %b
207 define float @select_icmp_ne(i32 %x, i32 %y, float %a, float %b) {
208 ; CHECK-LABEL: select_icmp_ne
210 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, ne
211 %1 = icmp ne i32 %x, %y
212 %2 = select i1 %1, float %a, float %b
216 define float @select_icmp_ugt(i32 %x, i32 %y, float %a, float %b) {
217 ; CHECK-LABEL: select_icmp_ugt
219 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, hi
220 %1 = icmp ugt i32 %x, %y
221 %2 = select i1 %1, float %a, float %b
225 define float @select_icmp_uge(i32 %x, i32 %y, float %a, float %b) {
226 ; CHECK-LABEL: select_icmp_uge
228 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, hs
229 %1 = icmp uge i32 %x, %y
230 %2 = select i1 %1, float %a, float %b
234 define float @select_icmp_ult(i32 %x, i32 %y, float %a, float %b) {
235 ; CHECK-LABEL: select_icmp_ult
237 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, lo
238 %1 = icmp ult i32 %x, %y
239 %2 = select i1 %1, float %a, float %b
243 define float @select_icmp_ule(i32 %x, i32 %y, float %a, float %b) {
244 ; CHECK-LABEL: select_icmp_ule
246 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, ls
247 %1 = icmp ule i32 %x, %y
248 %2 = select i1 %1, float %a, float %b
252 define float @select_icmp_sgt(i32 %x, i32 %y, float %a, float %b) {
253 ; CHECK-LABEL: select_icmp_sgt
255 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, gt
256 %1 = icmp sgt i32 %x, %y
257 %2 = select i1 %1, float %a, float %b
261 define float @select_icmp_sge(i32 %x, i32 %y, float %a, float %b) {
262 ; CHECK-LABEL: select_icmp_sge
264 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, ge
265 %1 = icmp sge i32 %x, %y
266 %2 = select i1 %1, float %a, float %b
270 define float @select_icmp_slt(i32 %x, i32 %y, float %a, float %b) {
271 ; CHECK-LABEL: select_icmp_slt
273 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, lt
274 %1 = icmp slt i32 %x, %y
275 %2 = select i1 %1, float %a, float %b
279 define float @select_icmp_sle(i32 %x, i32 %y, float %a, float %b) {
280 ; CHECK-LABEL: select_icmp_sle
282 ; CHECK-NEXT: fcsel {{s[0-9]+}}, s0, s1, le
283 %1 = icmp sle i32 %x, %y
284 %2 = select i1 %1, float %a, float %b
288 ; Test peephole optimizations for select.
289 define zeroext i1 @select_opt1(i1 zeroext %c, i1 zeroext %a) {
290 ; CHECK-LABEL: select_opt1
291 ; CHECK: orr {{w[0-9]+}}, w0, w1
292 %1 = select i1 %c, i1 true, i1 %a
296 define zeroext i1 @select_opt2(i1 zeroext %c, i1 zeroext %a) {
297 ; CHECK-LABEL: select_opt2
298 ; CHECK: eor [[REG:w[0-9]+]], w0, #0x1
299 ; CHECK: orr {{w[0-9]+}}, [[REG]], w1
300 %1 = select i1 %c, i1 %a, i1 true
304 define zeroext i1 @select_opt3(i1 zeroext %c, i1 zeroext %a) {
305 ; CHECK-LABEL: select_opt3
306 ; CHECK: bic {{w[0-9]+}}, w1, w0
307 %1 = select i1 %c, i1 false, i1 %a
311 define zeroext i1 @select_opt4(i1 zeroext %c, i1 zeroext %a) {
312 ; CHECK-LABEL: select_opt4
313 ; CHECK: and {{w[0-9]+}}, w0, w1
314 %1 = select i1 %c, i1 %a, i1 false