1 ; RUN: llc < %s -mtriple=i386-apple-macosx -mcpu=penryn | FileCheck %s
4 ; The register+memory form of the BT instruction should be usable on
5 ; pentium4, however it is currently disabled due to the register+memory
6 ; form having different semantics than the register+register form.
9 ; (X & (1 << N)) != 0 --> BT(X, N).
10 ; ((X >>u N) & 1) != 0 --> BT(X, N).
11 ; as well as several variations:
12 ; - The second form can use an arithmetic shift.
13 ; - Either form can use == instead of !=.
14 ; - Either form can compare with an operand of the &
16 ; - The comparison can be commuted (only cases where neither
17 ; operand is constant are included).
18 ; - The and can be commuted.
20 define void @test2(i32 %x, i32 %n) nounwind {
23 ; CHECK: btl %eax, %ecx
25 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
26 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
27 %tmp4 = icmp eq i32 %tmp3, 0 ; <i1> [#uses=1]
28 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
34 UnifiedReturnBlock: ; preds = %entry
38 define void @test2b(i32 %x, i32 %n) nounwind {
41 ; CHECK: btl %e{{..}}, %e{{..}}
43 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
44 %tmp3 = and i32 1, %tmp29
45 %tmp4 = icmp eq i32 %tmp3, 0 ; <i1> [#uses=1]
46 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
52 UnifiedReturnBlock: ; preds = %entry
56 define void @atest2(i32 %x, i32 %n) nounwind {
59 ; CHECK: btl %e{{..}}, %e{{..}}
61 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
62 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
63 %tmp4 = icmp eq i32 %tmp3, 0 ; <i1> [#uses=1]
64 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
70 UnifiedReturnBlock: ; preds = %entry
74 define void @atest2b(i32 %x, i32 %n) nounwind {
77 ; CHECK: btl %e{{..}}, %e{{..}}
78 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
79 %tmp3 = and i32 1, %tmp29
80 %tmp4 = icmp eq i32 %tmp3, 0 ; <i1> [#uses=1]
81 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
87 UnifiedReturnBlock: ; preds = %entry
91 define void @test3(i32 %x, i32 %n) nounwind {
94 ; CHECK: btl %e{{..}}, %e{{..}}
96 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
97 %tmp3 = and i32 %tmp29, %x ; <i32> [#uses=1]
98 %tmp4 = icmp eq i32 %tmp3, 0 ; <i1> [#uses=1]
99 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
105 UnifiedReturnBlock: ; preds = %entry
109 define void @test3b(i32 %x, i32 %n) nounwind {
112 ; CHECK: btl %e{{..}}, %e{{..}}
114 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
115 %tmp3 = and i32 %x, %tmp29
116 %tmp4 = icmp eq i32 %tmp3, 0 ; <i1> [#uses=1]
117 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
123 UnifiedReturnBlock: ; preds = %entry
127 define void @testne2(i32 %x, i32 %n) nounwind {
130 ; CHECK: btl %e{{..}}, %e{{..}}
132 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
133 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
134 %tmp4 = icmp ne i32 %tmp3, 0 ; <i1> [#uses=1]
135 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
141 UnifiedReturnBlock: ; preds = %entry
145 define void @testne2b(i32 %x, i32 %n) nounwind {
148 ; CHECK: btl %e{{..}}, %e{{..}}
150 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
151 %tmp3 = and i32 1, %tmp29
152 %tmp4 = icmp ne i32 %tmp3, 0 ; <i1> [#uses=1]
153 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
159 UnifiedReturnBlock: ; preds = %entry
163 define void @atestne2(i32 %x, i32 %n) nounwind {
166 ; CHECK: btl %e{{..}}, %e{{..}}
168 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
169 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
170 %tmp4 = icmp ne i32 %tmp3, 0 ; <i1> [#uses=1]
171 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
177 UnifiedReturnBlock: ; preds = %entry
181 define void @atestne2b(i32 %x, i32 %n) nounwind {
184 ; CHECK: btl %e{{..}}, %e{{..}}
186 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
187 %tmp3 = and i32 1, %tmp29
188 %tmp4 = icmp ne i32 %tmp3, 0 ; <i1> [#uses=1]
189 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
195 UnifiedReturnBlock: ; preds = %entry
199 define void @testne3(i32 %x, i32 %n) nounwind {
202 ; CHECK: btl %e{{..}}, %e{{..}}
204 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
205 %tmp3 = and i32 %tmp29, %x ; <i32> [#uses=1]
206 %tmp4 = icmp ne i32 %tmp3, 0 ; <i1> [#uses=1]
207 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
213 UnifiedReturnBlock: ; preds = %entry
217 define void @testne3b(i32 %x, i32 %n) nounwind {
220 ; CHECK: btl %e{{..}}, %e{{..}}
222 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
223 %tmp3 = and i32 %x, %tmp29
224 %tmp4 = icmp ne i32 %tmp3, 0 ; <i1> [#uses=1]
225 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
231 UnifiedReturnBlock: ; preds = %entry
235 define void @query2(i32 %x, i32 %n) nounwind {
238 ; CHECK: btl %e{{..}}, %e{{..}}
240 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
241 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
242 %tmp4 = icmp eq i32 %tmp3, 1 ; <i1> [#uses=1]
243 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
249 UnifiedReturnBlock: ; preds = %entry
253 define void @query2b(i32 %x, i32 %n) nounwind {
256 ; CHECK: btl %e{{..}}, %e{{..}}
258 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
259 %tmp3 = and i32 1, %tmp29
260 %tmp4 = icmp eq i32 %tmp3, 1 ; <i1> [#uses=1]
261 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
267 UnifiedReturnBlock: ; preds = %entry
271 define void @aquery2(i32 %x, i32 %n) nounwind {
274 ; CHECK: btl %e{{..}}, %e{{..}}
276 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
277 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
278 %tmp4 = icmp eq i32 %tmp3, 1 ; <i1> [#uses=1]
279 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
285 UnifiedReturnBlock: ; preds = %entry
289 define void @aquery2b(i32 %x, i32 %n) nounwind {
292 ; CHECK: btl %e{{..}}, %e{{..}}
294 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
295 %tmp3 = and i32 1, %tmp29
296 %tmp4 = icmp eq i32 %tmp3, 1 ; <i1> [#uses=1]
297 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
303 UnifiedReturnBlock: ; preds = %entry
307 define void @query3(i32 %x, i32 %n) nounwind {
310 ; CHECK: btl %e{{..}}, %e{{..}}
312 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
313 %tmp3 = and i32 %tmp29, %x ; <i32> [#uses=1]
314 %tmp4 = icmp eq i32 %tmp3, %tmp29 ; <i1> [#uses=1]
315 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
321 UnifiedReturnBlock: ; preds = %entry
325 define void @query3b(i32 %x, i32 %n) nounwind {
328 ; CHECK: btl %e{{..}}, %e{{..}}
330 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
331 %tmp3 = and i32 %x, %tmp29
332 %tmp4 = icmp eq i32 %tmp3, %tmp29 ; <i1> [#uses=1]
333 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
339 UnifiedReturnBlock: ; preds = %entry
343 define void @query3x(i32 %x, i32 %n) nounwind {
346 ; CHECK: btl %e{{..}}, %e{{..}}
348 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
349 %tmp3 = and i32 %tmp29, %x ; <i32> [#uses=1]
350 %tmp4 = icmp eq i32 %tmp29, %tmp3 ; <i1> [#uses=1]
351 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
357 UnifiedReturnBlock: ; preds = %entry
361 define void @query3bx(i32 %x, i32 %n) nounwind {
364 ; CHECK: btl %e{{..}}, %e{{..}}
366 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
367 %tmp3 = and i32 %x, %tmp29
368 %tmp4 = icmp eq i32 %tmp29, %tmp3 ; <i1> [#uses=1]
369 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
375 UnifiedReturnBlock: ; preds = %entry
379 define void @queryne2(i32 %x, i32 %n) nounwind {
382 ; CHECK: btl %e{{..}}, %e{{..}}
384 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
385 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
386 %tmp4 = icmp ne i32 %tmp3, 1 ; <i1> [#uses=1]
387 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
393 UnifiedReturnBlock: ; preds = %entry
397 define void @queryne2b(i32 %x, i32 %n) nounwind {
400 ; CHECK: btl %e{{..}}, %e{{..}}
402 %tmp29 = lshr i32 %x, %n ; <i32> [#uses=1]
403 %tmp3 = and i32 1, %tmp29
404 %tmp4 = icmp ne i32 %tmp3, 1 ; <i1> [#uses=1]
405 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
411 UnifiedReturnBlock: ; preds = %entry
415 define void @aqueryne2(i32 %x, i32 %n) nounwind {
418 ; CHECK: btl %e{{..}}, %e{{..}}
420 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
421 %tmp3 = and i32 %tmp29, 1 ; <i32> [#uses=1]
422 %tmp4 = icmp ne i32 %tmp3, 1 ; <i1> [#uses=1]
423 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
429 UnifiedReturnBlock: ; preds = %entry
433 define void @aqueryne2b(i32 %x, i32 %n) nounwind {
436 ; CHECK: btl %e{{..}}, %e{{..}}
438 %tmp29 = ashr i32 %x, %n ; <i32> [#uses=1]
439 %tmp3 = and i32 1, %tmp29
440 %tmp4 = icmp ne i32 %tmp3, 1 ; <i1> [#uses=1]
441 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
447 UnifiedReturnBlock: ; preds = %entry
451 define void @queryne3(i32 %x, i32 %n) nounwind {
454 ; CHECK: btl %e{{..}}, %e{{..}}
456 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
457 %tmp3 = and i32 %tmp29, %x ; <i32> [#uses=1]
458 %tmp4 = icmp ne i32 %tmp3, %tmp29 ; <i1> [#uses=1]
459 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
465 UnifiedReturnBlock: ; preds = %entry
469 define void @queryne3b(i32 %x, i32 %n) nounwind {
472 ; CHECK: btl %e{{..}}, %e{{..}}
474 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
475 %tmp3 = and i32 %x, %tmp29
476 %tmp4 = icmp ne i32 %tmp3, %tmp29 ; <i1> [#uses=1]
477 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
483 UnifiedReturnBlock: ; preds = %entry
487 define void @queryne3x(i32 %x, i32 %n) nounwind {
490 ; CHECK: btl %e{{..}}, %e{{..}}
492 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
493 %tmp3 = and i32 %tmp29, %x ; <i32> [#uses=1]
494 %tmp4 = icmp ne i32 %tmp29, %tmp3 ; <i1> [#uses=1]
495 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
501 UnifiedReturnBlock: ; preds = %entry
505 define void @queryne3bx(i32 %x, i32 %n) nounwind {
508 ; CHECK: btl %e{{..}}, %e{{..}}
510 %tmp29 = shl i32 1, %n ; <i32> [#uses=1]
511 %tmp3 = and i32 %x, %tmp29
512 %tmp4 = icmp ne i32 %tmp29, %tmp3 ; <i1> [#uses=1]
513 br i1 %tmp4, label %bb, label %UnifiedReturnBlock
519 UnifiedReturnBlock: ; preds = %entry
525 define zeroext i1 @invert(i32 %flags, i32 %flag) nounwind {
528 %neg = xor i32 %flags, -1
529 %shl = shl i32 1, %flag
530 %and = and i32 %shl, %neg
531 %tobool = icmp ne i32 %and, 0