1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin10 -mcpu=generic | FileCheck %s
2 ; RUN: llc < %s -mtriple=x86_64-apple-darwin10 -mcpu=atom | FileCheck -check-prefix=ATOM %s
7 define i32 @test1(%0* %p, %0* %q, i1 %r) nounwind {
10 %t4 = select i1 %r, %0 %t0, %0 %t1
11 %t5 = extractvalue %0 %t4, 1
14 ; CHECK: cmovneq %rdi, %rsi
15 ; CHECK: movl (%rsi), %eax
18 ; ATOM: cmovneq %rdi, %rsi
19 ; ATOM: movl (%rsi), %eax
24 define i32 @test2() nounwind {
26 %tmp73 = tail call i1 @return_false() ; <i8> [#uses=1]
27 %g.0 = select i1 %tmp73, i16 0, i16 -480 ; <i16> [#uses=2]
28 %tmp7778 = sext i16 %g.0 to i32 ; <i32> [#uses=1]
29 %tmp80 = shl i32 %tmp7778, 3 ; <i32> [#uses=2]
30 %tmp87 = icmp sgt i32 %tmp80, 32767 ; <i1> [#uses=1]
31 br i1 %tmp87, label %bb90, label %bb91
32 bb90: ; preds = %bb84, %bb72
45 declare i1 @return_false()
48 ;; Select between two floating point constants.
49 define float @test3(i32 %x) nounwind readnone {
51 %0 = icmp eq i32 %x, 0 ; <i1> [#uses=1]
52 %iftmp.0.0 = select i1 %0, float 4.200000e+01, float 2.300000e+01 ; <float> [#uses=1]
55 ; CHECK: movss {{.*}},4), %xmm0
58 ; ATOM: movss {{.*}},4), %xmm0
61 define signext i8 @test4(i8* nocapture %P, double %F) nounwind readonly {
63 %0 = fcmp olt double %F, 4.200000e+01 ; <i1> [#uses=1]
64 %iftmp.0.0 = select i1 %0, i32 4, i32 0 ; <i32> [#uses=1]
65 %1 = getelementptr i8* %P, i32 %iftmp.0.0 ; <i8*> [#uses=1]
66 %2 = load i8* %1, align 1 ; <i8> [#uses=1]
69 ; CHECK: movsbl ({{.*}},4), %eax
72 ; ATOM: movsbl ({{.*}},4), %eax
75 define void @test5(i1 %c, <2 x i16> %a, <2 x i16> %b, <2 x i16>* %p) nounwind {
76 %x = select i1 %c, <2 x i16> %a, <2 x i16> %b
77 store <2 x i16> %x, <2 x i16>* %p
84 define void @test6(i32 %C, <4 x float>* %A, <4 x float>* %B) nounwind {
85 %tmp = load <4 x float>* %A ; <<4 x float>> [#uses=1]
86 %tmp3 = load <4 x float>* %B ; <<4 x float>> [#uses=2]
87 %tmp9 = fmul <4 x float> %tmp3, %tmp3 ; <<4 x float>> [#uses=1]
88 %tmp.upgrd.1 = icmp eq i32 %C, 0 ; <i1> [#uses=1]
89 %iftmp.38.0 = select i1 %tmp.upgrd.1, <4 x float> %tmp9, <4 x float> %tmp ; <<4 x float>> [#uses=1]
90 store <4 x float> %iftmp.38.0, <4 x float>* %A
92 ; Verify that the fmul gets sunk into the one part of the diamond where it is
108 define x86_fp80 @test7(i32 %tmp8) nounwind {
109 %tmp9 = icmp sgt i32 %tmp8, -1 ; <i1> [#uses=1]
110 %retval = select i1 %tmp9, x86_fp80 0xK4005B400000000000000, x86_fp80 0xK40078700000000000000
112 ; CHECK-LABEL: test7:
114 ; CHECK: fldt (%r{{.}}x,%r{{.}}x)
118 ; ATOM: fldt (%r{{.}}x,%r{{.}}x)
121 ; widening select v6i32 and then a sub
122 define void @test8(i1 %c, <6 x i32>* %dst.addr, <6 x i32> %src1,<6 x i32> %src2) nounwind {
123 %x = select i1 %c, <6 x i32> %src1, <6 x i32> %src2
124 %val = sub <6 x i32> %x, < i32 1, i32 1, i32 1, i32 1, i32 1, i32 1 >
125 store <6 x i32> %val, <6 x i32>* %dst.addr
128 ; CHECK-LABEL: test8:
134 ;; Test integer select between values and constants.
136 define i64 @test9(i64 %x, i64 %y) nounwind readnone ssp noredzone {
137 %cmp = icmp ne i64 %x, 0
138 %cond = select i1 %cmp, i64 %y, i64 -1
140 ; CHECK-LABEL: test9:
141 ; CHECK: cmpq $1, %rdi
142 ; CHECK: sbbq %rax, %rax
143 ; CHECK: orq %rsi, %rax
147 ; ATOM: cmpq $1, %rdi
148 ; ATOM: sbbq %rax, %rax
149 ; ATOM: orq %rsi, %rax
154 define i64 @test9a(i64 %x, i64 %y) nounwind readnone ssp noredzone {
155 %cmp = icmp eq i64 %x, 0
156 %cond = select i1 %cmp, i64 -1, i64 %y
158 ; CHECK-LABEL: test9a:
159 ; CHECK: cmpq $1, %rdi
160 ; CHECK: sbbq %rax, %rax
161 ; CHECK: orq %rsi, %rax
164 ; ATOM-LABEL: test9a:
165 ; ATOM: cmpq $1, %rdi
166 ; ATOM: sbbq %rax, %rax
167 ; ATOM: orq %rsi, %rax
171 define i64 @test9b(i64 %x, i64 %y) nounwind readnone ssp noredzone {
172 %cmp = icmp eq i64 %x, 0
173 %A = sext i1 %cmp to i64
174 %cond = or i64 %y, %A
176 ; CHECK-LABEL: test9b:
177 ; CHECK: cmpq $1, %rdi
178 ; CHECK: sbbq %rax, %rax
179 ; CHECK: orq %rsi, %rax
182 ; ATOM-LABEL: test9b:
183 ; ATOM: cmpq $1, %rdi
184 ; ATOM: sbbq %rax, %rax
185 ; ATOM: orq %rsi, %rax
189 ;; Select between -1 and 1.
190 define i64 @test10(i64 %x, i64 %y) nounwind readnone ssp noredzone {
191 %cmp = icmp eq i64 %x, 0
192 %cond = select i1 %cmp, i64 -1, i64 1
194 ; CHECK-LABEL: test10:
195 ; CHECK: cmpq $1, %rdi
196 ; CHECK: sbbq %rax, %rax
197 ; CHECK: orq $1, %rax
200 ; ATOM-LABEL: test10:
201 ; ATOM: cmpq $1, %rdi
202 ; ATOM: sbbq %rax, %rax
209 define i64 @test11(i64 %x, i64 %y) nounwind readnone ssp noredzone {
210 %cmp = icmp eq i64 %x, 0
211 %cond = select i1 %cmp, i64 %y, i64 -1
213 ; CHECK-LABEL: test11:
214 ; CHECK: cmpq $1, %rdi
215 ; CHECK: sbbq %rax, %rax
217 ; CHECK: orq %rsi, %rax
220 ; ATOM-LABEL: test11:
221 ; ATOM: cmpq $1, %rdi
222 ; ATOM: sbbq %rax, %rax
224 ; ATOM: orq %rsi, %rax
228 define i64 @test11a(i64 %x, i64 %y) nounwind readnone ssp noredzone {
229 %cmp = icmp ne i64 %x, 0
230 %cond = select i1 %cmp, i64 -1, i64 %y
232 ; CHECK-LABEL: test11a:
233 ; CHECK: cmpq $1, %rdi
234 ; CHECK: sbbq %rax, %rax
236 ; CHECK: orq %rsi, %rax
239 ; ATOM-LABEL: test11a:
240 ; ATOM: cmpq $1, %rdi
241 ; ATOM: sbbq %rax, %rax
243 ; ATOM: orq %rsi, %rax
248 declare noalias i8* @_Znam(i64) noredzone
250 define noalias i8* @test12(i64 %count) nounwind ssp noredzone {
252 %A = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %count, i64 4)
253 %B = extractvalue { i64, i1 } %A, 1
254 %C = extractvalue { i64, i1 } %A, 0
255 %D = select i1 %B, i64 -1, i64 %C
256 %call = tail call noalias i8* @_Znam(i64 %D) nounwind noredzone
258 ; CHECK-LABEL: test12:
260 ; CHECK: movq $-1, %[[R:r..]]
261 ; CHECK: cmovnoq %rax, %[[R]]
264 ; ATOM-LABEL: test12:
266 ; ATOM: movq $-1, %rdi
267 ; ATOM: cmovnoq %rax, %rdi
271 declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) nounwind readnone
273 define i32 @test13(i32 %a, i32 %b) nounwind {
274 %c = icmp ult i32 %a, %b
275 %d = sext i1 %c to i32
277 ; CHECK-LABEL: test13:
282 ; ATOM-LABEL: test13:
288 define i32 @test14(i32 %a, i32 %b) nounwind {
289 %c = icmp uge i32 %a, %b
290 %d = sext i1 %c to i32
292 ; CHECK-LABEL: test14:
298 ; ATOM-LABEL: test14:
306 define i32 @test15(i32 %x) nounwind {
308 %cmp = icmp ne i32 %x, 0
309 %sub = sext i1 %cmp to i32
311 ; CHECK-LABEL: test15:
315 ; ATOM-LABEL: test15:
320 define i64 @test16(i64 %x) nounwind uwtable readnone ssp {
322 %cmp = icmp ne i64 %x, 0
323 %conv1 = sext i1 %cmp to i64
325 ; CHECK-LABEL: test16:
329 ; ATOM-LABEL: test16:
334 define i16 @test17(i16 %x) nounwind {
336 %cmp = icmp ne i16 %x, 0
337 %sub = sext i1 %cmp to i16
339 ; CHECK-LABEL: test17:
343 ; ATOM-LABEL: test17:
348 define i8 @test18(i32 %x, i8 zeroext %a, i8 zeroext %b) nounwind {
349 %cmp = icmp slt i32 %x, 15
350 %sel = select i1 %cmp, i8 %a, i8 %b
352 ; CHECK-LABEL: test18:
353 ; CHECK: cmpl $15, %edi
354 ; CHECK: cmovgel %edx
356 ; ATOM-LABEL: test18:
357 ; ATOM: cmpl $15, %edi