llvm.org GIT mirror llvm / e7149b9
[x86] add select-of-constant tests; NFC We're using cmov in these cases, but we could reduce to simpler ops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307859 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
1 changed file(s) with 109 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
202202 ; CHECK-NEXT: retq
203203 %sel = select i1 %cond, i32 41, i32 42
204204 ret i32 %sel
205 }
206
207 ; If the constants differ by a small multiplier, use LEA.
208 ; select Cond, C1, C2 --> add (mul (zext Cond), C1-C2), C2 --> LEA C2(Cond * (C1-C2))
209
210 define i32 @select_lea_2(i1 zeroext %cond) {
211 ; CHECK-LABEL: select_lea_2:
212 ; CHECK: # BB#0:
213 ; CHECK-NEXT: testb %dil, %dil
214 ; CHECK-NEXT: movl $-1, %ecx
215 ; CHECK-NEXT: movl $1, %eax
216 ; CHECK-NEXT: cmovnel %ecx, %eax
217 ; CHECK-NEXT: retq
218 %sel = select i1 %cond, i32 -1, i32 1
219 ret i32 %sel
220 }
221
222 define i64 @select_lea_3(i1 zeroext %cond) {
223 ; CHECK-LABEL: select_lea_3:
224 ; CHECK: # BB#0:
225 ; CHECK-NEXT: testb %dil, %dil
226 ; CHECK-NEXT: movl $1, %ecx
227 ; CHECK-NEXT: movq $-2, %rax
228 ; CHECK-NEXT: cmoveq %rcx, %rax
229 ; CHECK-NEXT: retq
230 %sel = select i1 %cond, i64 -2, i64 1
231 ret i64 %sel
232 }
233
234 define i32 @select_lea_5(i1 zeroext %cond) {
235 ; CHECK-LABEL: select_lea_5:
236 ; CHECK: # BB#0:
237 ; CHECK-NEXT: testb %dil, %dil
238 ; CHECK-NEXT: movl $-2, %ecx
239 ; CHECK-NEXT: movl $3, %eax
240 ; CHECK-NEXT: cmovnel %ecx, %eax
241 ; CHECK-NEXT: retq
242 %sel = select i1 %cond, i32 -2, i32 3
243 ret i32 %sel
244 }
245
246 define i64 @select_lea_9(i1 zeroext %cond) {
247 ; CHECK-LABEL: select_lea_9:
248 ; CHECK: # BB#0:
249 ; CHECK-NEXT: testb %dil, %dil
250 ; CHECK-NEXT: movl $2, %ecx
251 ; CHECK-NEXT: movq $-7, %rax
252 ; CHECK-NEXT: cmoveq %rcx, %rax
253 ; CHECK-NEXT: retq
254 %sel = select i1 %cond, i64 -7, i64 2
255 ret i64 %sel
256 }
257
258
259 ; If the constants differ by a large power-of-2, that can be a shift of the difference plus the smaller constant.
260 ; select Cond, C1, C2 --> add (mul (zext Cond), C1-C2), C2
261
262 define i8 @select_pow2_diff(i1 zeroext %cond) {
263 ; CHECK-LABEL: select_pow2_diff:
264 ; CHECK: # BB#0:
265 ; CHECK-NEXT: testb %dil, %dil
266 ; CHECK-NEXT: movb $19, %al
267 ; CHECK-NEXT: jne .LBB22_2
268 ; CHECK-NEXT: # BB#1:
269 ; CHECK-NEXT: movb $3, %al
270 ; CHECK-NEXT: .LBB22_2:
271 ; CHECK-NEXT: retq
272 %sel = select i1 %cond, i8 19, i8 3
273 ret i8 %sel
274 }
275
276 define i16 @select_pow2_diff_invert(i1 zeroext %cond) {
277 ; CHECK-LABEL: select_pow2_diff_invert:
278 ; CHECK: # BB#0:
279 ; CHECK-NEXT: testb %dil, %dil
280 ; CHECK-NEXT: movw $7, %cx
281 ; CHECK-NEXT: movw $71, %ax
282 ; CHECK-NEXT: cmovnew %cx, %ax
283 ; CHECK-NEXT: retq
284 %sel = select i1 %cond, i16 7, i16 71
285 ret i16 %sel
286 }
287
288 define i32 @select_pow2_diff_neg(i1 zeroext %cond) {
289 ; CHECK-LABEL: select_pow2_diff_neg:
290 ; CHECK: # BB#0:
291 ; CHECK-NEXT: testb %dil, %dil
292 ; CHECK-NEXT: movl $-9, %ecx
293 ; CHECK-NEXT: movl $-25, %eax
294 ; CHECK-NEXT: cmovnel %ecx, %eax
295 ; CHECK-NEXT: retq
296 %sel = select i1 %cond, i32 -9, i32 -25
297 ret i32 %sel
298 }
299
300 define i64 @select_pow2_diff_neg_invert(i1 zeroext %cond) {
301 ; CHECK-LABEL: select_pow2_diff_neg_invert:
302 ; CHECK: # BB#0:
303 ; CHECK-NEXT: testb %dil, %dil
304 ; CHECK-NEXT: movl $29, %ecx
305 ; CHECK-NEXT: movq $-99, %rax
306 ; CHECK-NEXT: cmoveq %rcx, %rax
307 ; CHECK-NEXT: retq
308 %sel = select i1 %cond, i64 -99, i64 29
309 ret i64 %sel
205310 }
206311
207312 ; In general, select of 2 constants could be:
262367 ; CHECK-LABEL: sel_constants_add_constant_vec:
263368 ; CHECK: # BB#0:
264369 ; CHECK-NEXT: testb $1, %dil
265 ; CHECK-NEXT: jne .LBB22_1
370 ; CHECK-NEXT: jne .LBB30_1
266371 ; CHECK-NEXT: # BB#2:
267372 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [12,13,14,15]
268373 ; CHECK-NEXT: retq
269 ; CHECK-NEXT: .LBB22_1:
374 ; CHECK-NEXT: .LBB30_1:
270375 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [4294967293,14,4,4]
271376 ; CHECK-NEXT: retq
272377 %sel = select i1 %cond, <4 x i32> , <4 x i32>
278383 ; CHECK-LABEL: sel_constants_fmul_constant_vec:
279384 ; CHECK: # BB#0:
280385 ; CHECK-NEXT: testb $1, %dil
281 ; CHECK-NEXT: jne .LBB23_1
386 ; CHECK-NEXT: jne .LBB31_1
282387 ; CHECK-NEXT: # BB#2:
283388 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [1.188300e+02,3.454000e+01]
284389 ; CHECK-NEXT: retq
285 ; CHECK-NEXT: .LBB23_1:
390 ; CHECK-NEXT: .LBB31_1:
286391 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [-2.040000e+01,3.768000e+01]
287392 ; CHECK-NEXT: retq
288393 %sel = select i1 %cond, <2 x double> , <2 x double>