1; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s 2 3; Test that when extracting the same unknown vector index from an 4; insertelement the dynamic indexing is folded away. 5 6declare i32 @llvm.amdgcn.workitem.id.x() #0 7 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 12; GCN-NOT: [[VAL]] 13; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]] 14; GCN-NOT: [[VVAL]] 15; GCN: buffer_store_dword [[VVAL]] 16define 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 25 ret void 26} 27 28; GCN-LABEL: {{^}}extract_insert_different_dynelt_v4i32: 29; GCN: buffer_load_dwordx4 30; GCN: v_movreld_b32 31; GCN: v_cndmask_b32 32; GCN: v_cndmask_b32 33; GCN: v_cndmask_b32 34; GCN: buffer_store_dword v 35define 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 { 36 %id = call i32 @llvm.amdgcn.workitem.id.x() 37 %id.ext = sext i32 %id to i64 38 %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)* %in, i64 %id.ext 39 %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %id.ext 40 %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in 41 %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx0 42 %extract = extractelement <4 x i32> %insert, i32 %idx1 43 store i32 %extract, i32 addrspace(1)* %gep.out 44 ret void 45} 46 47; GCN-LABEL: {{^}}extract_insert_same_elt2_v4i32: 48; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd{{$}} 49; GCN-NOT buffer_load_dword 50; GCN-NOT: [[VAL]] 51; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]] 52; GCN-NOT: [[VVAL]] 53; GCN: buffer_store_dword [[VVAL]] 54define amdgpu_kernel void @extract_insert_same_elt2_v4i32(i32 addrspace(1)* %out, <4 x i32> addrspace(1)* %in, i32 %val, i32 %idx) #1 { 55 %id = call i32 @llvm.amdgcn.workitem.id.x() 56 %id.ext = sext i32 %id to i64 57 %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)* %in, i64 %id.ext 58 %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %id.ext 59 %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in 60 %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx 61 %extract = extractelement <4 x i32> %insert, i32 %idx 62 store i32 %extract, i32 addrspace(1)* %gep.out 63 ret void 64} 65 66; GCN-LABEL: {{^}}extract_insert_same_dynelt_v4f32: 67; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd{{$}} 68; GCN-NOT buffer_load_dword 69; GCN-NOT: [[VAL]] 70; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]] 71; GCN-NOT: [[VVAL]] 72; GCN: buffer_store_dword [[VVAL]] 73define amdgpu_kernel void @extract_insert_same_dynelt_v4f32(float addrspace(1)* %out, <4 x float> addrspace(1)* %in, float %val, i32 %idx) #1 { 74 %id = call i32 @llvm.amdgcn.workitem.id.x() 75 %id.ext = sext i32 %id to i64 76 %gep.in = getelementptr inbounds <4 x float>, <4 x float> addrspace(1)* %in, i64 %id.ext 77 %gep.out = getelementptr inbounds float, float addrspace(1)* %out, i64 %id.ext 78 %vec = load volatile <4 x float>, <4 x float> addrspace(1)* %gep.in 79 %insert = insertelement <4 x float> %vec, float %val, i32 %idx 80 %extract = extractelement <4 x float> %insert, i32 %idx 81 store float %extract, float addrspace(1)* %gep.out 82 ret void 83} 84 85attributes #0 = { nounwind readnone } 86attributes #1 = { nounwind } 87