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_cndmask_b32 31; GCN: v_cndmask_b32 32; GCN: v_cndmask_b32 33; GCN: v_cndmask_b32 34; GCN: v_cndmask_b32 35; GCN: v_cndmask_b32 36; GCN: v_cndmask_b32 37; GCN: buffer_store_dword v 38define 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 47 ret void 48} 49 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 53; GCN-NOT: [[VAL]] 54; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]] 55; GCN-NOT: [[VVAL]] 56; GCN: buffer_store_dword [[VVAL]] 57define 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 66 ret void 67} 68 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 72; GCN-NOT: [[VAL]] 73; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]] 74; GCN-NOT: [[VVAL]] 75; GCN: buffer_store_dword [[VVAL]] 76define 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 85 ret void 86} 87 88attributes #0 = { nounwind readnone } 89attributes #1 = { nounwind } 90