1 ; RUN: llc -march=amdgcn -mcpu=SI -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
3 ; RUN: llc -march=r600 -mcpu=cypress -verify-machineinstrs < %s | FileCheck -check-prefix=EG -check-prefix=FUNC %s
5 declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
6 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32>, i1) nounwind readnone
7 declare <4 x i32> @llvm.ctlz.v4i32(<4 x i32>, i1) nounwind readnone
9 declare i64 @llvm.ctlz.i64(i64, i1) nounwind readnone
10 declare <2 x i64> @llvm.ctlz.v2i64(<2 x i64>, i1) nounwind readnone
11 declare <4 x i64> @llvm.ctlz.v4i64(<4 x i64>, i1) nounwind readnone
13 declare i32 @llvm.r600.read.tidig.x() nounwind readnone
15 ; FUNC-LABEL: {{^}}s_ctlz_i32:
16 ; SI: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, {{0xb|0x2c}}
17 ; SI-DAG: s_flbit_i32_b32 [[CTLZ:s[0-9]+]], [[VAL]]
18 ; SI-DAG: v_cmp_eq_i32_e64 [[CMPZ:s\[[0-9]+:[0-9]+\]]], 0, [[VAL]]
19 ; SI-DAG: v_mov_b32_e32 [[VCTLZ:v[0-9]+]], [[CTLZ]]
20 ; SI: v_cndmask_b32_e64 [[RESULT:v[0-9]+]], [[VCTLZ]], 32, [[CMPZ]]
21 ; SI: buffer_store_dword [[RESULT]]
26 define void @s_ctlz_i32(i32 addrspace(1)* noalias %out, i32 %val) nounwind {
27 %ctlz = call i32 @llvm.ctlz.i32(i32 %val, i1 false) nounwind readnone
28 store i32 %ctlz, i32 addrspace(1)* %out, align 4
32 ; FUNC-LABEL: {{^}}v_ctlz_i32:
33 ; SI: buffer_load_dword [[VAL:v[0-9]+]],
34 ; SI-DAG: v_ffbh_u32_e32 [[CTLZ:v[0-9]+]], [[VAL]]
35 ; SI-DAG: v_cmp_eq_i32_e32 vcc, 0, [[CTLZ]]
36 ; SI: v_cndmask_b32_e64 [[RESULT:v[0-9]+]], [[CTLZ]], 32, vcc
37 ; SI: buffer_store_dword [[RESULT]],
42 define void @v_ctlz_i32(i32 addrspace(1)* noalias %out, i32 addrspace(1)* noalias %valptr) nounwind {
43 %val = load i32, i32 addrspace(1)* %valptr, align 4
44 %ctlz = call i32 @llvm.ctlz.i32(i32 %val, i1 false) nounwind readnone
45 store i32 %ctlz, i32 addrspace(1)* %out, align 4
49 ; FUNC-LABEL: {{^}}v_ctlz_v2i32:
50 ; SI: buffer_load_dwordx2
53 ; SI: buffer_store_dwordx2
60 define void @v_ctlz_v2i32(<2 x i32> addrspace(1)* noalias %out, <2 x i32> addrspace(1)* noalias %valptr) nounwind {
61 %val = load <2 x i32>, <2 x i32> addrspace(1)* %valptr, align 8
62 %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %val, i1 false) nounwind readnone
63 store <2 x i32> %ctlz, <2 x i32> addrspace(1)* %out, align 8
67 ; FUNC-LABEL: {{^}}v_ctlz_v4i32:
68 ; SI: buffer_load_dwordx4
73 ; SI: buffer_store_dwordx4
88 define void @v_ctlz_v4i32(<4 x i32> addrspace(1)* noalias %out, <4 x i32> addrspace(1)* noalias %valptr) nounwind {
89 %val = load <4 x i32>, <4 x i32> addrspace(1)* %valptr, align 16
90 %ctlz = call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %val, i1 false) nounwind readnone
91 store <4 x i32> %ctlz, <4 x i32> addrspace(1)* %out, align 16
95 ; FUNC-LABEL: {{^}}s_ctlz_i64:
96 define void @s_ctlz_i64(i64 addrspace(1)* noalias %out, i64 %val) nounwind {
97 %ctlz = call i64 @llvm.ctlz.i64(i64 %val, i1 false)
98 store i64 %ctlz, i64 addrspace(1)* %out
102 ; FUNC-LABEL: {{^}}s_ctlz_i64_trunc:
103 define void @s_ctlz_i64_trunc(i32 addrspace(1)* noalias %out, i64 %val) nounwind {
104 %ctlz = call i64 @llvm.ctlz.i64(i64 %val, i1 false)
105 %trunc = trunc i64 %ctlz to i32
106 store i32 %trunc, i32 addrspace(1)* %out
110 ; FUNC-LABEL: {{^}}v_ctlz_i64:
111 define void @v_ctlz_i64(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in) nounwind {
112 %tid = call i32 @llvm.r600.read.tidig.x()
113 %in.gep = getelementptr i64, i64 addrspace(1)* %in, i32 %tid
114 %out.gep = getelementptr i64, i64 addrspace(1)* %out, i32 %tid
115 %val = load i64, i64 addrspace(1)* %in.gep
116 %ctlz = call i64 @llvm.ctlz.i64(i64 %val, i1 false)
117 store i64 %ctlz, i64 addrspace(1)* %out.gep
121 ; FUNC-LABEL: {{^}}v_ctlz_i64_trunc:
122 define void @v_ctlz_i64_trunc(i32 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in) nounwind {
123 %tid = call i32 @llvm.r600.read.tidig.x()
124 %in.gep = getelementptr i64, i64 addrspace(1)* %in, i32 %tid
125 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
126 %val = load i64, i64 addrspace(1)* %in.gep
127 %ctlz = call i64 @llvm.ctlz.i64(i64 %val, i1 false)
128 %trunc = trunc i64 %ctlz to i32
129 store i32 %trunc, i32 addrspace(1)* %out.gep