1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -show-mc-encoding -verify-machineinstrs < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Workerdeclare i32 @llvm.amdgcn.workitem.id.x() readnone 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker;;;==========================================================================;;; 6*9880d681SAndroid Build Coastguard Worker;;; MUBUF LOAD TESTS 7*9880d681SAndroid Build Coastguard Worker;;;==========================================================================;;; 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Worker; MUBUF load with an immediate byte offset that fits into 12-bits 10*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_load0: 11*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_load_dword v{{[0-9]}}, off, s[{{[0-9]+:[0-9]+}}], 0 offset:4 ; encoding: [0x04,0x00,0x30,0xe0 12*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_load0(i32 addrspace(1)* %out, i32 addrspace(1)* %in) { 13*9880d681SAndroid Build Coastguard Workerentry: 14*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i32, i32 addrspace(1)* %in, i64 1 15*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32 addrspace(1)* %0 16*9880d681SAndroid Build Coastguard Worker store i32 %1, i32 addrspace(1)* %out 17*9880d681SAndroid Build Coastguard Worker ret void 18*9880d681SAndroid Build Coastguard Worker} 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker; MUBUF load with the largest possible immediate offset 21*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_load1: 22*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_load_ubyte v{{[0-9]}}, off, s[{{[0-9]+:[0-9]+}}], 0 offset:4095 ; encoding: [0xff,0x0f,0x20,0xe0 23*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_load1(i8 addrspace(1)* %out, i8 addrspace(1)* %in) { 24*9880d681SAndroid Build Coastguard Workerentry: 25*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i8, i8 addrspace(1)* %in, i64 4095 26*9880d681SAndroid Build Coastguard Worker %1 = load i8, i8 addrspace(1)* %0 27*9880d681SAndroid Build Coastguard Worker store i8 %1, i8 addrspace(1)* %out 28*9880d681SAndroid Build Coastguard Worker ret void 29*9880d681SAndroid Build Coastguard Worker} 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Worker; MUBUF load with an immediate byte offset that doesn't fit into 12-bits 32*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_load2: 33*9880d681SAndroid Build Coastguard Worker; CHECK: s_movk_i32 [[SOFFSET:s[0-9]+]], 0x1000 34*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_load_dword v{{[0-9]}}, off, s[{{[0-9]+:[0-9]+}}], [[SOFFSET]] ; encoding: [0x00,0x00,0x30,0xe0 35*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_load2(i32 addrspace(1)* %out, i32 addrspace(1)* %in) { 36*9880d681SAndroid Build Coastguard Workerentry: 37*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i32, i32 addrspace(1)* %in, i64 1024 38*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32 addrspace(1)* %0 39*9880d681SAndroid Build Coastguard Worker store i32 %1, i32 addrspace(1)* %out 40*9880d681SAndroid Build Coastguard Worker ret void 41*9880d681SAndroid Build Coastguard Worker} 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker; MUBUF load with a 12-bit immediate offset and a register offset 44*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_load3: 45*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: ADD 46*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_load_dword v{{[0-9]}}, v[{{[0-9]+:[0-9]+}}], s[{{[0-9]+:[0-9]+}}], 0 addr64 offset:4 ; encoding: [0x04,0x80,0x30,0xe0 47*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_load3(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i64 %offset) { 48*9880d681SAndroid Build Coastguard Workerentry: 49*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i32, i32 addrspace(1)* %in, i64 %offset 50*9880d681SAndroid Build Coastguard Worker %1 = getelementptr i32, i32 addrspace(1)* %0, i64 1 51*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32 addrspace(1)* %1 52*9880d681SAndroid Build Coastguard Worker store i32 %2, i32 addrspace(1)* %out 53*9880d681SAndroid Build Coastguard Worker ret void 54*9880d681SAndroid Build Coastguard Worker} 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}soffset_max_imm: 57*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_load_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+}}:{{[0-9]+}}], 64 offen glc 58*9880d681SAndroid Build Coastguard Workerdefine amdgpu_gs void @soffset_max_imm([6 x <16 x i8>] addrspace(2)* byval, [17 x <16 x i8>] addrspace(2)* byval, [16 x <4 x i32>] addrspace(2)* byval, [32 x <8 x i32>] addrspace(2)* byval, i32 inreg, i32 inreg, i32, i32, i32, i32, i32, i32, i32, i32) { 59*9880d681SAndroid Build Coastguard Workermain_body: 60*9880d681SAndroid Build Coastguard Worker %tmp0 = getelementptr [6 x <16 x i8>], [6 x <16 x i8>] addrspace(2)* %0, i32 0, i32 0 61*9880d681SAndroid Build Coastguard Worker %tmp1 = load <16 x i8>, <16 x i8> addrspace(2)* %tmp0 62*9880d681SAndroid Build Coastguard Worker %tmp2 = shl i32 %6, 2 63*9880d681SAndroid Build Coastguard Worker %tmp3 = call i32 @llvm.SI.buffer.load.dword.i32.i32(<16 x i8> %tmp1, i32 %tmp2, i32 64, i32 0, i32 1, i32 0, i32 1, i32 0, i32 0) 64*9880d681SAndroid Build Coastguard Worker %tmp4 = add i32 %6, 16 65*9880d681SAndroid Build Coastguard Worker call void @llvm.SI.tbuffer.store.i32(<16 x i8> %tmp1, i32 %tmp3, i32 1, i32 %tmp4, i32 %4, i32 0, i32 4, i32 4, i32 1, i32 0, i32 1, i32 1, i32 0) 66*9880d681SAndroid Build Coastguard Worker ret void 67*9880d681SAndroid Build Coastguard Worker} 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Worker; Make sure immediates that aren't inline constants don't get folded into 70*9880d681SAndroid Build Coastguard Worker; the soffset operand. 71*9880d681SAndroid Build Coastguard Worker; FIXME: for this test we should be smart enough to shift the immediate into 72*9880d681SAndroid Build Coastguard Worker; the offset field. 73*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}soffset_no_fold: 74*9880d681SAndroid Build Coastguard Worker; CHECK: s_movk_i32 [[SOFFSET:s[0-9]+]], 0x41 75*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_load_dword v{{[0-9+]}}, v{{[0-9+]}}, s[{{[0-9]+}}:{{[0-9]+}}], [[SOFFSET]] offen glc 76*9880d681SAndroid Build Coastguard Workerdefine amdgpu_gs void @soffset_no_fold([6 x <16 x i8>] addrspace(2)* byval, [17 x <16 x i8>] addrspace(2)* byval, [16 x <4 x i32>] addrspace(2)* byval, [32 x <8 x i32>] addrspace(2)* byval, i32 inreg, i32 inreg, i32, i32, i32, i32, i32, i32, i32, i32) { 77*9880d681SAndroid Build Coastguard Workermain_body: 78*9880d681SAndroid Build Coastguard Worker %tmp0 = getelementptr [6 x <16 x i8>], [6 x <16 x i8>] addrspace(2)* %0, i32 0, i32 0 79*9880d681SAndroid Build Coastguard Worker %tmp1 = load <16 x i8>, <16 x i8> addrspace(2)* %tmp0 80*9880d681SAndroid Build Coastguard Worker %tmp2 = shl i32 %6, 2 81*9880d681SAndroid Build Coastguard Worker %tmp3 = call i32 @llvm.SI.buffer.load.dword.i32.i32(<16 x i8> %tmp1, i32 %tmp2, i32 65, i32 0, i32 1, i32 0, i32 1, i32 0, i32 0) 82*9880d681SAndroid Build Coastguard Worker %tmp4 = add i32 %6, 16 83*9880d681SAndroid Build Coastguard Worker call void @llvm.SI.tbuffer.store.i32(<16 x i8> %tmp1, i32 %tmp3, i32 1, i32 %tmp4, i32 %4, i32 0, i32 4, i32 4, i32 1, i32 0, i32 1, i32 1, i32 0) 84*9880d681SAndroid Build Coastguard Worker ret void 85*9880d681SAndroid Build Coastguard Worker} 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker;;;==========================================================================;;; 88*9880d681SAndroid Build Coastguard Worker;;; MUBUF STORE TESTS 89*9880d681SAndroid Build Coastguard Worker;;;==========================================================================;;; 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard Worker; MUBUF store with an immediate byte offset that fits into 12-bits 92*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_store0: 93*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dword v{{[0-9]}}, off, s[{{[0-9]:[0-9]}}], 0 offset:4 ; encoding: [0x04,0x00,0x70,0xe0 94*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_store0(i32 addrspace(1)* %out) { 95*9880d681SAndroid Build Coastguard Workerentry: 96*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i32, i32 addrspace(1)* %out, i64 1 97*9880d681SAndroid Build Coastguard Worker store i32 0, i32 addrspace(1)* %0 98*9880d681SAndroid Build Coastguard Worker ret void 99*9880d681SAndroid Build Coastguard Worker} 100*9880d681SAndroid Build Coastguard Worker 101*9880d681SAndroid Build Coastguard Worker; MUBUF store with the largest possible immediate offset 102*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_store1: 103*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_byte v{{[0-9]}}, off, s[{{[0-9]:[0-9]}}], 0 offset:4095 ; encoding: [0xff,0x0f,0x60,0xe0 104*9880d681SAndroid Build Coastguard Worker 105*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_store1(i8 addrspace(1)* %out) { 106*9880d681SAndroid Build Coastguard Workerentry: 107*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i8, i8 addrspace(1)* %out, i64 4095 108*9880d681SAndroid Build Coastguard Worker store i8 0, i8 addrspace(1)* %0 109*9880d681SAndroid Build Coastguard Worker ret void 110*9880d681SAndroid Build Coastguard Worker} 111*9880d681SAndroid Build Coastguard Worker 112*9880d681SAndroid Build Coastguard Worker; MUBUF store with an immediate byte offset that doesn't fit into 12-bits 113*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_store2: 114*9880d681SAndroid Build Coastguard Worker; CHECK: s_movk_i32 [[SOFFSET:s[0-9]+]], 0x1000 115*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dword v{{[0-9]}}, off, s[{{[0-9]:[0-9]}}], [[SOFFSET]] ; encoding: [0x00,0x00,0x70,0xe0 116*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_store2(i32 addrspace(1)* %out) { 117*9880d681SAndroid Build Coastguard Workerentry: 118*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i32, i32 addrspace(1)* %out, i64 1024 119*9880d681SAndroid Build Coastguard Worker store i32 0, i32 addrspace(1)* %0 120*9880d681SAndroid Build Coastguard Worker ret void 121*9880d681SAndroid Build Coastguard Worker} 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard Worker; MUBUF store with a 12-bit immediate offset and a register offset 124*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}mubuf_store3: 125*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: ADD 126*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dword v{{[0-9]}}, v[{{[0-9]:[0-9]}}], s[{{[0-9]:[0-9]}}], 0 addr64 offset:4 ; encoding: [0x04,0x80,0x70,0xe0 127*9880d681SAndroid Build Coastguard Workerdefine void @mubuf_store3(i32 addrspace(1)* %out, i64 %offset) { 128*9880d681SAndroid Build Coastguard Workerentry: 129*9880d681SAndroid Build Coastguard Worker %0 = getelementptr i32, i32 addrspace(1)* %out, i64 %offset 130*9880d681SAndroid Build Coastguard Worker %1 = getelementptr i32, i32 addrspace(1)* %0, i64 1 131*9880d681SAndroid Build Coastguard Worker store i32 0, i32 addrspace(1)* %1 132*9880d681SAndroid Build Coastguard Worker ret void 133*9880d681SAndroid Build Coastguard Worker} 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}store_sgpr_ptr: 136*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 137*9880d681SAndroid Build Coastguard Workerdefine void @store_sgpr_ptr(i32 addrspace(1)* %out) #0 { 138*9880d681SAndroid Build Coastguard Worker store i32 99, i32 addrspace(1)* %out, align 4 139*9880d681SAndroid Build Coastguard Worker ret void 140*9880d681SAndroid Build Coastguard Worker} 141*9880d681SAndroid Build Coastguard Worker 142*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}store_sgpr_ptr_offset: 143*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:40 144*9880d681SAndroid Build Coastguard Workerdefine void @store_sgpr_ptr_offset(i32 addrspace(1)* %out) #0 { 145*9880d681SAndroid Build Coastguard Worker %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 10 146*9880d681SAndroid Build Coastguard Worker store i32 99, i32 addrspace(1)* %out.gep, align 4 147*9880d681SAndroid Build Coastguard Worker ret void 148*9880d681SAndroid Build Coastguard Worker} 149*9880d681SAndroid Build Coastguard Worker 150*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}store_sgpr_ptr_large_offset: 151*9880d681SAndroid Build Coastguard Worker; CHECK: s_mov_b32 [[SOFFSET:s[0-9]+]], 0x20000 152*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dword v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, [[SOFFSET]] 153*9880d681SAndroid Build Coastguard Workerdefine void @store_sgpr_ptr_large_offset(i32 addrspace(1)* %out) #0 { 154*9880d681SAndroid Build Coastguard Worker %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 32768 155*9880d681SAndroid Build Coastguard Worker store i32 99, i32 addrspace(1)* %out.gep, align 4 156*9880d681SAndroid Build Coastguard Worker ret void 157*9880d681SAndroid Build Coastguard Worker} 158*9880d681SAndroid Build Coastguard Worker 159*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}store_sgpr_ptr_large_offset_atomic: 160*9880d681SAndroid Build Coastguard Worker; CHECK: s_mov_b32 [[SOFFSET:s[0-9]+]], 0x20000 161*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_atomic_add v{{[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, [[SOFFSET]] 162*9880d681SAndroid Build Coastguard Workerdefine void @store_sgpr_ptr_large_offset_atomic(i32 addrspace(1)* %out) #0 { 163*9880d681SAndroid Build Coastguard Worker %gep = getelementptr i32, i32 addrspace(1)* %out, i32 32768 164*9880d681SAndroid Build Coastguard Worker %val = atomicrmw volatile add i32 addrspace(1)* %gep, i32 5 seq_cst 165*9880d681SAndroid Build Coastguard Worker ret void 166*9880d681SAndroid Build Coastguard Worker} 167*9880d681SAndroid Build Coastguard Worker 168*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: {{^}}store_vgpr_ptr: 169*9880d681SAndroid Build Coastguard Worker; CHECK: buffer_store_dword v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0 addr64 170*9880d681SAndroid Build Coastguard Workerdefine void @store_vgpr_ptr(i32 addrspace(1)* %out) #0 { 171*9880d681SAndroid Build Coastguard Worker %tid = call i32 @llvm.amdgcn.workitem.id.x() readnone 172*9880d681SAndroid Build Coastguard Worker %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid 173*9880d681SAndroid Build Coastguard Worker store i32 99, i32 addrspace(1)* %out.gep, align 4 174*9880d681SAndroid Build Coastguard Worker ret void 175*9880d681SAndroid Build Coastguard Worker} 176*9880d681SAndroid Build Coastguard Worker 177*9880d681SAndroid Build Coastguard Workerdeclare i32 @llvm.SI.buffer.load.dword.i32.i32(<16 x i8>, i32, i32, i32, i32, i32, i32, i32, i32) #0 178*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.SI.tbuffer.store.i32(<16 x i8>, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) 179*9880d681SAndroid Build Coastguard Worker 180*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind readonly } 181