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-LABEL: lshr_ctlz_cmpeq_one_i64:
17 ; X64-NEXT: testq %rdi, %rdi
20 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 0)
21 %lshr = lshr i64 %ctlz, 6
22 %icmp = icmp eq i64 %lshr, 1
26 define i1 @lshr_ctlz_undef_cmpeq_one_i64(i64 %in) nounwind {
27 ; X86-BSR-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
29 ; X86-BSR-NEXT: xorl %eax, %eax
32 ; X86-LZCNT-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
34 ; X86-LZCNT-NEXT: lzcntl {{[0-9]+}}(%esp), %ecx
35 ; X86-LZCNT-NEXT: addl $32, %ecx
36 ; X86-LZCNT-NEXT: xorl %eax, %eax
37 ; X86-LZCNT-NEXT: cmpl $0, {{[0-9]+}}(%esp)
38 ; X86-LZCNT-NEXT: cmovel %ecx, %eax
39 ; X86-LZCNT-NEXT: shrl $6, %eax
40 ; X86-LZCNT-NEXT: # kill: def $al killed $al killed $eax
41 ; X86-LZCNT-NEXT: retl
43 ; X64-BSR-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
45 ; X64-BSR-NEXT: xorl %eax, %eax
48 ; X64-LZCNT-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
50 ; X64-LZCNT-NEXT: lzcntq %rdi, %rax
51 ; X64-LZCNT-NEXT: shrl $6, %eax
52 ; X64-LZCNT-NEXT: # kill: def $al killed $al killed $rax
53 ; X64-LZCNT-NEXT: retq
54 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 -1)
55 %lshr = lshr i64 %ctlz, 6
56 %icmp = icmp eq i64 %lshr, 1
60 define i1 @lshr_ctlz_cmpne_zero_i64(i64 %in) nounwind {
61 ; X86-LABEL: lshr_ctlz_cmpne_zero_i64:
63 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
64 ; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
68 ; X64-LABEL: lshr_ctlz_cmpne_zero_i64:
70 ; X64-NEXT: testq %rdi, %rdi
73 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 0)
74 %lshr = lshr i64 %ctlz, 6
75 %icmp = icmp ne i64 %lshr, 0
79 define i1 @lshr_ctlz_undef_cmpne_zero_i64(i64 %in) nounwind {
80 ; X86-BSR-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
82 ; X86-BSR-NEXT: xorl %eax, %eax
85 ; X86-LZCNT-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
87 ; X86-LZCNT-NEXT: lzcntl {{[0-9]+}}(%esp), %ecx
88 ; X86-LZCNT-NEXT: addl $32, %ecx
89 ; X86-LZCNT-NEXT: xorl %eax, %eax
90 ; X86-LZCNT-NEXT: cmpl $0, {{[0-9]+}}(%esp)
91 ; X86-LZCNT-NEXT: cmovel %ecx, %eax
92 ; X86-LZCNT-NEXT: shrl $6, %eax
93 ; X86-LZCNT-NEXT: # kill: def $al killed $al killed $eax
94 ; X86-LZCNT-NEXT: retl
96 ; X64-BSR-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
98 ; X64-BSR-NEXT: xorl %eax, %eax
101 ; X64-LZCNT-LABEL: lshr_ctlz_undef_cmpne_zero_i64:
102 ; X64-LZCNT: # %bb.0:
103 ; X64-LZCNT-NEXT: lzcntq %rdi, %rax
104 ; X64-LZCNT-NEXT: shrl $6, %eax
105 ; X64-LZCNT-NEXT: # kill: def $al killed $al killed $rax
106 ; X64-LZCNT-NEXT: retq
107 %ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 -1)
108 %lshr = lshr i64 %ctlz, 6
109 %icmp = icmp ne i64 %lshr, 0
113 define <2 x i64> @lshr_ctlz_cmpeq_zero_v2i64(<2 x i64> %in) nounwind {
114 ; X86-LABEL: lshr_ctlz_cmpeq_zero_v2i64:
116 ; X86-NEXT: pushl %esi
117 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
118 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
119 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
120 ; X86-NEXT: xorl %ecx, %ecx
121 ; X86-NEXT: orl {{[0-9]+}}(%esp), %edx
122 ; X86-NEXT: setne %cl
123 ; X86-NEXT: negl %ecx
124 ; X86-NEXT: xorl %edx, %edx
125 ; X86-NEXT: orl {{[0-9]+}}(%esp), %esi
126 ; X86-NEXT: setne %dl
127 ; X86-NEXT: negl %edx
128 ; X86-NEXT: movl %edx, 12(%eax)
129 ; X86-NEXT: movl %edx, 8(%eax)
130 ; X86-NEXT: movl %ecx, 4(%eax)
131 ; X86-NEXT: movl %ecx, (%eax)
132 ; X86-NEXT: popl %esi
135 ; X64-LABEL: lshr_ctlz_cmpeq_zero_v2i64:
137 ; X64-NEXT: pxor %xmm1, %xmm1
138 ; X64-NEXT: pcmpeqd %xmm1, %xmm0
139 ; X64-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,0,3,2]
140 ; X64-NEXT: pand %xmm1, %xmm0
141 ; X64-NEXT: pcmpeqd %xmm1, %xmm1
142 ; X64-NEXT: pxor %xmm1, %xmm0
144 %ctlz = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %in, i1 0)
145 %lshr = lshr <2 x i64> %ctlz, <i64 6, i64 6>
146 %icmp = icmp eq <2 x i64> %lshr, zeroinitializer
147 %sext = sext <2 x i1> %icmp to <2 x i64>
151 define <2 x i64> @lshr_ctlz_cmpne_zero_v2i64(<2 x i64> %in) nounwind {
152 ; X86-LABEL: lshr_ctlz_cmpne_zero_v2i64:
154 ; X86-NEXT: pushl %esi
155 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
156 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
157 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
158 ; X86-NEXT: xorl %ecx, %ecx
159 ; X86-NEXT: orl {{[0-9]+}}(%esp), %edx
161 ; X86-NEXT: negl %ecx
162 ; X86-NEXT: xorl %edx, %edx
163 ; X86-NEXT: orl {{[0-9]+}}(%esp), %esi
165 ; X86-NEXT: negl %edx
166 ; X86-NEXT: movl %edx, 12(%eax)
167 ; X86-NEXT: movl %edx, 8(%eax)
168 ; X86-NEXT: movl %ecx, 4(%eax)
169 ; X86-NEXT: movl %ecx, (%eax)
170 ; X86-NEXT: popl %esi
173 ; X64-LABEL: lshr_ctlz_cmpne_zero_v2i64:
175 ; X64-NEXT: pxor %xmm1, %xmm1
176 ; X64-NEXT: pcmpeqd %xmm1, %xmm0
177 ; X64-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,0,3,2]
178 ; X64-NEXT: pand %xmm1, %xmm0
180 %ctlz = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %in, i1 0)
181 %lshr = lshr <2 x i64> %ctlz, <i64 6, i64 6>
182 %icmp = icmp ne <2 x i64> %lshr, zeroinitializer
183 %sext = sext <2 x i1> %icmp to <2 x i64>
187 declare i64 @llvm.ctlz.i64(i64, i1)
188 declare <2 x i64> @llvm.ctlz.v2i64(<2 x i64>, i1)