1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-pc-linux -mattr=+bmi,+lzcnt | FileCheck %s
4 ; LZCNT and TZCNT will always produce the operand size when the input operand
5 ; is zero. This test is to verify that we efficiently select LZCNT/TZCNT
6 ; based on the fact that the 'icmp+select' sequence is always redundant
7 ; in every function defined below.
10 define i16 @test1_ctlz(i16 %v) {
11 ; CHECK-LABEL: test1_ctlz:
13 ; CHECK-NEXT: lzcntw %di, %ax
15 %cnt = tail call i16 @llvm.ctlz.i16(i16 %v, i1 true)
16 %tobool = icmp eq i16 %v, 0
17 %cond = select i1 %tobool, i16 16, i16 %cnt
22 define i32 @test2_ctlz(i32 %v) {
23 ; CHECK-LABEL: test2_ctlz:
25 ; CHECK-NEXT: lzcntl %edi, %eax
27 %cnt = tail call i32 @llvm.ctlz.i32(i32 %v, i1 true)
28 %tobool = icmp eq i32 %v, 0
29 %cond = select i1 %tobool, i32 32, i32 %cnt
34 define i64 @test3_ctlz(i64 %v) {
35 ; CHECK-LABEL: test3_ctlz:
37 ; CHECK-NEXT: lzcntq %rdi, %rax
39 %cnt = tail call i64 @llvm.ctlz.i64(i64 %v, i1 true)
40 %tobool = icmp eq i64 %v, 0
41 %cond = select i1 %tobool, i64 64, i64 %cnt
46 define i16 @test4_ctlz(i16 %v) {
47 ; CHECK-LABEL: test4_ctlz:
49 ; CHECK-NEXT: lzcntw %di, %ax
51 %cnt = tail call i16 @llvm.ctlz.i16(i16 %v, i1 true)
52 %tobool = icmp eq i16 0, %v
53 %cond = select i1 %tobool, i16 16, i16 %cnt
58 define i32 @test5_ctlz(i32 %v) {
59 ; CHECK-LABEL: test5_ctlz:
61 ; CHECK-NEXT: lzcntl %edi, %eax
63 %cnt = tail call i32 @llvm.ctlz.i32(i32 %v, i1 true)
64 %tobool = icmp eq i32 0, %v
65 %cond = select i1 %tobool, i32 32, i32 %cnt
70 define i64 @test6_ctlz(i64 %v) {
71 ; CHECK-LABEL: test6_ctlz:
73 ; CHECK-NEXT: lzcntq %rdi, %rax
75 %cnt = tail call i64 @llvm.ctlz.i64(i64 %v, i1 true)
76 %tobool = icmp eq i64 0, %v
77 %cond = select i1 %tobool, i64 64, i64 %cnt
82 define i16 @test10_ctlz(ptr %ptr) {
83 ; CHECK-LABEL: test10_ctlz:
85 ; CHECK-NEXT: lzcntw (%rdi), %ax
87 %v = load i16, ptr %ptr
88 %cnt = tail call i16 @llvm.ctlz.i16(i16 %v, i1 true)
89 %tobool = icmp eq i16 %v, 0
90 %cond = select i1 %tobool, i16 16, i16 %cnt
95 define i32 @test11_ctlz(ptr %ptr) {
96 ; CHECK-LABEL: test11_ctlz:
98 ; CHECK-NEXT: lzcntl (%rdi), %eax
100 %v = load i32, ptr %ptr
101 %cnt = tail call i32 @llvm.ctlz.i32(i32 %v, i1 true)
102 %tobool = icmp eq i32 %v, 0
103 %cond = select i1 %tobool, i32 32, i32 %cnt
108 define i64 @test12_ctlz(ptr %ptr) {
109 ; CHECK-LABEL: test12_ctlz:
111 ; CHECK-NEXT: lzcntq (%rdi), %rax
113 %v = load i64, ptr %ptr
114 %cnt = tail call i64 @llvm.ctlz.i64(i64 %v, i1 true)
115 %tobool = icmp eq i64 %v, 0
116 %cond = select i1 %tobool, i64 64, i64 %cnt
121 define i16 @test13_ctlz(ptr %ptr) {
122 ; CHECK-LABEL: test13_ctlz:
124 ; CHECK-NEXT: lzcntw (%rdi), %ax
126 %v = load i16, ptr %ptr
127 %cnt = tail call i16 @llvm.ctlz.i16(i16 %v, i1 true)
128 %tobool = icmp eq i16 0, %v
129 %cond = select i1 %tobool, i16 16, i16 %cnt
134 define i32 @test14_ctlz(ptr %ptr) {
135 ; CHECK-LABEL: test14_ctlz:
137 ; CHECK-NEXT: lzcntl (%rdi), %eax
139 %v = load i32, ptr %ptr
140 %cnt = tail call i32 @llvm.ctlz.i32(i32 %v, i1 true)
141 %tobool = icmp eq i32 0, %v
142 %cond = select i1 %tobool, i32 32, i32 %cnt
147 define i64 @test15_ctlz(ptr %ptr) {
148 ; CHECK-LABEL: test15_ctlz:
150 ; CHECK-NEXT: lzcntq (%rdi), %rax
152 %v = load i64, ptr %ptr
153 %cnt = tail call i64 @llvm.ctlz.i64(i64 %v, i1 true)
154 %tobool = icmp eq i64 0, %v
155 %cond = select i1 %tobool, i64 64, i64 %cnt
160 define i16 @test1_cttz(i16 %v) {
161 ; CHECK-LABEL: test1_cttz:
163 ; CHECK-NEXT: orl $65536, %edi # imm = 0x10000
164 ; CHECK-NEXT: tzcntl %edi, %eax
165 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
167 %cnt = tail call i16 @llvm.cttz.i16(i16 %v, i1 true)
168 %tobool = icmp eq i16 %v, 0
169 %cond = select i1 %tobool, i16 16, i16 %cnt
174 define i32 @test2_cttz(i32 %v) {
175 ; CHECK-LABEL: test2_cttz:
177 ; CHECK-NEXT: tzcntl %edi, %eax
179 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
180 %tobool = icmp eq i32 %v, 0
181 %cond = select i1 %tobool, i32 32, i32 %cnt
186 define i64 @test3_cttz(i64 %v) {
187 ; CHECK-LABEL: test3_cttz:
189 ; CHECK-NEXT: tzcntq %rdi, %rax
191 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
192 %tobool = icmp eq i64 %v, 0
193 %cond = select i1 %tobool, i64 64, i64 %cnt
198 define i16 @test4_cttz(i16 %v) {
199 ; CHECK-LABEL: test4_cttz:
201 ; CHECK-NEXT: orl $65536, %edi # imm = 0x10000
202 ; CHECK-NEXT: tzcntl %edi, %eax
203 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
205 %cnt = tail call i16 @llvm.cttz.i16(i16 %v, i1 true)
206 %tobool = icmp eq i16 0, %v
207 %cond = select i1 %tobool, i16 16, i16 %cnt
212 define i32 @test5_cttz(i32 %v) {
213 ; CHECK-LABEL: test5_cttz:
215 ; CHECK-NEXT: tzcntl %edi, %eax
217 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
218 %tobool = icmp eq i32 0, %v
219 %cond = select i1 %tobool, i32 32, i32 %cnt
224 define i64 @test6_cttz(i64 %v) {
225 ; CHECK-LABEL: test6_cttz:
227 ; CHECK-NEXT: tzcntq %rdi, %rax
229 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
230 %tobool = icmp eq i64 0, %v
231 %cond = select i1 %tobool, i64 64, i64 %cnt
236 define i16 @test10_cttz(ptr %ptr) {
237 ; CHECK-LABEL: test10_cttz:
239 ; CHECK-NEXT: movzwl (%rdi), %eax
240 ; CHECK-NEXT: orl $65536, %eax # imm = 0x10000
241 ; CHECK-NEXT: tzcntl %eax, %eax
242 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
244 %v = load i16, ptr %ptr
245 %cnt = tail call i16 @llvm.cttz.i16(i16 %v, i1 true)
246 %tobool = icmp eq i16 %v, 0
247 %cond = select i1 %tobool, i16 16, i16 %cnt
252 define i32 @test11_cttz(ptr %ptr) {
253 ; CHECK-LABEL: test11_cttz:
255 ; CHECK-NEXT: tzcntl (%rdi), %eax
257 %v = load i32, ptr %ptr
258 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
259 %tobool = icmp eq i32 %v, 0
260 %cond = select i1 %tobool, i32 32, i32 %cnt
265 define i64 @test12_cttz(ptr %ptr) {
266 ; CHECK-LABEL: test12_cttz:
268 ; CHECK-NEXT: tzcntq (%rdi), %rax
270 %v = load i64, ptr %ptr
271 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
272 %tobool = icmp eq i64 %v, 0
273 %cond = select i1 %tobool, i64 64, i64 %cnt
278 define i16 @test13_cttz(ptr %ptr) {
279 ; CHECK-LABEL: test13_cttz:
281 ; CHECK-NEXT: movzwl (%rdi), %eax
282 ; CHECK-NEXT: orl $65536, %eax # imm = 0x10000
283 ; CHECK-NEXT: tzcntl %eax, %eax
284 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
286 %v = load i16, ptr %ptr
287 %cnt = tail call i16 @llvm.cttz.i16(i16 %v, i1 true)
288 %tobool = icmp eq i16 0, %v
289 %cond = select i1 %tobool, i16 16, i16 %cnt
294 define i32 @test14_cttz(ptr %ptr) {
295 ; CHECK-LABEL: test14_cttz:
297 ; CHECK-NEXT: tzcntl (%rdi), %eax
299 %v = load i32, ptr %ptr
300 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
301 %tobool = icmp eq i32 0, %v
302 %cond = select i1 %tobool, i32 32, i32 %cnt
307 define i64 @test15_cttz(ptr %ptr) {
308 ; CHECK-LABEL: test15_cttz:
310 ; CHECK-NEXT: tzcntq (%rdi), %rax
312 %v = load i64, ptr %ptr
313 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
314 %tobool = icmp eq i64 0, %v
315 %cond = select i1 %tobool, i64 64, i64 %cnt
320 define i16 @test4b_ctlz(i16 %v) {
321 ; CHECK-LABEL: test4b_ctlz:
323 ; CHECK-NEXT: lzcntw %di, %ax
325 %cnt = tail call i16 @llvm.ctlz.i16(i16 %v, i1 true)
326 %tobool = icmp ne i16 %v, 0
327 %cond = select i1 %tobool, i16 %cnt, i16 16
332 define i32 @test5b_ctlz(i32 %v) {
333 ; CHECK-LABEL: test5b_ctlz:
335 ; CHECK-NEXT: lzcntl %edi, %eax
337 %cnt = tail call i32 @llvm.ctlz.i32(i32 %v, i1 true)
338 %tobool = icmp ne i32 %v, 0
339 %cond = select i1 %tobool, i32 %cnt, i32 32
344 define i64 @test6b_ctlz(i64 %v) {
345 ; CHECK-LABEL: test6b_ctlz:
347 ; CHECK-NEXT: lzcntq %rdi, %rax
349 %cnt = tail call i64 @llvm.ctlz.i64(i64 %v, i1 true)
350 %tobool = icmp ne i64 %v, 0
351 %cond = select i1 %tobool, i64 %cnt, i64 64
356 define i16 @test4b_cttz(i16 %v) {
357 ; CHECK-LABEL: test4b_cttz:
359 ; CHECK-NEXT: orl $65536, %edi # imm = 0x10000
360 ; CHECK-NEXT: tzcntl %edi, %eax
361 ; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
363 %cnt = tail call i16 @llvm.cttz.i16(i16 %v, i1 true)
364 %tobool = icmp ne i16 %v, 0
365 %cond = select i1 %tobool, i16 %cnt, i16 16
370 define i32 @test5b_cttz(i32 %v) {
371 ; CHECK-LABEL: test5b_cttz:
373 ; CHECK-NEXT: tzcntl %edi, %eax
375 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
376 %tobool = icmp ne i32 %v, 0
377 %cond = select i1 %tobool, i32 %cnt, i32 32
382 define i64 @test6b_cttz(i64 %v) {
383 ; CHECK-LABEL: test6b_cttz:
385 ; CHECK-NEXT: tzcntq %rdi, %rax
387 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
388 %tobool = icmp ne i64 %v, 0
389 %cond = select i1 %tobool, i64 %cnt, i64 64
394 declare i64 @llvm.cttz.i64(i64, i1)
395 declare i32 @llvm.cttz.i32(i32, i1)
396 declare i16 @llvm.cttz.i16(i16, i1)
397 declare i64 @llvm.ctlz.i64(i64, i1)
398 declare i32 @llvm.ctlz.i32(i32, i1)
399 declare i16 @llvm.ctlz.i16(i16, i1)