1; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=GCN -check-prefix=FUNC %s 2; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=VI -check-prefix=GCN -check-prefix=FUNC %s 3 4declare i64 @llvm.ctpop.i64(i64) nounwind readnone 5declare <2 x i64> @llvm.ctpop.v2i64(<2 x i64>) nounwind readnone 6declare <4 x i64> @llvm.ctpop.v4i64(<4 x i64>) nounwind readnone 7declare <8 x i64> @llvm.ctpop.v8i64(<8 x i64>) nounwind readnone 8declare <16 x i64> @llvm.ctpop.v16i64(<16 x i64>) nounwind readnone 9 10declare i65 @llvm.ctpop.i65(i65) nounwind readnone 11declare i128 @llvm.ctpop.i128(i128) nounwind readnone 12 13; FUNC-LABEL: {{^}}s_ctpop_i64: 14; SI: s_load_dwordx2 [[SVAL:s\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}, 0xb 15; VI: s_load_dwordx2 [[SVAL:s\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}, 0x2c 16; GCN: s_bcnt1_i32_b64 [[SRESULT:s[0-9]+]], [[SVAL]] 17; GCN: v_mov_b32_e32 [[VRESULT:v[0-9]+]], [[SRESULT]] 18; GCN: buffer_store_dword [[VRESULT]], 19; GCN: s_endpgm 20define void @s_ctpop_i64(i32 addrspace(1)* noalias %out, i64 %val) nounwind { 21 %ctpop = call i64 @llvm.ctpop.i64(i64 %val) nounwind readnone 22 %truncctpop = trunc i64 %ctpop to i32 23 store i32 %truncctpop, i32 addrspace(1)* %out, align 4 24 ret void 25} 26 27; FUNC-LABEL: {{^}}v_ctpop_i64: 28; GCN: buffer_load_dwordx2 v{{\[}}[[LOVAL:[0-9]+]]:[[HIVAL:[0-9]+]]{{\]}}, 29; GCN: v_bcnt_u32_b32_e64 [[MIDRESULT:v[0-9]+]], v[[LOVAL]], 0 30; SI-NEXT: v_bcnt_u32_b32_e32 [[RESULT:v[0-9]+]], v[[HIVAL]], [[MIDRESULT]] 31; VI-NEXT: v_bcnt_u32_b32_e64 [[RESULT:v[0-9]+]], v[[HIVAL]], [[MIDRESULT]] 32; GCN: buffer_store_dword [[RESULT]], 33; GCN: s_endpgm 34define void @v_ctpop_i64(i32 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in) nounwind { 35 %val = load i64, i64 addrspace(1)* %in, align 8 36 %ctpop = call i64 @llvm.ctpop.i64(i64 %val) nounwind readnone 37 %truncctpop = trunc i64 %ctpop to i32 38 store i32 %truncctpop, i32 addrspace(1)* %out, align 4 39 ret void 40} 41 42; FIXME: or 0 should be replaxed with copy 43; FUNC-LABEL: {{^}}v_ctpop_i64_user: 44; GCN: buffer_load_dwordx2 v{{\[}}[[LOVAL:[0-9]+]]:[[HIVAL:[0-9]+]]{{\]}}, 45; GCN: v_bcnt_u32_b32_e64 [[MIDRESULT:v[0-9]+]], v[[LOVAL]], 0 46; SI-NEXT: v_bcnt_u32_b32_e32 [[RESULT:v[0-9]+]], v[[HIVAL]], [[MIDRESULT]] 47; VI-NEXT: v_bcnt_u32_b32_e64 [[RESULT:v[0-9]+]], v[[HIVAL]], [[MIDRESULT]] 48; GCN-DAG: v_or_b32_e32 v[[RESULT_LO:[0-9]+]], s{{[0-9]+}}, [[RESULT]] 49; GCN-DAG: v_or_b32_e64 v[[RESULT_HI:[0-9]+]], 0, s{{[0-9]+}} 50; GCN: buffer_store_dwordx2 v{{\[}}[[RESULT_LO]]:[[RESULT_HI]]{{\]}} 51; GCN: s_endpgm 52define void @v_ctpop_i64_user(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in, i64 %s.val) nounwind { 53 %val = load i64, i64 addrspace(1)* %in, align 8 54 %ctpop = call i64 @llvm.ctpop.i64(i64 %val) nounwind readnone 55 %or = or i64 %ctpop, %s.val 56 store i64 %or, i64 addrspace(1)* %out 57 ret void 58} 59 60; FUNC-LABEL: {{^}}s_ctpop_v2i64: 61; GCN: s_bcnt1_i32_b64 62; GCN: s_bcnt1_i32_b64 63; GCN: s_endpgm 64define void @s_ctpop_v2i64(<2 x i32> addrspace(1)* noalias %out, <2 x i64> %val) nounwind { 65 %ctpop = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %val) nounwind readnone 66 %truncctpop = trunc <2 x i64> %ctpop to <2 x i32> 67 store <2 x i32> %truncctpop, <2 x i32> addrspace(1)* %out, align 8 68 ret void 69} 70 71; FUNC-LABEL: {{^}}s_ctpop_v4i64: 72; GCN: s_bcnt1_i32_b64 73; GCN: s_bcnt1_i32_b64 74; GCN: s_bcnt1_i32_b64 75; GCN: s_bcnt1_i32_b64 76; GCN: s_endpgm 77define void @s_ctpop_v4i64(<4 x i32> addrspace(1)* noalias %out, <4 x i64> %val) nounwind { 78 %ctpop = call <4 x i64> @llvm.ctpop.v4i64(<4 x i64> %val) nounwind readnone 79 %truncctpop = trunc <4 x i64> %ctpop to <4 x i32> 80 store <4 x i32> %truncctpop, <4 x i32> addrspace(1)* %out, align 16 81 ret void 82} 83 84; FUNC-LABEL: {{^}}v_ctpop_v2i64: 85; GCN: v_bcnt_u32_b32 86; GCN: v_bcnt_u32_b32 87; GCN: v_bcnt_u32_b32 88; GCN: v_bcnt_u32_b32 89; GCN: s_endpgm 90define void @v_ctpop_v2i64(<2 x i32> addrspace(1)* noalias %out, <2 x i64> addrspace(1)* noalias %in) nounwind { 91 %val = load <2 x i64>, <2 x i64> addrspace(1)* %in, align 16 92 %ctpop = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %val) nounwind readnone 93 %truncctpop = trunc <2 x i64> %ctpop to <2 x i32> 94 store <2 x i32> %truncctpop, <2 x i32> addrspace(1)* %out, align 8 95 ret void 96} 97 98; FUNC-LABEL: {{^}}v_ctpop_v4i64: 99; GCN: v_bcnt_u32_b32 100; GCN: v_bcnt_u32_b32 101; GCN: v_bcnt_u32_b32 102; GCN: v_bcnt_u32_b32 103; GCN: v_bcnt_u32_b32 104; GCN: v_bcnt_u32_b32 105; GCN: v_bcnt_u32_b32 106; GCN: v_bcnt_u32_b32 107; GCN: s_endpgm 108define void @v_ctpop_v4i64(<4 x i32> addrspace(1)* noalias %out, <4 x i64> addrspace(1)* noalias %in) nounwind { 109 %val = load <4 x i64>, <4 x i64> addrspace(1)* %in, align 32 110 %ctpop = call <4 x i64> @llvm.ctpop.v4i64(<4 x i64> %val) nounwind readnone 111 %truncctpop = trunc <4 x i64> %ctpop to <4 x i32> 112 store <4 x i32> %truncctpop, <4 x i32> addrspace(1)* %out, align 16 113 ret void 114} 115 116; FUNC-LABEL: {{^}}ctpop_i64_in_br: 117; SI-DAG: s_load_dwordx2 s{{\[}}[[LOVAL:[0-9]+]]:[[HIVAL:[0-9]+]]{{\]}}, s[{{[0-9]+:[0-9]+}}], 0xd 118; VI-DAG: s_load_dwordx2 s{{\[}}[[LOVAL:[0-9]+]]:[[HIVAL:[0-9]+]]{{\]}}, s[{{[0-9]+:[0-9]+}}], 0x34 119; GCN-DAG: s_bcnt1_i32_b64 [[RESULT:s[0-9]+]], {{s\[}}[[LOVAL]]:[[HIVAL]]{{\]}} 120; GCN-DAG: s_mov_b32 [[ZERO:s[0-9]+]], 0 121; GCN-DAG: v_mov_b32_e32 v[[VLO:[0-9]+]], [[RESULT]] 122; GCN-DAG: v_mov_b32_e32 v[[VHI:[0-9]+]], [[ZERO]] 123; GCN: buffer_store_dwordx2 {{v\[}}[[VLO]]:[[VHI]]{{\]}} 124; GCN: s_endpgm 125define void @ctpop_i64_in_br(i64 addrspace(1)* %out, i64 addrspace(1)* %in, i64 %ctpop_arg, i32 %cond) { 126entry: 127 %tmp0 = icmp eq i32 %cond, 0 128 br i1 %tmp0, label %if, label %else 129 130if: 131 %tmp2 = call i64 @llvm.ctpop.i64(i64 %ctpop_arg) 132 br label %endif 133 134else: 135 %tmp3 = getelementptr i64, i64 addrspace(1)* %in, i32 1 136 %tmp4 = load i64, i64 addrspace(1)* %tmp3 137 br label %endif 138 139endif: 140 %tmp5 = phi i64 [%tmp2, %if], [%tmp4, %else] 141 store i64 %tmp5, i64 addrspace(1)* %out 142 ret void 143} 144 145; FUNC-LABEL: {{^}}s_ctpop_i128: 146; GCN: s_bcnt1_i32_b64 [[SRESULT0:s[0-9]+]], 147; GCN: s_bcnt1_i32_b64 [[SRESULT1:s[0-9]+]], 148; GCN: s_add_i32 s{{[0-9]+}}, [[SRESULT1]], [[SRESULT0]] 149; GCN: s_endpgm 150define void @s_ctpop_i128(i32 addrspace(1)* noalias %out, i128 %val) nounwind { 151 %ctpop = call i128 @llvm.ctpop.i128(i128 %val) nounwind readnone 152 %truncctpop = trunc i128 %ctpop to i32 153 store i32 %truncctpop, i32 addrspace(1)* %out, align 4 154 ret void 155} 156 157; FUNC-LABEL: {{^}}s_ctpop_i65: 158; GCN: s_and_b32 159; GCN: s_bcnt1_i32_b64 [[REG0:s[0-9]+]], 160; GCN: s_bcnt1_i32_b64 [[REG1:s[0-9]+]], 161; GCN: s_add_i32 {{s[0-9]+}}, [[REG0]], [[REG1]] 162; GCN: s_endpgm 163define void @s_ctpop_i65(i32 addrspace(1)* noalias %out, i65 %val) nounwind { 164 %ctpop = call i65 @llvm.ctpop.i65(i65 %val) nounwind readnone 165 %truncctpop = trunc i65 %ctpop to i32 166 store i32 %truncctpop, i32 addrspace(1)* %out, align 4 167 ret void 168} 169 170; FIXME: Should not have extra add 171 172; FUNC-LABEL: {{^}}v_ctpop_i128: 173; GCN: buffer_load_dwordx4 v{{\[}}[[VAL0:[0-9]+]]:[[VAL3:[0-9]+]]{{\]}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0{{$}} 174 175; GCN-DAG: v_bcnt_u32_b32_e64 [[MIDRESULT0:v[0-9]+]], v{{[0-9]+}}, 0 176; GCN-DAG: v_bcnt_u32_b32{{_e32|_e64}} [[MIDRESULT1:v[0-9]+]], v[[VAL3]], [[MIDRESULT0]] 177 178; GCN-DAG: v_bcnt_u32_b32_e64 [[MIDRESULT2:v[0-9]+]], v[[VAL0]], 0 179; GCN-DAG: v_bcnt_u32_b32{{_e32|_e64}} [[MIDRESULT3:v[0-9]+]], v{{[0-9]+}}, [[MIDRESULT2]] 180 181; GCN: v_add_i32_e32 [[RESULT:v[0-9]+]], vcc, [[MIDRESULT1]], [[MIDRESULT2]] 182 183; GCN: buffer_store_dword [[RESULT]], 184; GCN: s_endpgm 185define void @v_ctpop_i128(i32 addrspace(1)* noalias %out, i128 addrspace(1)* noalias %in) nounwind { 186 %val = load i128, i128 addrspace(1)* %in, align 8 187 %ctpop = call i128 @llvm.ctpop.i128(i128 %val) nounwind readnone 188 %truncctpop = trunc i128 %ctpop to i32 189 store i32 %truncctpop, i32 addrspace(1)* %out, align 4 190 ret void 191} 192