Switch the lowering of CTLZ_ZERO_UNDEF from a .td pattern back to the
[oota-llvm.git] / test / CodeGen / X86 / clz.ll
1 ; RUN: llc < %s -march=x86 -mcpu=yonah | FileCheck %s
2
3 define i32 @t1(i32 %x) nounwind  {
4   %tmp = tail call i32 @llvm.ctlz.i32( i32 %x, i1 true )
5   ret i32 %tmp
6 ; CHECK: t1:
7 ; CHECK: bsrl
8 ; CHECK-NOT: cmov
9 ; CHECK: xorl $31,
10 ; CHECK: ret
11 }
12
13 declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone 
14
15 define i32 @t2(i32 %x) nounwind  {
16   %tmp = tail call i32 @llvm.cttz.i32( i32 %x, i1 true )
17   ret i32 %tmp
18 ; CHECK: t2:
19 ; CHECK: bsfl
20 ; CHECK-NOT: cmov
21 ; CHECK: ret
22 }
23
24 declare i32 @llvm.cttz.i32(i32, i1) nounwind readnone 
25
26 define i16 @t3(i16 %x, i16 %y) nounwind  {
27 entry:
28   %tmp1 = add i16 %x, %y
29   %tmp2 = tail call i16 @llvm.ctlz.i16( i16 %tmp1, i1 true )    ; <i16> [#uses=1]
30   ret i16 %tmp2
31 ; CHECK: t3:
32 ; CHECK: bsrw
33 ; CHECK-NOT: cmov
34 ; CHECK: xorl $15,
35 ; CHECK: ret
36 }
37
38 declare i16 @llvm.ctlz.i16(i16, i1) nounwind readnone 
39
40 define i32 @t4(i32 %n) nounwind {
41 entry:
42 ; Generate a cmov to handle zero inputs when necessary.
43 ; CHECK: t4:
44 ; CHECK: bsrl
45 ; CHECK: cmov
46 ; CHECK: xorl $31,
47 ; CHECK: ret
48   %tmp1 = tail call i32 @llvm.ctlz.i32(i32 %n, i1 false)
49   ret i32 %tmp1
50 }
51
52 define i32 @t5(i32 %n) nounwind {
53 entry:
54 ; Don't generate the cmovne when the source is known non-zero (and bsr would
55 ; not set ZF).
56 ; rdar://9490949
57 ; CHECK: t5:
58 ; CHECK: bsrl
59 ; CHECK-NOT: cmov
60 ; CHECK: xorl $31,
61 ; CHECK: ret
62   %or = or i32 %n, 1
63   %tmp1 = tail call i32 @llvm.ctlz.i32(i32 %or, i1 false)
64   ret i32 %tmp1
65 }
66
67 define i32 @t6(i32 %n) nounwind {
68 entry:
69 ; Don't generate any xors when a 'ctlz' intrinsic is actually used to compute
70 ; the most significant bit, which is what 'bsr' does natively.
71 ; CHECK: t6:
72 ; CHECK: bsrl
73 ; CHECK-NOT: xorl
74 ; CHECK: ret
75   %ctlz = tail call i32 @llvm.ctlz.i32(i32 %n, i1 true)
76   %bsr = xor i32 %ctlz, 31
77   ret i32 %bsr
78 }
79
80 define i32 @t7(i32 %n) nounwind {
81 entry:
82 ; Same as t6, but ensure this happens even when there is a potential zero.
83 ; CHECK: t7:
84 ; CHECK: bsrl
85 ; CHECK-NOT: xorl
86 ; CHECK: ret
87   %ctlz = tail call i32 @llvm.ctlz.i32(i32 %n, i1 false)
88   %bsr = xor i32 %ctlz, 31
89   ret i32 %bsr
90 }