1 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
3 ; Test that when extracting the same unknown vector index from an
4 ; insertelement the dynamic indexing is folded away.
6 declare i32 @llvm.amdgcn.workitem.id.x() #0
8 ; No dynamic indexing required
9 ; GCN-LABEL: {{^}}extract_insert_same_dynelt_v4i32:
10 ; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd{{$}}
11 ; GCN-NOT buffer_load_dword
13 ; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]]
15 ; GCN: buffer_store_dword [[VVAL]]
16 define amdgpu_kernel void @extract_insert_same_dynelt_v4i32(i32 addrspace(1)* %out, <4 x i32> addrspace(1)* %in, i32 %val, i32 %idx) #1 {
17 %id = call i32 @llvm.amdgcn.workitem.id.x()
18 %id.ext = sext i32 %id to i64
19 %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)* %in, i64 %id.ext
20 %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %id.ext
21 %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in
22 %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx
23 %extract = extractelement <4 x i32> %insert, i32 %idx
24 store i32 %extract, i32 addrspace(1)* %gep.out
28 ; GCN-LABEL: {{^}}extract_insert_different_dynelt_v4i32:
29 ; GCN: buffer_load_dwordx4
37 ; GCN: buffer_store_dword v
38 define amdgpu_kernel void @extract_insert_different_dynelt_v4i32(i32 addrspace(1)* %out, <4 x i32> addrspace(1)* %in, i32 %val, i32 %idx0, i32 %idx1) #1 {
39 %id = call i32 @llvm.amdgcn.workitem.id.x()
40 %id.ext = sext i32 %id to i64
41 %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)* %in, i64 %id.ext
42 %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %id.ext
43 %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in
44 %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx0
45 %extract = extractelement <4 x i32> %insert, i32 %idx1
46 store i32 %extract, i32 addrspace(1)* %gep.out
50 ; GCN-LABEL: {{^}}extract_insert_same_elt2_v4i32:
51 ; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd{{$}}
52 ; GCN-NOT buffer_load_dword
54 ; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]]
56 ; GCN: buffer_store_dword [[VVAL]]
57 define amdgpu_kernel void @extract_insert_same_elt2_v4i32(i32 addrspace(1)* %out, <4 x i32> addrspace(1)* %in, i32 %val, i32 %idx) #1 {
58 %id = call i32 @llvm.amdgcn.workitem.id.x()
59 %id.ext = sext i32 %id to i64
60 %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)* %in, i64 %id.ext
61 %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %id.ext
62 %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in
63 %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx
64 %extract = extractelement <4 x i32> %insert, i32 %idx
65 store i32 %extract, i32 addrspace(1)* %gep.out
69 ; GCN-LABEL: {{^}}extract_insert_same_dynelt_v4f32:
70 ; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd{{$}}
71 ; GCN-NOT buffer_load_dword
73 ; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]]
75 ; GCN: buffer_store_dword [[VVAL]]
76 define amdgpu_kernel void @extract_insert_same_dynelt_v4f32(float addrspace(1)* %out, <4 x float> addrspace(1)* %in, float %val, i32 %idx) #1 {
77 %id = call i32 @llvm.amdgcn.workitem.id.x()
78 %id.ext = sext i32 %id to i64
79 %gep.in = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %in, i64 %id.ext
80 %gep.out = getelementptr inbounds float, float addrspace(1)* %out, i64 %id.ext
81 %vec = load volatile <4 x float>, <4 x float> addrspace(1)* %gep.in
82 %insert = insertelement <4 x float> %vec, float %val, i32 %idx
83 %extract = extractelement <4 x float> %insert, i32 %idx
84 store float %extract, float addrspace(1)* %gep.out
88 attributes #0 = { nounwind readnone }
89 attributes #1 = { nounwind }