1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-- | FileCheck %s --check-prefixes=X86,X86-BSR
3 ; RUN: llc < %s -mtriple=i686-- -mattr=+lzcnt,+cmov | FileCheck %s --check-prefixes=X86,X86-LZCNT
4 ; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=X64,X64-BSR
5 ; RUN: llc < %s -mtriple=x86_64-- -mattr=+lzcnt | FileCheck %s --check-prefixes=X64,X64-LZCNT
7 define i1 @lshr_ctlz_cmpeq_one_i64(i64 %in) nounwind {
8 ; X86-LABEL: lshr_ctlz_cmpeq_one_i64:
10 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
11 ; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
15 ; X64-BSR-LABEL: lshr_ctlz_cmpeq_one_i64:
17 ; X64-BSR-NEXT: testq %rdi, %rdi
18 ; X64-BSR-NEXT: je .LBB0_1
19 ; X64-BSR-NEXT: # %bb.2: # %cond.false
20 ; X64-BSR-NEXT: bsrq %rdi, %rax
21 ; X64-BSR-NEXT: xorq $63, %rax
22 ; X64-BSR-NEXT: jmp .LBB0_3
23 ; X64-BSR-NEXT: .LBB0_1:
24 ; X64-BSR-NEXT: movl $64, %eax
25 ; X64-BSR-NEXT: .LBB0_3: # %cond.end
26 ; X64-BSR-NEXT: shrq $6, %rax
27 ; X64-BSR-NEXT: cmpq $1, %rax
28 ; X64-BSR-NEXT: sete %al
31 ; X64-LZCNT-LABEL: lshr_ctlz_cmpeq_one_i64:
33 ; X64-LZCNT-NEXT: testq %rdi, %rdi
34 ; X64-LZCNT-NEXT: sete %al
35 ; X64-LZCNT-NEXT: retq
36 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 0)
37 %lshr = lshr i64 %ctlz, 6
38 %icmp = icmp eq i64 %lshr, 1
42 define i1 @lshr_ctlz_undef_cmpeq_one_i64(i64 %in) nounwind {
43 ; X86-BSR-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
45 ; X86-BSR-NEXT: xorl %eax, %eax
46 ; X86-BSR-NEXT: cmpl $0, {{[0-9]+}}(%esp)
47 ; X86-BSR-NEXT: jne .LBB1_2
48 ; X86-BSR-NEXT: # %bb.1:
49 ; X86-BSR-NEXT: bsrl {{[0-9]+}}(%esp), %eax
50 ; X86-BSR-NEXT: xorl $31, %eax
51 ; X86-BSR-NEXT: addl $32, %eax
52 ; X86-BSR-NEXT: .LBB1_2:
53 ; X86-BSR-NEXT: shrl $6, %eax
54 ; X86-BSR-NEXT: # kill: def $al killed $al killed $eax
57 ; X86-LZCNT-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
59 ; X86-LZCNT-NEXT: lzcntl {{[0-9]+}}(%esp), %ecx
60 ; X86-LZCNT-NEXT: addl $32, %ecx
61 ; X86-LZCNT-NEXT: xorl %eax, %eax
62 ; X86-LZCNT-NEXT: cmpl $0, {{[0-9]+}}(%esp)
63 ; X86-LZCNT-NEXT: cmovel %ecx, %eax
64 ; X86-LZCNT-NEXT: shrl $6, %eax
65 ; X86-LZCNT-NEXT: # kill: def $al killed $al killed $eax
66 ; X86-LZCNT-NEXT: retl
68 ; X64-BSR-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
70 ; X64-BSR-NEXT: bsrq %rdi, %rax
71 ; X64-BSR-NEXT: shrl $6, %eax
72 ; X64-BSR-NEXT: # kill: def $al killed $al killed $rax
75 ; X64-LZCNT-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
77 ; X64-LZCNT-NEXT: lzcntq %rdi, %rax
78 ; X64-LZCNT-NEXT: shrl $6, %eax
79 ; X64-LZCNT-NEXT: # kill: def $al killed $al killed $rax
80 ; X64-LZCNT-NEXT: retq
81 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 -1)
82 %lshr = lshr i64 %ctlz, 6
83 %icmp = icmp eq i64 %lshr, 1
87 define i1 @lshr_ctlz_cmpne_zero_i64(i64 %in) nounwind {
88 ; X86-LABEL: lshr_ctlz_cmpne_zero_i64:
90 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
91 ; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
95 ; X64-BSR-LABEL: lshr_ctlz_cmpne_zero_i64:
97 ; X64-BSR-NEXT: testq %rdi, %rdi
98 ; X64-BSR-NEXT: je .LBB2_1
99 ; X64-BSR-NEXT: # %bb.2: # %cond.false
100 ; X64-BSR-NEXT: bsrq %rdi, %rax
101 ; X64-BSR-NEXT: xorq $63, %rax
102 ; X64-BSR-NEXT: jmp .LBB2_3
103 ; X64-BSR-NEXT: .LBB2_1:
104 ; X64-BSR-NEXT: movl $64, %eax
105 ; X64-BSR-NEXT: .LBB2_3: # %cond.end
106 ; X64-BSR-NEXT: testq $-64, %rax
107 ; X64-BSR-NEXT: setne %al
110 ; X64-LZCNT-LABEL: lshr_ctlz_cmpne_zero_i64:
111 ; X64-LZCNT: # %bb.0:
112 ; X64-LZCNT-NEXT: testq %rdi, %rdi
113 ; X64-LZCNT-NEXT: sete %al
114 ; X64-LZCNT-NEXT: retq
115 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 0)
116 %lshr = lshr i64 %ctlz, 6
117 %icmp = icmp ne i64 %lshr, 0
121 define i1 @lshr_ctlz_undef_cmpne_zero_i64(i64 %in) nounwind {
122 ; X86-BSR-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
124 ; X86-BSR-NEXT: xorl %eax, %eax
125 ; X86-BSR-NEXT: cmpl $0, {{[0-9]+}}(%esp)
126 ; X86-BSR-NEXT: jne .LBB3_2
127 ; X86-BSR-NEXT: # %bb.1:
128 ; X86-BSR-NEXT: bsrl {{[0-9]+}}(%esp), %eax
129 ; X86-BSR-NEXT: xorl $31, %eax
130 ; X86-BSR-NEXT: addl $32, %eax
131 ; X86-BSR-NEXT: .LBB3_2:
132 ; X86-BSR-NEXT: shrl $6, %eax
133 ; X86-BSR-NEXT: # kill: def $al killed $al killed $eax
136 ; X86-LZCNT-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
137 ; X86-LZCNT: # %bb.0:
138 ; X86-LZCNT-NEXT: lzcntl {{[0-9]+}}(%esp), %ecx
139 ; X86-LZCNT-NEXT: addl $32, %ecx
140 ; X86-LZCNT-NEXT: xorl %eax, %eax
141 ; X86-LZCNT-NEXT: cmpl $0, {{[0-9]+}}(%esp)
142 ; X86-LZCNT-NEXT: cmovel %ecx, %eax
143 ; X86-LZCNT-NEXT: shrl $6, %eax
144 ; X86-LZCNT-NEXT: # kill: def $al killed $al killed $eax
145 ; X86-LZCNT-NEXT: retl
147 ; X64-BSR-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
149 ; X64-BSR-NEXT: bsrq %rdi, %rax
150 ; X64-BSR-NEXT: shrl $6, %eax
151 ; X64-BSR-NEXT: # kill: def $al killed $al killed $rax
154 ; X64-LZCNT-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
155 ; X64-LZCNT: # %bb.0:
156 ; X64-LZCNT-NEXT: lzcntq %rdi, %rax
157 ; X64-LZCNT-NEXT: shrl $6, %eax
158 ; X64-LZCNT-NEXT: # kill: def $al killed $al killed $rax
159 ; X64-LZCNT-NEXT: retq
160 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 -1)
161 %lshr = lshr i64 %ctlz, 6
162 %icmp = icmp ne i64 %lshr, 0
166 define <2 x i64> @lshr_ctlz_cmpeq_zero_v2i64(<2 x i64> %in) nounwind {
167 ; X86-LABEL: lshr_ctlz_cmpeq_zero_v2i64:
169 ; X86-NEXT: pushl %esi
170 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
171 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
172 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
173 ; X86-NEXT: xorl %ecx, %ecx
174 ; X86-NEXT: orl {{[0-9]+}}(%esp), %edx
175 ; X86-NEXT: setne %cl
176 ; X86-NEXT: negl %ecx
177 ; X86-NEXT: xorl %edx, %edx
178 ; X86-NEXT: orl {{[0-9]+}}(%esp), %esi
179 ; X86-NEXT: setne %dl
180 ; X86-NEXT: negl %edx
181 ; X86-NEXT: movl %edx, 12(%eax)
182 ; X86-NEXT: movl %edx, 8(%eax)
183 ; X86-NEXT: movl %ecx, 4(%eax)
184 ; X86-NEXT: movl %ecx, (%eax)
185 ; X86-NEXT: popl %esi
188 ; X64-LABEL: lshr_ctlz_cmpeq_zero_v2i64:
190 ; X64-NEXT: pxor %xmm1, %xmm1
191 ; X64-NEXT: pcmpeqd %xmm1, %xmm0
192 ; X64-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,0,3,2]
193 ; X64-NEXT: pand %xmm1, %xmm0
194 ; X64-NEXT: pcmpeqd %xmm1, %xmm1
195 ; X64-NEXT: pxor %xmm1, %xmm0
197 %ctlz = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %in, i1 0)
198 %lshr = lshr <2 x i64> %ctlz, <i64 6, i64 6>
199 %icmp = icmp eq <2 x i64> %lshr, zeroinitializer
200 %sext = sext <2 x i1> %icmp to <2 x i64>
204 define <2 x i64> @lshr_ctlz_cmpne_zero_v2i64(<2 x i64> %in) nounwind {
205 ; X86-LABEL: lshr_ctlz_cmpne_zero_v2i64:
207 ; X86-NEXT: pushl %esi
208 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
209 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
210 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
211 ; X86-NEXT: xorl %ecx, %ecx
212 ; X86-NEXT: orl {{[0-9]+}}(%esp), %edx
214 ; X86-NEXT: negl %ecx
215 ; X86-NEXT: xorl %edx, %edx
216 ; X86-NEXT: orl {{[0-9]+}}(%esp), %esi
218 ; X86-NEXT: negl %edx
219 ; X86-NEXT: movl %edx, 12(%eax)
220 ; X86-NEXT: movl %edx, 8(%eax)
221 ; X86-NEXT: movl %ecx, 4(%eax)
222 ; X86-NEXT: movl %ecx, (%eax)
223 ; X86-NEXT: popl %esi
226 ; X64-LABEL: lshr_ctlz_cmpne_zero_v2i64:
228 ; X64-NEXT: pxor %xmm1, %xmm1
229 ; X64-NEXT: pcmpeqd %xmm1, %xmm0
230 ; X64-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,0,3,2]
231 ; X64-NEXT: pand %xmm1, %xmm0
233 %ctlz = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %in, i1 0)
234 %lshr = lshr <2 x i64> %ctlz, <i64 6, i64 6>
235 %icmp = icmp ne <2 x i64> %lshr, zeroinitializer
236 %sext = sext <2 x i1> %icmp to <2 x i64>
240 declare i64 @llvm.ctlz.i64(i64, i1)
241 declare <2 x i64> @llvm.ctlz.v2i64(<2 x i64>, i1)