1*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -march=amdgcn < %s | FileCheck -check-prefix=GCN %s 2*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -march=amdgcn -mcpu=tonga < %s | FileCheck -check-prefix=GCN %s 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Worker; When a frame index offset is more than 12-bits, make sure we don't store 5*9880d681SAndroid Build Coastguard Worker; it in mubuf's offset field. 6*9880d681SAndroid Build Coastguard Worker 7*9880d681SAndroid Build Coastguard Worker; Also, make sure we use the same register for storing the scratch buffer addresss 8*9880d681SAndroid Build Coastguard Worker; for both stores. This register is allocated by the register scavenger, so we 9*9880d681SAndroid Build Coastguard Worker; should be able to reuse the same regiser for each scratch buffer access. 10*9880d681SAndroid Build Coastguard Worker 11*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}legal_offset_fi: 12*9880d681SAndroid Build Coastguard Worker; GCN: v_mov_b32_e32 [[OFFSET:v[0-9]+]], 0{{$}} 13*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword v{{[0-9]+}}, [[OFFSET]], s[{{[0-9]+}}:{{[0-9]+}}], s{{[0-9]+}} offen 14*9880d681SAndroid Build Coastguard Worker; GCN: v_mov_b32_e32 [[OFFSET]], 0x8000 15*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword v{{[0-9]+}}, [[OFFSET]], s[{{[0-9]+}}:{{[0-9]+}}], s{{[0-9]+}} offen{{$}} 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Workerdefine void @legal_offset_fi(i32 addrspace(1)* %out, i32 %cond, i32 %if_offset, i32 %else_offset) { 18*9880d681SAndroid Build Coastguard Workerentry: 19*9880d681SAndroid Build Coastguard Worker %scratch0 = alloca [8192 x i32] 20*9880d681SAndroid Build Coastguard Worker %scratch1 = alloca [8192 x i32] 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Worker %scratchptr0 = getelementptr [8192 x i32], [8192 x i32]* %scratch0, i32 0, i32 0 23*9880d681SAndroid Build Coastguard Worker store i32 1, i32* %scratchptr0 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker %scratchptr1 = getelementptr [8192 x i32], [8192 x i32]* %scratch1, i32 0, i32 0 26*9880d681SAndroid Build Coastguard Worker store i32 2, i32* %scratchptr1 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker %cmp = icmp eq i32 %cond, 0 29*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %if, label %else 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Workerif: 32*9880d681SAndroid Build Coastguard Worker %if_ptr = getelementptr [8192 x i32], [8192 x i32]* %scratch0, i32 0, i32 %if_offset 33*9880d681SAndroid Build Coastguard Worker %if_value = load i32, i32* %if_ptr 34*9880d681SAndroid Build Coastguard Worker br label %done 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Workerelse: 37*9880d681SAndroid Build Coastguard Worker %else_ptr = getelementptr [8192 x i32], [8192 x i32]* %scratch1, i32 0, i32 %else_offset 38*9880d681SAndroid Build Coastguard Worker %else_value = load i32, i32* %else_ptr 39*9880d681SAndroid Build Coastguard Worker br label %done 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Workerdone: 42*9880d681SAndroid Build Coastguard Worker %value = phi i32 [%if_value, %if], [%else_value, %else] 43*9880d681SAndroid Build Coastguard Worker store i32 %value, i32 addrspace(1)* %out 44*9880d681SAndroid Build Coastguard Worker ret void 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker ret void 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker} 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}legal_offset_fi_offset: 51*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+}}:{{[0-9]+}}], s{{[0-9]+}} offen{{$}} 52*9880d681SAndroid Build Coastguard Worker; GCN: v_add_i32_e32 [[OFFSET:v[0-9]+]], vcc, 0x8000 53*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword v{{[0-9]+}}, [[OFFSET]], s[{{[0-9]+}}:{{[0-9]+}}], s{{[0-9]+}} offen{{$}} 54*9880d681SAndroid Build Coastguard Worker 55*9880d681SAndroid Build Coastguard Workerdefine void @legal_offset_fi_offset(i32 addrspace(1)* %out, i32 %cond, i32 addrspace(1)* %offsets, i32 %if_offset, i32 %else_offset) { 56*9880d681SAndroid Build Coastguard Workerentry: 57*9880d681SAndroid Build Coastguard Worker %scratch0 = alloca [8192 x i32] 58*9880d681SAndroid Build Coastguard Worker %scratch1 = alloca [8192 x i32] 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Worker %offset0 = load i32, i32 addrspace(1)* %offsets 61*9880d681SAndroid Build Coastguard Worker %scratchptr0 = getelementptr [8192 x i32], [8192 x i32]* %scratch0, i32 0, i32 %offset0 62*9880d681SAndroid Build Coastguard Worker store i32 %offset0, i32* %scratchptr0 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker %offsetptr1 = getelementptr i32, i32 addrspace(1)* %offsets, i32 1 65*9880d681SAndroid Build Coastguard Worker %offset1 = load i32, i32 addrspace(1)* %offsetptr1 66*9880d681SAndroid Build Coastguard Worker %scratchptr1 = getelementptr [8192 x i32], [8192 x i32]* %scratch1, i32 0, i32 %offset1 67*9880d681SAndroid Build Coastguard Worker store i32 %offset1, i32* %scratchptr1 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Worker %cmp = icmp eq i32 %cond, 0 70*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %if, label %else 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Workerif: 73*9880d681SAndroid Build Coastguard Worker %if_ptr = getelementptr [8192 x i32], [8192 x i32]* %scratch0, i32 0, i32 %if_offset 74*9880d681SAndroid Build Coastguard Worker %if_value = load i32, i32* %if_ptr 75*9880d681SAndroid Build Coastguard Worker br label %done 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Workerelse: 78*9880d681SAndroid Build Coastguard Worker %else_ptr = getelementptr [8192 x i32], [8192 x i32]* %scratch1, i32 0, i32 %else_offset 79*9880d681SAndroid Build Coastguard Worker %else_value = load i32, i32* %else_ptr 80*9880d681SAndroid Build Coastguard Worker br label %done 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Workerdone: 83*9880d681SAndroid Build Coastguard Worker %value = phi i32 [%if_value, %if], [%else_value, %else] 84*9880d681SAndroid Build Coastguard Worker store i32 %value, i32 addrspace(1)* %out 85*9880d681SAndroid Build Coastguard Worker ret void 86*9880d681SAndroid Build Coastguard Worker} 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}neg_vaddr_offset: 89*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:16{{$}} 90*9880d681SAndroid Build Coastguard Workerdefine void @neg_vaddr_offset(i32 %offset) { 91*9880d681SAndroid Build Coastguard Workerentry: 92*9880d681SAndroid Build Coastguard Worker %array = alloca [8192 x i32] 93*9880d681SAndroid Build Coastguard Worker %ptr_offset = add i32 %offset, 4 94*9880d681SAndroid Build Coastguard Worker %ptr = getelementptr [8192 x i32], [8192 x i32]* %array, i32 0, i32 %ptr_offset 95*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %ptr 96*9880d681SAndroid Build Coastguard Worker ret void 97*9880d681SAndroid Build Coastguard Worker} 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}pos_vaddr_offset: 100*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:16 101*9880d681SAndroid Build Coastguard Workerdefine void @pos_vaddr_offset(i32 addrspace(1)* %out, i32 %offset) { 102*9880d681SAndroid Build Coastguard Workerentry: 103*9880d681SAndroid Build Coastguard Worker %array = alloca [8192 x i32] 104*9880d681SAndroid Build Coastguard Worker %ptr = getelementptr [8192 x i32], [8192 x i32]* %array, i32 0, i32 4 105*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %ptr 106*9880d681SAndroid Build Coastguard Worker %load_ptr = getelementptr [8192 x i32], [8192 x i32]* %array, i32 0, i32 %offset 107*9880d681SAndroid Build Coastguard Worker %val = load i32, i32* %load_ptr 108*9880d681SAndroid Build Coastguard Worker store i32 %val, i32 addrspace(1)* %out 109*9880d681SAndroid Build Coastguard Worker ret void 110*9880d681SAndroid Build Coastguard Worker} 111