Peephole optimization of ptest-conditioned branch in X86 arch. Performs instruction...
[oota-llvm.git] / test / CodeGen / X86 / avx-brcond.ll
1 ; RUN: llc < %s -mtriple=i386-apple-darwin10 -mcpu=corei7-avx -mattr=+avx | FileCheck %s
2
3 declare i32 @llvm.x86.avx.ptestz.256(<4 x i64> %p1, <4 x i64> %p2) nounwind
4 declare i32 @llvm.x86.avx.ptestc.256(<4 x i64> %p1, <4 x i64> %p2) nounwind
5
6 define <4 x float> @test1(<4 x i64> %a, <4 x float> %b) nounwind {
7 entry:
8 ; CHECK: test1:
9 ; CHECK: vptest
10 ; CHECK-NEXT:   jne
11 ; CHECK: ret
12
13   %res = call i32 @llvm.x86.avx.ptestz.256(<4 x i64> %a, <4 x i64> %a) nounwind 
14   %one = icmp ne i32 %res, 0 
15   br i1 %one, label %bb1, label %bb2
16
17 bb1:
18   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
19   br label %return
20
21 bb2:
22         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
23         br label %return
24
25 return:
26   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
27   ret <4 x float> %e
28 }
29
30 define <4 x float> @test2(<4 x i64> %a, <4 x float> %b) nounwind {
31 entry:
32 ; CHECK: test2:
33 ; CHECK: vptest
34 ; CHECK-NEXT:   je
35 ; CHECK: ret
36
37   %res = call i32 @llvm.x86.avx.ptestz.256(<4 x i64> %a, <4 x i64> %a) nounwind 
38   %one = icmp eq i32 %res, 0 
39   br i1 %one, label %bb1, label %bb2
40
41 bb1:
42   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
43   br label %return
44
45 bb2:
46         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
47         br label %return
48
49 return:
50   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
51   ret <4 x float> %e
52 }
53
54 define <4 x float> @test3(<4 x i64> %a, <4 x float> %b) nounwind {
55 entry:
56 ; CHECK: test3:
57 ; CHECK: vptest
58 ; CHECK-NEXT:   jne
59 ; CHECK: ret
60
61   %res = call i32 @llvm.x86.avx.ptestz.256(<4 x i64> %a, <4 x i64> %a) nounwind 
62   %one = trunc i32 %res to i1 
63   br i1 %one, label %bb1, label %bb2
64
65 bb1:
66   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
67   br label %return
68
69 bb2:
70         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
71         br label %return
72
73 return:
74   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
75   ret <4 x float> %e
76 }
77
78 define <4 x float> @test4(<4 x i64> %a, <4 x float> %b) nounwind {
79 entry:
80 ; CHECK: test4:
81 ; CHECK: vptest
82 ; CHECK-NEXT:   jae
83 ; CHECK: ret
84
85   %res = call i32 @llvm.x86.avx.ptestc.256(<4 x i64> %a, <4 x i64> %a) nounwind 
86   %one = icmp ne i32 %res, 0 
87   br i1 %one, label %bb1, label %bb2
88
89 bb1:
90   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
91   br label %return
92
93 bb2:
94         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
95         br label %return
96
97 return:
98   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
99   ret <4 x float> %e
100 }
101
102 define <4 x float> @test5(<4 x i64> %a, <4 x float> %b) nounwind {
103 entry:
104 ; CHECK: test5:
105 ; CHECK: vptest
106 ; CHECK-NEXT:   jb
107 ; CHECK: ret
108
109   %res = call i32 @llvm.x86.avx.ptestc.256(<4 x i64> %a, <4 x i64> %a) nounwind 
110   %one = icmp eq i32 %res, 0 
111   br i1 %one, label %bb1, label %bb2
112
113 bb1:
114   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
115   br label %return
116
117 bb2:
118         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
119         br label %return
120
121 return:
122   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
123   ret <4 x float> %e
124 }
125
126 define <4 x float> @test6(<4 x i64> %a, <4 x float> %b) nounwind {
127 entry:
128 ; CHECK: test6:
129 ; CHECK: vptest
130 ; CHECK-NEXT:   jae
131 ; CHECK: ret
132
133   %res = call i32 @llvm.x86.avx.ptestc.256(<4 x i64> %a, <4 x i64> %a) nounwind 
134   %one = trunc i32 %res to i1 
135   br i1 %one, label %bb1, label %bb2
136
137 bb1:
138   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
139   br label %return
140
141 bb2:
142         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
143         br label %return
144
145 return:
146   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
147   ret <4 x float> %e
148 }
149
150 define <4 x float> @test7(<4 x i64> %a, <4 x float> %b) nounwind {
151 entry:
152 ; CHECK: test7:
153 ; CHECK: vptest
154 ; CHECK-NEXT:   jne
155 ; CHECK: ret
156
157   %res = call i32 @llvm.x86.avx.ptestz.256(<4 x i64> %a, <4 x i64> %a) nounwind 
158   %one = icmp eq i32 %res, 1 
159   br i1 %one, label %bb1, label %bb2
160
161 bb1:
162   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
163   br label %return
164
165 bb2:
166         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
167         br label %return
168
169 return:
170   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
171   ret <4 x float> %e
172 }
173
174 define <4 x float> @test8(<4 x i64> %a, <4 x float> %b) nounwind {
175 entry:
176 ; CHECK: test8:
177 ; CHECK: vptest
178 ; CHECK-NEXT:   je
179 ; CHECK: ret
180
181   %res = call i32 @llvm.x86.avx.ptestz.256(<4 x i64> %a, <4 x i64> %a) nounwind 
182   %one = icmp ne i32 %res, 1 
183   br i1 %one, label %bb1, label %bb2
184
185 bb1:
186   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
187   br label %return
188
189 bb2:
190         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
191         br label %return
192
193 return:
194   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
195   ret <4 x float> %e
196 }
197
198 define <4 x float> @test9(<4 x i64> %a, <4 x float> %b) nounwind {
199 entry:
200 ; CHECK: test9:
201 ; CHECK: vptest
202 ; CHECK-NEXT:   jae
203 ; CHECK: ret
204
205   %res = call i32 @llvm.x86.avx.ptestc.256(<4 x i64> %a, <4 x i64> %a) nounwind 
206   %one = icmp eq i32 %res, 1 
207   br i1 %one, label %bb1, label %bb2
208
209 bb1:
210   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
211   br label %return
212
213 bb2:
214         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
215         br label %return
216
217 return:
218   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
219   ret <4 x float> %e
220 }
221
222 define <4 x float> @test10(<4 x i64> %a, <4 x float> %b) nounwind {
223 entry:
224 ; CHECK: test10:
225 ; CHECK: vptest
226 ; CHECK-NEXT:   jb
227 ; CHECK: ret
228
229   %res = call i32 @llvm.x86.avx.ptestc.256(<4 x i64> %a, <4 x i64> %a) nounwind 
230   %one = icmp ne i32 %res, 1 
231   br i1 %one, label %bb1, label %bb2
232
233 bb1:
234   %c = fadd <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
235   br label %return
236
237 bb2:
238         %d = fdiv <4 x float> %b, < float 1.000000e+002, float 2.000000e+002, float 3.000000e+002, float 4.000000e+002 >
239         br label %return
240
241 return:
242   %e = phi <4 x float> [%c, %bb1], [%d, %bb2]
243   ret <4 x float> %e
244 }