Home | History | Annotate | Download | only in R600
      1 ; RUN: llc -march=r600 -mcpu=SI -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
      2 
      3 declare i64 @llvm.ctpop.i64(i64) nounwind readnone
      4 declare <2 x i64> @llvm.ctpop.v2i64(<2 x i64>) nounwind readnone
      5 declare <4 x i64> @llvm.ctpop.v4i64(<4 x i64>) nounwind readnone
      6 declare <8 x i64> @llvm.ctpop.v8i64(<8 x i64>) nounwind readnone
      7 declare <16 x i64> @llvm.ctpop.v16i64(<16 x i64>) nounwind readnone
      8 
      9 ; FUNC-LABEL: @s_ctpop_i64:
     10 ; SI: S_LOAD_DWORDX2 [[SVAL:s\[[0-9]+:[0-9]+\]]],
     11 ; SI: S_BCNT1_I32_B64 [[SRESULT:s[0-9]+]], [[SVAL]]
     12 ; SI: V_MOV_B32_e32 [[VRESULT:v[0-9]+]], [[SRESULT]]
     13 ; SI: BUFFER_STORE_DWORD [[VRESULT]],
     14 ; SI: S_ENDPGM
     15 define void @s_ctpop_i64(i32 addrspace(1)* noalias %out, i64 %val) nounwind {
     16   %ctpop = call i64 @llvm.ctpop.i64(i64 %val) nounwind readnone
     17   %truncctpop = trunc i64 %ctpop to i32
     18   store i32 %truncctpop, i32 addrspace(1)* %out, align 4
     19   ret void
     20 }
     21 
     22 ; FUNC-LABEL: @v_ctpop_i64:
     23 ; SI: BUFFER_LOAD_DWORDX2 v{{\[}}[[LOVAL:[0-9]+]]:[[HIVAL:[0-9]+]]{{\]}},
     24 ; SI: V_MOV_B32_e32 [[VZERO:v[0-9]+]], 0
     25 ; SI: V_BCNT_U32_B32_e32 [[MIDRESULT:v[0-9]+]], v[[LOVAL]], [[VZERO]]
     26 ; SI-NEXT: V_BCNT_U32_B32_e32 [[RESULT:v[0-9]+]], v[[HIVAL]], [[MIDRESULT]]
     27 ; SI: BUFFER_STORE_DWORD [[RESULT]],
     28 ; SI: S_ENDPGM
     29 define void @v_ctpop_i64(i32 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in) nounwind {
     30   %val = load i64 addrspace(1)* %in, align 8
     31   %ctpop = call i64 @llvm.ctpop.i64(i64 %val) nounwind readnone
     32   %truncctpop = trunc i64 %ctpop to i32
     33   store i32 %truncctpop, i32 addrspace(1)* %out, align 4
     34   ret void
     35 }
     36 
     37 ; FUNC-LABEL: @s_ctpop_v2i64:
     38 ; SI: S_BCNT1_I32_B64
     39 ; SI: S_BCNT1_I32_B64
     40 ; SI: S_ENDPGM
     41 define void @s_ctpop_v2i64(<2 x i32> addrspace(1)* noalias %out, <2 x i64> %val) nounwind {
     42   %ctpop = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %val) nounwind readnone
     43   %truncctpop = trunc <2 x i64> %ctpop to <2 x i32>
     44   store <2 x i32> %truncctpop, <2 x i32> addrspace(1)* %out, align 8
     45   ret void
     46 }
     47 
     48 ; FUNC-LABEL: @s_ctpop_v4i64:
     49 ; SI: S_BCNT1_I32_B64
     50 ; SI: S_BCNT1_I32_B64
     51 ; SI: S_BCNT1_I32_B64
     52 ; SI: S_BCNT1_I32_B64
     53 ; SI: S_ENDPGM
     54 define void @s_ctpop_v4i64(<4 x i32> addrspace(1)* noalias %out, <4 x i64> %val) nounwind {
     55   %ctpop = call <4 x i64> @llvm.ctpop.v4i64(<4 x i64> %val) nounwind readnone
     56   %truncctpop = trunc <4 x i64> %ctpop to <4 x i32>
     57   store <4 x i32> %truncctpop, <4 x i32> addrspace(1)* %out, align 16
     58   ret void
     59 }
     60 
     61 ; FUNC-LABEL: @v_ctpop_v2i64:
     62 ; SI: V_BCNT_U32_B32
     63 ; SI: V_BCNT_U32_B32
     64 ; SI: V_BCNT_U32_B32
     65 ; SI: V_BCNT_U32_B32
     66 ; SI: S_ENDPGM
     67 define void @v_ctpop_v2i64(<2 x i32> addrspace(1)* noalias %out, <2 x i64> addrspace(1)* noalias %in) nounwind {
     68   %val = load <2 x i64> addrspace(1)* %in, align 16
     69   %ctpop = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %val) nounwind readnone
     70   %truncctpop = trunc <2 x i64> %ctpop to <2 x i32>
     71   store <2 x i32> %truncctpop, <2 x i32> addrspace(1)* %out, align 8
     72   ret void
     73 }
     74 
     75 ; FUNC-LABEL: @v_ctpop_v4i64:
     76 ; SI: V_BCNT_U32_B32
     77 ; SI: V_BCNT_U32_B32
     78 ; SI: V_BCNT_U32_B32
     79 ; SI: V_BCNT_U32_B32
     80 ; SI: V_BCNT_U32_B32
     81 ; SI: V_BCNT_U32_B32
     82 ; SI: V_BCNT_U32_B32
     83 ; SI: V_BCNT_U32_B32
     84 ; SI: S_ENDPGM
     85 define void @v_ctpop_v4i64(<4 x i32> addrspace(1)* noalias %out, <4 x i64> addrspace(1)* noalias %in) nounwind {
     86   %val = load <4 x i64> addrspace(1)* %in, align 32
     87   %ctpop = call <4 x i64> @llvm.ctpop.v4i64(<4 x i64> %val) nounwind readnone
     88   %truncctpop = trunc <4 x i64> %ctpop to <4 x i32>
     89   store <4 x i32> %truncctpop, <4 x i32> addrspace(1)* %out, align 16
     90   ret void
     91 }
     92 
     93 ; FIXME: We currently disallow SALU instructions in all branches,
     94 ; but there are some cases when the should be allowed.
     95 
     96 ; FUNC-LABEL: @ctpop_i64_in_br
     97 ; SI: V_BCNT_U32_B32_e64 [[BCNT_LO:v[0-9]+]], v{{[0-9]+}}, 0
     98 ; SI: V_BCNT_U32_B32_e32 v[[BCNT:[0-9]+]], v{{[0-9]+}}, [[BCNT_LO]]
     99 ; SI: V_MOV_B32_e32 v[[ZERO:[0-9]+]], 0
    100 ; SI: BUFFER_STORE_DWORDX2 v[
    101 ; SI: [[BCNT]]:[[ZERO]]]
    102 ; SI: S_ENDPGM
    103 define void @ctpop_i64_in_br(i64 addrspace(1)* %out, i64 addrspace(1)* %in, i32 %cond) {
    104 entry:
    105   %0 = icmp eq i32 %cond, 0
    106   br i1 %0, label %if, label %else
    107 
    108 if:
    109   %1 = load i64 addrspace(1)* %in
    110   %2 = call i64 @llvm.ctpop.i64(i64 %1)
    111   br label %endif
    112 
    113 else:
    114   %3 = getelementptr i64 addrspace(1)* %in, i32 1
    115   %4 = load i64 addrspace(1)* %3
    116   br label %endif
    117 
    118 endif:
    119   %5 = phi i64 [%2, %if], [%4, %else]
    120   store i64 %5, i64 addrspace(1)* %out
    121   ret void
    122 }
    123