1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s --check-prefixes=CHECK,CHECK-SD
; RUN: llc < %s -mtriple=aarch64-unknown-unknown -global-isel | FileCheck %s --check-prefixes=CHECK,CHECK-GI
; Compare if negative and select of constants where one constant is zero.
define i32 @neg_sel_constants(i32 %a) {
; CHECK-SD-LABEL: neg_sel_constants:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: mov w8, #5 // =0x5
; CHECK-SD-NEXT: and w0, w8, w0, asr #31
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: neg_sel_constants:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: mov w8, #5 // =0x5
; CHECK-GI-NEXT: cmp w0, #0
; CHECK-GI-NEXT: csel w0, w8, wzr, lt
; CHECK-GI-NEXT: ret
%tmp.1 = icmp slt i32 %a, 0
%retval = select i1 %tmp.1, i32 5, i32 0
ret i32 %retval
}
; Compare if negative and select of constants where one constant is zero and the other is a single bit.
define i32 @neg_sel_special_constant(i32 %a) {
; CHECK-SD-LABEL: neg_sel_special_constant:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: lsr w8, w0, #22
; CHECK-SD-NEXT: and w0, w8, #0x200
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: neg_sel_special_constant:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: cmp w0, #0
; CHECK-GI-NEXT: cset w8, lt
; CHECK-GI-NEXT: lsl w0, w8, #9
; CHECK-GI-NEXT: ret
%tmp.1 = icmp slt i32 %a, 0
%retval = select i1 %tmp.1, i32 512, i32 0
ret i32 %retval
}
; Compare if negative and select variable or zero.
define i32 @neg_sel_variable_and_zero(i32 %a, i32 %b) {
; CHECK-SD-LABEL: neg_sel_variable_and_zero:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: and w0, w1, w0, asr #31
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: neg_sel_variable_and_zero:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: cmp w0, #0
; CHECK-GI-NEXT: csel w0, w1, wzr, lt
; CHECK-GI-NEXT: ret
%tmp.1 = icmp slt i32 %a, 0
%retval = select i1 %tmp.1, i32 %b, i32 0
ret i32 %retval
}
; Compare if not positive and select the same variable as being compared: smin(a, 0).
define i32 @not_pos_sel_same_variable(i32 %a) {
; CHECK-SD-LABEL: not_pos_sel_same_variable:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: and w0, w0, w0, asr #31
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: not_pos_sel_same_variable:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: cmp w0, #1
; CHECK-GI-NEXT: csel w0, w0, wzr, lt
; CHECK-GI-NEXT: ret
%tmp = icmp slt i32 %a, 1
%min = select i1 %tmp, i32 %a, i32 0
ret i32 %min
}
; Flipping the comparison condition can be handled by getting the bitwise not of the sign mask.
; Compare if positive and select of constants where one constant is zero.
define i32 @pos_sel_constants(i32 %a) {
; CHECK-SD-LABEL: pos_sel_constants:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: mov w8, #5 // =0x5
; CHECK-SD-NEXT: bic w0, w8, w0, asr #31
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: pos_sel_constants:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: mov w8, #5 // =0x5
; CHECK-GI-NEXT: cmp w0, #0
; CHECK-GI-NEXT: csel w0, w8, wzr, ge
; CHECK-GI-NEXT: ret
%tmp.1 = icmp sgt i32 %a, -1
%retval = select i1 %tmp.1, i32 5, i32 0
ret i32 %retval
}
; Compare if positive and select of constants where one constant is zero and the other is a single bit.
define i32 @pos_sel_special_constant(i32 %a) {
; CHECK-SD-LABEL: pos_sel_special_constant:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: mov w8, #512 // =0x200
; CHECK-SD-NEXT: bic w0, w8, w0, lsr #22
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: pos_sel_special_constant:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: cmp w0, #0
; CHECK-GI-NEXT: cset w8, ge
; CHECK-GI-NEXT: lsl w0, w8, #9
; CHECK-GI-NEXT: ret
%tmp.1 = icmp sgt i32 %a, -1
%retval = select i1 %tmp.1, i32 512, i32 0
ret i32 %retval
}
; Compare if positive and select variable or zero.
define i32 @pos_sel_variable_and_zero(i32 %a, i32 %b) {
; CHECK-SD-LABEL: pos_sel_variable_and_zero:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: bic w0, w1, w0, asr #31
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: pos_sel_variable_and_zero:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: cmp w0, #0
; CHECK-GI-NEXT: csel w0, w1, wzr, ge
; CHECK-GI-NEXT: ret
%tmp.1 = icmp sgt i32 %a, -1
%retval = select i1 %tmp.1, i32 %b, i32 0
ret i32 %retval
}
; Compare if not negative or zero and select the same variable as being compared: smax(a, 0).
define i32 @not_neg_sel_same_variable(i32 %a) {
; CHECK-SD-LABEL: not_neg_sel_same_variable:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: bic w0, w0, w0, asr #31
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: not_neg_sel_same_variable:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: cmp w0, #0
; CHECK-GI-NEXT: csel w0, w0, wzr, gt
; CHECK-GI-NEXT: ret
%tmp = icmp sgt i32 %a, 0
%min = select i1 %tmp, i32 %a, i32 0
ret i32 %min
}
; https://llvm.org/bugs/show_bug.cgi?id=31175
; ret = (x-y) > 0 ? x-y : 0
define i32 @PR31175(i32 %x, i32 %y) {
; CHECK-SD-LABEL: PR31175:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: sub w8, w0, w1
; CHECK-SD-NEXT: bic w0, w8, w8, asr #31
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: PR31175:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: subs w8, w0, w1
; CHECK-GI-NEXT: csel w0, w8, wzr, gt
; CHECK-GI-NEXT: ret
%sub = sub nsw i32 %x, %y
%cmp = icmp sgt i32 %sub, 0
%sel = select i1 %cmp, i32 %sub, i32 0
ret i32 %sel
}
define i8 @sel_shift_bool_i8(i1 %t) {
; CHECK-SD-LABEL: sel_shift_bool_i8:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: mov w8, #-128 // =0xffffff80
; CHECK-SD-NEXT: tst w0, #0x1
; CHECK-SD-NEXT: csel w0, w8, wzr, ne
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_i8:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: lsl w0, w0, #7
; CHECK-GI-NEXT: ret
%shl = select i1 %t, i8 128, i8 0
ret i8 %shl
}
define i16 @sel_shift_bool_i16(i1 %t) {
; CHECK-SD-LABEL: sel_shift_bool_i16:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: mov w8, #128 // =0x80
; CHECK-SD-NEXT: tst w0, #0x1
; CHECK-SD-NEXT: csel w0, w8, wzr, ne
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_i16:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: and w8, w0, #0x1
; CHECK-GI-NEXT: lsl w0, w8, #7
; CHECK-GI-NEXT: ret
%shl = select i1 %t, i16 128, i16 0
ret i16 %shl
}
define i32 @sel_shift_bool_i32(i1 %t) {
; CHECK-SD-LABEL: sel_shift_bool_i32:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: mov w8, #64 // =0x40
; CHECK-SD-NEXT: tst w0, #0x1
; CHECK-SD-NEXT: csel w0, w8, wzr, ne
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_i32:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: and w8, w0, #0x1
; CHECK-GI-NEXT: lsl w0, w8, #6
; CHECK-GI-NEXT: ret
%shl = select i1 %t, i32 64, i32 0
ret i32 %shl
}
define i64 @sel_shift_bool_i64(i1 %t) {
; CHECK-SD-LABEL: sel_shift_bool_i64:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: mov w8, #65536 // =0x10000
; CHECK-SD-NEXT: tst w0, #0x1
; CHECK-SD-NEXT: csel x0, x8, xzr, ne
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_i64:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: // kill: def $w0 killed $w0 def $x0
; CHECK-GI-NEXT: and x8, x0, #0x1
; CHECK-GI-NEXT: lsl x0, x8, #16
; CHECK-GI-NEXT: ret
%shl = select i1 %t, i64 65536, i64 0
ret i64 %shl
}
define <16 x i8> @sel_shift_bool_v16i8(<16 x i1> %t) {
; CHECK-SD-LABEL: sel_shift_bool_v16i8:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: shl v0.16b, v0.16b, #7
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_v16i8:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: shl v0.16b, v0.16b, #7
; CHECK-GI-NEXT: movi v1.16b, #128
; CHECK-GI-NEXT: sshr v0.16b, v0.16b, #7
; CHECK-GI-NEXT: and v0.16b, v1.16b, v0.16b
; CHECK-GI-NEXT: ret
%shl = select <16 x i1> %t, <16 x i8> <i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128>, <16 x i8> zeroinitializer
ret <16 x i8> %shl
}
define <8 x i16> @sel_shift_bool_v8i16(<8 x i1> %t) {
; CHECK-SD-LABEL: sel_shift_bool_v8i16:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: ushll v0.8h, v0.8b, #0
; CHECK-SD-NEXT: movi v1.8h, #128
; CHECK-SD-NEXT: shl v0.8h, v0.8h, #15
; CHECK-SD-NEXT: cmlt v0.8h, v0.8h, #0
; CHECK-SD-NEXT: and v0.16b, v0.16b, v1.16b
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_v8i16:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: ushll v0.8h, v0.8b, #0
; CHECK-GI-NEXT: movi v1.8h, #128
; CHECK-GI-NEXT: shl v0.8h, v0.8h, #15
; CHECK-GI-NEXT: sshr v0.8h, v0.8h, #15
; CHECK-GI-NEXT: and v0.16b, v1.16b, v0.16b
; CHECK-GI-NEXT: ret
%shl= select <8 x i1> %t, <8 x i16> <i16 128, i16 128, i16 128, i16 128, i16 128, i16 128, i16 128, i16 128>, <8 x i16> zeroinitializer
ret <8 x i16> %shl
}
define <4 x i32> @sel_shift_bool_v4i32(<4 x i1> %t) {
; CHECK-SD-LABEL: sel_shift_bool_v4i32:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: ushll v0.4s, v0.4h, #0
; CHECK-SD-NEXT: movi v1.4s, #64
; CHECK-SD-NEXT: shl v0.4s, v0.4s, #31
; CHECK-SD-NEXT: cmlt v0.4s, v0.4s, #0
; CHECK-SD-NEXT: and v0.16b, v0.16b, v1.16b
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_v4i32:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: ushll v0.4s, v0.4h, #0
; CHECK-GI-NEXT: movi v1.4s, #64
; CHECK-GI-NEXT: shl v0.4s, v0.4s, #31
; CHECK-GI-NEXT: sshr v0.4s, v0.4s, #31
; CHECK-GI-NEXT: and v0.16b, v1.16b, v0.16b
; CHECK-GI-NEXT: ret
%shl = select <4 x i1> %t, <4 x i32> <i32 64, i32 64, i32 64, i32 64>, <4 x i32> zeroinitializer
ret <4 x i32> %shl
}
define <2 x i64> @sel_shift_bool_v2i64(<2 x i1> %t) {
; CHECK-SD-LABEL: sel_shift_bool_v2i64:
; CHECK-SD: // %bb.0:
; CHECK-SD-NEXT: ushll v0.2d, v0.2s, #0
; CHECK-SD-NEXT: mov w8, #65536 // =0x10000
; CHECK-SD-NEXT: dup v1.2d, x8
; CHECK-SD-NEXT: shl v0.2d, v0.2d, #63
; CHECK-SD-NEXT: cmlt v0.2d, v0.2d, #0
; CHECK-SD-NEXT: and v0.16b, v0.16b, v1.16b
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: sel_shift_bool_v2i64:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: ushll v0.2d, v0.2s, #0
; CHECK-GI-NEXT: adrp x8, .LCPI16_0
; CHECK-GI-NEXT: ldr q1, [x8, :lo12:.LCPI16_0]
; CHECK-GI-NEXT: shl v0.2d, v0.2d, #63
; CHECK-GI-NEXT: sshr v0.2d, v0.2d, #63
; CHECK-GI-NEXT: and v0.16b, v1.16b, v0.16b
; CHECK-GI-NEXT: ret
%shl = select <2 x i1> %t, <2 x i64> <i64 65536, i64 65536>, <2 x i64> zeroinitializer
ret <2 x i64> %shl
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK: {{.*}}
|