1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mattr=+bmi,+bmi2,+popcnt,+lzcnt | FileCheck %s
3 declare dso_local void @foo(i32)
4 declare dso_local void @foo32(i32)
5 declare dso_local void @foo64(i64)
7 define void @neg(i32 %x) nounwind {
10 ; CHECK-NEXT: negl %edi
11 ; CHECK-NEXT: jne foo # TAILCALL
12 ; CHECK-NEXT: # %bb.1: # %return
15 %cmp = icmp eq i32 %sub, 0
16 br i1 %cmp, label %return, label %bb
19 tail call void @foo(i32 %sub)
26 define void @sar(i32 %x) nounwind {
29 ; CHECK-NEXT: sarl %edi
30 ; CHECK-NEXT: jne foo # TAILCALL
31 ; CHECK-NEXT: # %bb.1: # %return
33 %ashr = ashr i32 %x, 1
34 %cmp = icmp eq i32 %ashr, 0
35 br i1 %cmp, label %return, label %bb
38 tail call void @foo(i32 %ashr)
45 define void @shr(i32 %x) nounwind {
48 ; CHECK-NEXT: shrl %edi
49 ; CHECK-NEXT: jne foo # TAILCALL
50 ; CHECK-NEXT: # %bb.1: # %return
52 %ashr = lshr i32 %x, 1
53 %cmp = icmp eq i32 %ashr, 0
54 br i1 %cmp, label %return, label %bb
57 tail call void @foo(i32 %ashr)
64 define void @shri(i32 %x) nounwind {
67 ; CHECK-NEXT: shrl $3, %edi
68 ; CHECK-NEXT: jne foo # TAILCALL
69 ; CHECK-NEXT: # %bb.1: # %return
71 %ashr = lshr i32 %x, 3
72 %cmp = icmp eq i32 %ashr, 0
73 br i1 %cmp, label %return, label %bb
76 tail call void @foo(i32 %ashr)
83 define void @shl(i32 %x) nounwind {
86 ; CHECK-NEXT: addl %edi, %edi
87 ; CHECK-NEXT: jne foo # TAILCALL
88 ; CHECK-NEXT: # %bb.1: # %return
91 %cmp = icmp eq i32 %shl, 0
92 br i1 %cmp, label %return, label %bb
95 tail call void @foo(i32 %shl)
102 define void @shli(i32 %x) nounwind {
105 ; CHECK-NEXT: shll $4, %edi
106 ; CHECK-NEXT: jne foo # TAILCALL
107 ; CHECK-NEXT: # %bb.1: # %return
110 %cmp = icmp eq i32 %shl, 0
111 br i1 %cmp, label %return, label %bb
114 tail call void @foo(i32 %shl)
121 define zeroext i1 @adc(i128 %x) nounwind {
124 ; CHECK-NEXT: movabsq $-9223372036854775808, %rax # imm = 0x8000000000000000
125 ; CHECK-NEXT: addq %rdi, %rax
126 ; CHECK-NEXT: adcq $0, %rsi
127 ; CHECK-NEXT: sete %al
129 %add = add i128 %x, 9223372036854775808
130 %cmp = icmp ult i128 %add, 18446744073709551616
134 define zeroext i1 @sbb(i128 %x, i128 %y) nounwind {
137 ; CHECK-NEXT: cmpq %rdx, %rdi
138 ; CHECK-NEXT: sbbq %rcx, %rsi
139 ; CHECK-NEXT: setns %al
141 %sub = sub i128 %x, %y
142 %cmp = icmp sge i128 %sub, 0
146 define void @andn(i32 %x, i32 %y) nounwind {
149 ; CHECK-NEXT: andnl %esi, %edi, %edi
150 ; CHECK-NEXT: jne foo # TAILCALL
151 ; CHECK-NEXT: # %bb.1: # %return
153 %not = xor i32 %x, -1
154 %andn = and i32 %y, %not
155 %cmp = icmp eq i32 %andn, 0
156 br i1 %cmp, label %return, label %bb
159 tail call void @foo(i32 %andn)
166 declare i32 @llvm.x86.bmi.bextr.32(i32, i32) nounwind readnone
167 define void @bextr(i32 %x, i32 %y) nounwind {
168 ; CHECK-LABEL: bextr:
170 ; CHECK-NEXT: bextrl %esi, %edi, %edi
171 ; CHECK-NEXT: jne foo # TAILCALL
172 ; CHECK-NEXT: # %bb.1: # %return
174 %bextr = tail call i32 @llvm.x86.bmi.bextr.32(i32 %x, i32 %y)
175 %cmp = icmp eq i32 %bextr, 0
176 br i1 %cmp, label %return, label %bb
179 tail call void @foo(i32 %bextr)
186 declare i32 @llvm.ctpop.i32(i32) nounwind readnone
187 define void @popcnt(i32 %x) nounwind {
188 ; CHECK-LABEL: popcnt:
190 ; CHECK-NEXT: popcntl %edi, %edi
191 ; CHECK-NEXT: jne foo # TAILCALL
192 ; CHECK-NEXT: # %bb.1: # %return
194 %popcnt = tail call i32 @llvm.ctpop.i32(i32 %x)
195 %cmp = icmp eq i32 %popcnt, 0
196 br i1 %cmp, label %return, label %bb
198 tail call void @foo(i32 %popcnt)
204 declare i64 @llvm.cttz.i64(i64, i1)
205 define i64 @testCTZ(i64 %v) nounwind {
206 ; CHECK-LABEL: testCTZ:
208 ; CHECK-NEXT: tzcntq %rdi, %rcx
209 ; CHECK-NEXT: movl $255, %eax
210 ; CHECK-NEXT: cmovaeq %rcx, %rax
212 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
213 %tobool = icmp eq i64 %v, 0
214 %cond = select i1 %tobool, i64 255, i64 %cnt
218 declare i32 @llvm.cttz.i32(i32, i1)
219 define void @testCTZ2(i32 %v) nounwind {
220 ; CHECK-LABEL: testCTZ2:
222 ; CHECK-NEXT: pushq %rbx
223 ; CHECK-NEXT: tzcntl %edi, %ebx
224 ; CHECK-NEXT: jb .LBB12_2
225 ; CHECK-NEXT: # %bb.1: # %bb
226 ; CHECK-NEXT: movl %ebx, %edi
227 ; CHECK-NEXT: callq foo
228 ; CHECK-NEXT: .LBB12_2: # %return
229 ; CHECK-NEXT: movl %ebx, %edi
230 ; CHECK-NEXT: popq %rbx
231 ; CHECK-NEXT: jmp foo32 # TAILCALL
232 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
233 %cmp = icmp eq i32 %v, 0
234 br i1 %cmp, label %return, label %bb
237 tail call void @foo(i32 %cnt)
241 tail call void @foo32(i32 %cnt)
245 define void @testCTZ3(i32 %v) nounwind {
246 ; CHECK-LABEL: testCTZ3:
248 ; CHECK-NEXT: pushq %rbx
249 ; CHECK-NEXT: tzcntl %edi, %ebx
250 ; CHECK-NEXT: jae .LBB13_2
251 ; CHECK-NEXT: # %bb.1: # %bb
252 ; CHECK-NEXT: movl %ebx, %edi
253 ; CHECK-NEXT: callq foo
254 ; CHECK-NEXT: .LBB13_2: # %return
255 ; CHECK-NEXT: movl %ebx, %edi
256 ; CHECK-NEXT: popq %rbx
257 ; CHECK-NEXT: jmp foo32 # TAILCALL
258 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
259 %cmp = icmp ne i32 %v, 0
260 br i1 %cmp, label %return, label %bb
263 tail call void @foo(i32 %cnt)
267 tail call void @foo32(i32 %cnt)
271 declare i64 @llvm.ctlz.i64(i64, i1)
272 define i64 @testCLZ(i64 %v) nounwind {
273 ; CHECK-LABEL: testCLZ:
275 ; CHECK-NEXT: lzcntq %rdi, %rcx
276 ; CHECK-NEXT: movl $255, %eax
277 ; CHECK-NEXT: cmovaeq %rcx, %rax
279 %cnt = tail call i64 @llvm.ctlz.i64(i64 %v, i1 true)
280 %tobool = icmp ne i64 %v, 0
281 %cond = select i1 %tobool, i64 %cnt, i64 255
285 declare i64 @llvm.ctpop.i64(i64)
286 define i64 @testPOPCNT(i64 %v) nounwind {
287 ; CHECK-LABEL: testPOPCNT:
289 ; CHECK-NEXT: popcntq %rdi, %rcx
290 ; CHECK-NEXT: movl $255, %eax
291 ; CHECK-NEXT: cmovneq %rcx, %rax
293 %cnt = tail call i64 @llvm.ctpop.i64(i64 %v)
294 %tobool = icmp ne i64 %v, 0
295 %cond = select i1 %tobool, i64 %cnt, i64 255