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: testl $-64, %eax
54 ; X86-BSR-NEXT: setne %al
57 ; X86-LZCNT-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
59 ; X86-LZCNT-NEXT: lzcntl {{[0-9]+}}(%esp), %eax
60 ; X86-LZCNT-NEXT: addl $32, %eax
61 ; X86-LZCNT-NEXT: xorl %ecx, %ecx
62 ; X86-LZCNT-NEXT: cmpl $0, {{[0-9]+}}(%esp)
63 ; X86-LZCNT-NEXT: cmovel %eax, %ecx
64 ; X86-LZCNT-NEXT: testb $64, %cl
65 ; X86-LZCNT-NEXT: setne %al
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: cmpl $1, %eax
73 ; X64-BSR-NEXT: sete %al
76 ; X64-LZCNT-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
78 ; X64-LZCNT-NEXT: lzcntq %rdi, %rax
79 ; X64-LZCNT-NEXT: shrl $6, %eax
80 ; X64-LZCNT-NEXT: cmpl $1, %eax
81 ; X64-LZCNT-NEXT: sete %al
82 ; X64-LZCNT-NEXT: retq
83 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 -1)
84 %lshr = lshr i64 %ctlz, 6
85 %icmp = icmp eq i64 %lshr, 1
89 define i1 @lshr_ctlz_cmpne_zero_i64(i64 %in) nounwind {
90 ; X86-LABEL: lshr_ctlz_cmpne_zero_i64:
92 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
93 ; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
97 ; X64-BSR-LABEL: lshr_ctlz_cmpne_zero_i64:
99 ; X64-BSR-NEXT: testq %rdi, %rdi
100 ; X64-BSR-NEXT: je .LBB2_1
101 ; X64-BSR-NEXT: # %bb.2: # %cond.false
102 ; X64-BSR-NEXT: bsrq %rdi, %rax
103 ; X64-BSR-NEXT: xorq $63, %rax
104 ; X64-BSR-NEXT: jmp .LBB2_3
105 ; X64-BSR-NEXT: .LBB2_1:
106 ; X64-BSR-NEXT: movl $64, %eax
107 ; X64-BSR-NEXT: .LBB2_3: # %cond.end
108 ; X64-BSR-NEXT: testq $-64, %rax
109 ; X64-BSR-NEXT: setne %al
112 ; X64-LZCNT-LABEL: lshr_ctlz_cmpne_zero_i64:
113 ; X64-LZCNT: # %bb.0:
114 ; X64-LZCNT-NEXT: testq %rdi, %rdi
115 ; X64-LZCNT-NEXT: sete %al
116 ; X64-LZCNT-NEXT: retq
117 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 0)
118 %lshr = lshr i64 %ctlz, 6
119 %icmp = icmp ne i64 %lshr, 0
123 define i1 @lshr_ctlz_undef_cmpne_zero_i64(i64 %in) nounwind {
124 ; X86-BSR-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
126 ; X86-BSR-NEXT: xorl %eax, %eax
127 ; X86-BSR-NEXT: cmpl $0, {{[0-9]+}}(%esp)
128 ; X86-BSR-NEXT: jne .LBB3_2
129 ; X86-BSR-NEXT: # %bb.1:
130 ; X86-BSR-NEXT: bsrl {{[0-9]+}}(%esp), %eax
131 ; X86-BSR-NEXT: xorl $31, %eax
132 ; X86-BSR-NEXT: addl $32, %eax
133 ; X86-BSR-NEXT: .LBB3_2:
134 ; X86-BSR-NEXT: testl $-64, %eax
135 ; X86-BSR-NEXT: setne %al
138 ; X86-LZCNT-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
139 ; X86-LZCNT: # %bb.0:
140 ; X86-LZCNT-NEXT: lzcntl {{[0-9]+}}(%esp), %eax
141 ; X86-LZCNT-NEXT: addl $32, %eax
142 ; X86-LZCNT-NEXT: xorl %ecx, %ecx
143 ; X86-LZCNT-NEXT: cmpl $0, {{[0-9]+}}(%esp)
144 ; X86-LZCNT-NEXT: cmovel %eax, %ecx
145 ; X86-LZCNT-NEXT: testb $64, %cl
146 ; X86-LZCNT-NEXT: setne %al
147 ; X86-LZCNT-NEXT: retl
149 ; X64-BSR-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
151 ; X64-BSR-NEXT: bsrq %rdi, %rax
152 ; X64-BSR-NEXT: testl $-64, %eax
153 ; X64-BSR-NEXT: setne %al
156 ; X64-LZCNT-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
157 ; X64-LZCNT: # %bb.0:
158 ; X64-LZCNT-NEXT: lzcntq %rdi, %rax
159 ; X64-LZCNT-NEXT: testb $64, %al
160 ; X64-LZCNT-NEXT: setne %al
161 ; X64-LZCNT-NEXT: retq
162 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 -1)
163 %lshr = lshr i64 %ctlz, 6
164 %icmp = icmp ne i64 %lshr, 0
168 define <2 x i64> @lshr_ctlz_cmpeq_zero_v2i64(<2 x i64> %in) nounwind {
169 ; X86-LABEL: lshr_ctlz_cmpeq_zero_v2i64:
171 ; X86-NEXT: pushl %esi
172 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
173 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
174 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
175 ; X86-NEXT: xorl %ecx, %ecx
176 ; X86-NEXT: orl {{[0-9]+}}(%esp), %edx
177 ; X86-NEXT: setne %cl
178 ; X86-NEXT: negl %ecx
179 ; X86-NEXT: xorl %edx, %edx
180 ; X86-NEXT: orl {{[0-9]+}}(%esp), %esi
181 ; X86-NEXT: setne %dl
182 ; X86-NEXT: negl %edx
183 ; X86-NEXT: movl %edx, 12(%eax)
184 ; X86-NEXT: movl %edx, 8(%eax)
185 ; X86-NEXT: movl %ecx, 4(%eax)
186 ; X86-NEXT: movl %ecx, (%eax)
187 ; X86-NEXT: popl %esi
190 ; X64-LABEL: lshr_ctlz_cmpeq_zero_v2i64:
192 ; X64-NEXT: pxor %xmm1, %xmm1
193 ; X64-NEXT: pcmpeqd %xmm1, %xmm0
194 ; X64-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,0,3,2]
195 ; X64-NEXT: pand %xmm1, %xmm0
196 ; X64-NEXT: pcmpeqd %xmm1, %xmm1
197 ; X64-NEXT: pxor %xmm1, %xmm0
199 %ctlz = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %in, i1 0)
200 %lshr = lshr <2 x i64> %ctlz, <i64 6, i64 6>
201 %icmp = icmp eq <2 x i64> %lshr, zeroinitializer
202 %sext = sext <2 x i1> %icmp to <2 x i64>
206 define <2 x i64> @lshr_ctlz_cmpne_zero_v2i64(<2 x i64> %in) nounwind {
207 ; X86-LABEL: lshr_ctlz_cmpne_zero_v2i64:
209 ; X86-NEXT: pushl %esi
210 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
211 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
212 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
213 ; X86-NEXT: xorl %ecx, %ecx
214 ; X86-NEXT: orl {{[0-9]+}}(%esp), %edx
216 ; X86-NEXT: negl %ecx
217 ; X86-NEXT: xorl %edx, %edx
218 ; X86-NEXT: orl {{[0-9]+}}(%esp), %esi
220 ; X86-NEXT: negl %edx
221 ; X86-NEXT: movl %edx, 12(%eax)
222 ; X86-NEXT: movl %edx, 8(%eax)
223 ; X86-NEXT: movl %ecx, 4(%eax)
224 ; X86-NEXT: movl %ecx, (%eax)
225 ; X86-NEXT: popl %esi
228 ; X64-LABEL: lshr_ctlz_cmpne_zero_v2i64:
230 ; X64-NEXT: pxor %xmm1, %xmm1
231 ; X64-NEXT: pcmpeqd %xmm1, %xmm0
232 ; X64-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,0,3,2]
233 ; X64-NEXT: pand %xmm1, %xmm0
235 %ctlz = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %in, i1 0)
236 %lshr = lshr <2 x i64> %ctlz, <i64 6, i64 6>
237 %icmp = icmp ne <2 x i64> %lshr, zeroinitializer
238 %sext = sext <2 x i1> %icmp to <2 x i64>
242 declare i64 @llvm.ctlz.i64(i64, i1)
243 declare <2 x i64> @llvm.ctlz.v2i64(<2 x i64>, i1)