1; RUN: llc < %s -mtriple=i386-apple-darwin10 -mcpu=penryn | FileCheck %s
2
3; rdar://7475489
4
5define i32 @test1(i32 %a, i32 %b) nounwind ssp {
6entry:
7; CHECK-LABEL: test1:
8; CHECK: xorb
9; CHECK-NOT: andb
10; CHECK-NOT: shrb
11; CHECK: testb $64
12  %0 = and i32 %a, 16384
13  %1 = icmp ne i32 %0, 0
14  %2 = and i32 %b, 16384
15  %3 = icmp ne i32 %2, 0
16  %4 = xor i1 %1, %3
17  br i1 %4, label %bb1, label %bb
18
19bb:                                               ; preds = %entry
20  %5 = tail call i32 (...)* @foo() nounwind       ; <i32> [#uses=1]
21  ret i32 %5
22
23bb1:                                              ; preds = %entry
24  %6 = tail call i32 (...)* @bar() nounwind       ; <i32> [#uses=1]
25  ret i32 %6
26}
27
28declare i32 @foo(...)
29
30declare i32 @bar(...)
31
32
33
34; PR3351 - (P == 0) & (Q == 0) -> (P|Q) == 0
35define i32 @test2(i32* %P, i32* %Q) nounwind ssp {
36entry:
37  %a = icmp eq i32* %P, null                    ; <i1> [#uses=1]
38  %b = icmp eq i32* %Q, null                    ; <i1> [#uses=1]
39  %c = and i1 %a, %b
40  br i1 %c, label %bb1, label %return
41
42bb1:                                              ; preds = %entry
43  ret i32 4
44
45return:                                           ; preds = %entry
46  ret i32 192
47; CHECK-LABEL: test2:
48; CHECK:	movl	4(%esp), %eax
49; CHECK-NEXT:	orl	8(%esp), %eax
50; CHECK-NEXT:	jne	LBB1_2
51}
52
53; PR3351 - (P != 0) | (Q != 0) -> (P|Q) != 0
54define i32 @test3(i32* %P, i32* %Q) nounwind ssp {
55entry:
56  %a = icmp ne i32* %P, null                    ; <i1> [#uses=1]
57  %b = icmp ne i32* %Q, null                    ; <i1> [#uses=1]
58  %c = or i1 %a, %b
59  br i1 %c, label %bb1, label %return
60
61bb1:                                              ; preds = %entry
62  ret i32 4
63
64return:                                           ; preds = %entry
65  ret i32 192
66; CHECK-LABEL: test3:
67; CHECK:	movl	4(%esp), %eax
68; CHECK-NEXT:	orl	8(%esp), %eax
69; CHECK-NEXT:	je	LBB2_2
70}
71
72; <rdar://problem/7598384>:
73;
74;    jCC  L1
75;    jmp  L2
76; L1:
77;   ...
78; L2:
79;   ...
80;
81; to:
82;
83;    jnCC L2
84; L1:
85;   ...
86; L2:
87;   ...
88define float @test4(float %x, float %y) nounwind readnone optsize ssp {
89entry:
90  %0 = fpext float %x to double                   ; <double> [#uses=1]
91  %1 = fpext float %y to double                   ; <double> [#uses=1]
92  %2 = fmul double %0, %1                         ; <double> [#uses=3]
93  %3 = fcmp oeq double %2, 0.000000e+00           ; <i1> [#uses=1]
94  br i1 %3, label %bb2, label %bb1
95
96; CHECK:      jne
97; CHECK-NEXT: jnp
98; CHECK-NOT:  jmp
99; CHECK:      LBB
100
101bb1:                                              ; preds = %entry
102  %4 = fadd double %2, -1.000000e+00              ; <double> [#uses=1]
103  br label %bb2
104
105bb2:                                              ; preds = %entry, %bb1
106  %.0.in = phi double [ %4, %bb1 ], [ %2, %entry ] ; <double> [#uses=1]
107  %.0 = fptrunc double %.0.in to float            ; <float> [#uses=1]
108  ret float %.0
109}
110
111declare i32 @llvm.x86.sse41.ptestz(<4 x float> %p1, <4 x float> %p2) nounwind
112declare i32 @llvm.x86.sse41.ptestc(<4 x float> %p1, <4 x float> %p2) nounwind
113
114define <4 x float> @test5(<4 x float> %a, <4 x float> %b) nounwind {
115entry:
116; CHECK-LABEL: test5:
117; CHECK: ptest
118; CHECK-NEXT:	jne
119; CHECK: ret
120
121  %res = call i32 @llvm.x86.sse41.ptestz(<4 x float> %a, <4 x float> %a) nounwind
122  %one = icmp ne i32 %res, 0
123  br i1 %one, label %bb1, label %bb2
124
125bb1:
126  %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
127  br label %return
128
129bb2:
130	%d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
131	br label %return
132
133return:
134  %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
135  ret <4 x float> %e
136}
137
138define <4 x float> @test7(<4 x float> %a, <4 x float> %b) nounwind {
139entry:
140; CHECK-LABEL: test7:
141; CHECK: ptest
142; CHECK-NEXT:	jne
143; CHECK: ret
144
145  %res = call i32 @llvm.x86.sse41.ptestz(<4 x float> %a, <4 x float> %a) nounwind
146  %one = trunc i32 %res to i1
147  br i1 %one, label %bb1, label %bb2
148
149bb1:
150  %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
151  br label %return
152
153bb2:
154	%d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
155	br label %return
156
157return:
158  %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
159  ret <4 x float> %e
160}
161
162define <4 x float> @test8(<4 x float> %a, <4 x float> %b) nounwind {
163entry:
164; CHECK-LABEL: test8:
165; CHECK: ptest
166; CHECK-NEXT:	jae
167; CHECK: ret
168
169  %res = call i32 @llvm.x86.sse41.ptestc(<4 x float> %a, <4 x float> %a) nounwind
170  %one = icmp ne i32 %res, 0
171  br i1 %one, label %bb1, label %bb2
172
173bb1:
174  %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
175  br label %return
176
177bb2:
178	%d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
179	br label %return
180
181return:
182  %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
183  ret <4 x float> %e
184}
185
186define <4 x float> @test10(<4 x float> %a, <4 x float> %b) nounwind {
187entry:
188; CHECK-LABEL: test10:
189; CHECK: ptest
190; CHECK-NEXT:	jae
191; CHECK: ret
192
193  %res = call i32 @llvm.x86.sse41.ptestc(<4 x float> %a, <4 x float> %a) nounwind
194  %one = trunc i32 %res to i1
195  br i1 %one, label %bb1, label %bb2
196
197bb1:
198  %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
199  br label %return
200
201bb2:
202	%d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
203	br label %return
204
205return:
206  %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
207  ret <4 x float> %e
208}
209
210define <4 x float> @test11(<4 x float> %a, <4 x float> %b) nounwind {
211entry:
212; CHECK-LABEL: test11:
213; CHECK: ptest
214; CHECK-NEXT:	jne
215; CHECK: ret
216
217  %res = call i32 @llvm.x86.sse41.ptestz(<4 x float> %a, <4 x float> %a) nounwind
218  %one = icmp eq i32 %res, 1
219  br i1 %one, label %bb1, label %bb2
220
221bb1:
222  %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
223  br label %return
224
225bb2:
226	%d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
227	br label %return
228
229return:
230  %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
231  ret <4 x float> %e
232}
233
234define <4 x float> @test12(<4 x float> %a, <4 x float> %b) nounwind {
235entry:
236; CHECK-LABEL: test12:
237; CHECK: ptest
238; CHECK-NEXT:	je
239; CHECK: ret
240
241  %res = call i32 @llvm.x86.sse41.ptestz(<4 x float> %a, <4 x float> %a) nounwind
242  %one = icmp ne i32 %res, 1
243  br i1 %one, label %bb1, label %bb2
244
245bb1:
246  %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
247  br label %return
248
249bb2:
250	%d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
251	br label %return
252
253return:
254  %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
255  ret <4 x float> %e
256}
257
258