1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx906 < %s | FileCheck -check-prefixes=GCN,GFX9,MUBUF %s 3; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx906 --amdgpu-enable-flat-scratch < %s | FileCheck -check-prefixes=GCN,GFX9,FLATSCR %s 4 5; Make sure we use the correct frame offset is used with the local 6; frame area. 7; 8; %pin.low is allocated to offset 0. 9; 10; %local.area is assigned to the local frame offset by the 11; LocalStackSlotAllocation pass at offset 4096. 12; 13; The %load1 access to %gep.large.offset initially used the stack 14; pointer register and directly referenced the frame index. After 15; LocalStackSlotAllocation, it would no longer refer to a frame index 16; so eliminateFrameIndex would not adjust the access to use the 17; correct FP offset. 18 19define amdgpu_kernel void @local_stack_offset_uses_sp(i64 addrspace(1)* %out, i8 addrspace(1)* %in) { 20; MUBUF-LABEL: local_stack_offset_uses_sp: 21; MUBUF: ; %bb.0: ; %entry 22; MUBUF-NEXT: s_load_dwordx2 s[4:5], s[4:5], 0x0 23; MUBUF-NEXT: s_add_u32 flat_scratch_lo, s6, s9 24; MUBUF-NEXT: s_addc_u32 flat_scratch_hi, s7, 0 25; MUBUF-NEXT: s_add_u32 s0, s0, s9 26; MUBUF-NEXT: v_mov_b32_e32 v1, 0x3000 27; MUBUF-NEXT: s_addc_u32 s1, s1, 0 28; MUBUF-NEXT: v_add_u32_e32 v0, 64, v1 29; MUBUF-NEXT: v_mov_b32_e32 v2, 0 30; MUBUF-NEXT: v_mov_b32_e32 v3, 0x2000 31; MUBUF-NEXT: s_mov_b32 s6, 0 32; MUBUF-NEXT: buffer_store_dword v2, v3, s[0:3], 0 offen 33; MUBUF-NEXT: BB0_1: ; %loadstoreloop 34; MUBUF-NEXT: ; =>This Inner Loop Header: Depth=1 35; MUBUF-NEXT: v_add_u32_e32 v3, s6, v1 36; MUBUF-NEXT: s_add_i32 s6, s6, 1 37; MUBUF-NEXT: s_cmpk_lt_u32 s6, 0x2120 38; MUBUF-NEXT: buffer_store_byte v2, v3, s[0:3], 0 offen 39; MUBUF-NEXT: s_cbranch_scc1 BB0_1 40; MUBUF-NEXT: ; %bb.2: ; %split 41; MUBUF-NEXT: v_mov_b32_e32 v1, 0x3000 42; MUBUF-NEXT: v_add_u32_e32 v1, 0x20d0, v1 43; MUBUF-NEXT: buffer_load_dword v2, v1, s[0:3], 0 offen 44; MUBUF-NEXT: buffer_load_dword v1, v1, s[0:3], 0 offen offset:4 45; MUBUF-NEXT: buffer_load_dword v3, v0, s[0:3], 0 offen 46; MUBUF-NEXT: buffer_load_dword v4, v0, s[0:3], 0 offen offset:4 47; MUBUF-NEXT: s_waitcnt vmcnt(1) 48; MUBUF-NEXT: v_add_co_u32_e32 v0, vcc, v2, v3 49; MUBUF-NEXT: s_waitcnt vmcnt(0) 50; MUBUF-NEXT: v_addc_co_u32_e32 v1, vcc, v1, v4, vcc 51; MUBUF-NEXT: v_mov_b32_e32 v2, 0 52; MUBUF-NEXT: s_waitcnt lgkmcnt(0) 53; MUBUF-NEXT: global_store_dwordx2 v2, v[0:1], s[4:5] 54; MUBUF-NEXT: s_endpgm 55; 56; FLATSCR-LABEL: local_stack_offset_uses_sp: 57; FLATSCR: ; %bb.0: ; %entry 58; FLATSCR-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x0 59; FLATSCR-NEXT: s_add_u32 flat_scratch_lo, s2, s5 60; FLATSCR-NEXT: s_addc_u32 flat_scratch_hi, s3, 0 61; FLATSCR-NEXT: v_mov_b32_e32 v0, 0 62; FLATSCR-NEXT: s_movk_i32 vcc_hi, 0x2000 63; FLATSCR-NEXT: s_mov_b32 s2, 0 64; FLATSCR-NEXT: scratch_store_dword off, v0, vcc_hi 65; FLATSCR-NEXT: BB0_1: ; %loadstoreloop 66; FLATSCR-NEXT: ; =>This Inner Loop Header: Depth=1 67; FLATSCR-NEXT: s_add_u32 s3, 0x3000, s2 68; FLATSCR-NEXT: s_add_i32 s2, s2, 1 69; FLATSCR-NEXT: s_cmpk_lt_u32 s2, 0x2120 70; FLATSCR-NEXT: scratch_store_byte off, v0, s3 71; FLATSCR-NEXT: s_cbranch_scc1 BB0_1 72; FLATSCR-NEXT: ; %bb.2: ; %split 73; FLATSCR-NEXT: s_movk_i32 s2, 0x2000 74; FLATSCR-NEXT: s_add_u32 s2, 0x3000, s2 75; FLATSCR-NEXT: scratch_load_dwordx2 v[0:1], off, s2 offset:208 76; FLATSCR-NEXT: s_movk_i32 s2, 0x3000 77; FLATSCR-NEXT: scratch_load_dwordx2 v[2:3], off, s2 offset:64 78; FLATSCR-NEXT: s_waitcnt vmcnt(0) 79; FLATSCR-NEXT: v_add_co_u32_e32 v0, vcc, v0, v2 80; FLATSCR-NEXT: v_addc_co_u32_e32 v1, vcc, v1, v3, vcc 81; FLATSCR-NEXT: v_mov_b32_e32 v2, 0 82; FLATSCR-NEXT: s_waitcnt lgkmcnt(0) 83; FLATSCR-NEXT: global_store_dwordx2 v2, v[0:1], s[0:1] 84; FLATSCR-NEXT: s_endpgm 85entry: 86 %pin.low = alloca i32, align 8192, addrspace(5) 87 %local.area = alloca [1060 x i64], align 4096, addrspace(5) 88 store volatile i32 0, i32 addrspace(5)* %pin.low 89 %local.area.cast = bitcast [1060 x i64] addrspace(5)* %local.area to i8 addrspace(5)* 90 call void @llvm.memset.p5i8.i32(i8 addrspace(5)* align 4 %local.area.cast, i8 0, i32 8480, i1 true) 91 %gep.large.offset = getelementptr inbounds [1060 x i64], [1060 x i64] addrspace(5)* %local.area, i64 0, i64 1050 92 %gep.small.offset = getelementptr inbounds [1060 x i64], [1060 x i64] addrspace(5)* %local.area, i64 0, i64 8 93 %load0 = load volatile i64, i64 addrspace(5)* %gep.large.offset 94 %load1 = load volatile i64, i64 addrspace(5)* %gep.small.offset 95 %add0 = add i64 %load0, %load1 96 store volatile i64 %add0, i64 addrspace(1)* %out 97 ret void 98} 99 100define void @func_local_stack_offset_uses_sp(i64 addrspace(1)* %out, i8 addrspace(1)* %in) { 101; MUBUF-LABEL: func_local_stack_offset_uses_sp: 102; MUBUF: ; %bb.0: ; %entry 103; MUBUF-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) 104; MUBUF-NEXT: s_add_u32 s4, s32, 0x7ffc0 105; MUBUF-NEXT: s_mov_b32 s5, s33 106; MUBUF-NEXT: s_and_b32 s33, s4, 0xfff80000 107; MUBUF-NEXT: v_lshrrev_b32_e64 v3, 6, s33 108; MUBUF-NEXT: v_add_u32_e32 v3, 0x1000, v3 109; MUBUF-NEXT: v_mov_b32_e32 v4, 0 110; MUBUF-NEXT: v_add_u32_e32 v2, 64, v3 111; MUBUF-NEXT: s_mov_b32 s4, 0 112; MUBUF-NEXT: s_add_u32 s32, s32, 0x180000 113; MUBUF-NEXT: buffer_store_dword v4, off, s[0:3], s33 114; MUBUF-NEXT: BB1_1: ; %loadstoreloop 115; MUBUF-NEXT: ; =>This Inner Loop Header: Depth=1 116; MUBUF-NEXT: v_add_u32_e32 v5, s4, v3 117; MUBUF-NEXT: s_add_i32 s4, s4, 1 118; MUBUF-NEXT: s_cmpk_lt_u32 s4, 0x2120 119; MUBUF-NEXT: buffer_store_byte v4, v5, s[0:3], 0 offen 120; MUBUF-NEXT: s_cbranch_scc1 BB1_1 121; MUBUF-NEXT: ; %bb.2: ; %split 122; MUBUF-NEXT: v_lshrrev_b32_e64 v3, 6, s33 123; MUBUF-NEXT: v_add_u32_e32 v3, 0x1000, v3 124; MUBUF-NEXT: v_add_u32_e32 v3, 0x20d0, v3 125; MUBUF-NEXT: buffer_load_dword v4, v3, s[0:3], 0 offen 126; MUBUF-NEXT: buffer_load_dword v3, v3, s[0:3], 0 offen offset:4 127; MUBUF-NEXT: buffer_load_dword v5, v2, s[0:3], 0 offen 128; MUBUF-NEXT: buffer_load_dword v6, v2, s[0:3], 0 offen offset:4 129; MUBUF-NEXT: s_sub_u32 s32, s32, 0x180000 130; MUBUF-NEXT: s_mov_b32 s33, s5 131; MUBUF-NEXT: s_waitcnt vmcnt(1) 132; MUBUF-NEXT: v_add_co_u32_e32 v2, vcc, v4, v5 133; MUBUF-NEXT: s_waitcnt vmcnt(0) 134; MUBUF-NEXT: v_addc_co_u32_e32 v3, vcc, v3, v6, vcc 135; MUBUF-NEXT: global_store_dwordx2 v[0:1], v[2:3], off 136; MUBUF-NEXT: s_waitcnt vmcnt(0) 137; MUBUF-NEXT: s_setpc_b64 s[30:31] 138; 139; FLATSCR-LABEL: func_local_stack_offset_uses_sp: 140; FLATSCR: ; %bb.0: ; %entry 141; FLATSCR-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) 142; FLATSCR-NEXT: s_add_u32 s0, s32, 0x1fff 143; FLATSCR-NEXT: s_mov_b32 s2, s33 144; FLATSCR-NEXT: s_and_b32 s33, s0, 0xffffe000 145; FLATSCR-NEXT: v_mov_b32_e32 v2, 0 146; FLATSCR-NEXT: s_mov_b32 s0, 0 147; FLATSCR-NEXT: s_add_u32 s32, s32, 0x6000 148; FLATSCR-NEXT: scratch_store_dword off, v2, s33 149; FLATSCR-NEXT: BB1_1: ; %loadstoreloop 150; FLATSCR-NEXT: ; =>This Inner Loop Header: Depth=1 151; FLATSCR-NEXT: s_add_u32 vcc_hi, s33, 0x1000 152; FLATSCR-NEXT: s_add_u32 s1, vcc_hi, s0 153; FLATSCR-NEXT: s_add_i32 s0, s0, 1 154; FLATSCR-NEXT: s_cmpk_lt_u32 s0, 0x2120 155; FLATSCR-NEXT: scratch_store_byte off, v2, s1 156; FLATSCR-NEXT: s_cbranch_scc1 BB1_1 157; FLATSCR-NEXT: ; %bb.2: ; %split 158; FLATSCR-NEXT: s_movk_i32 s0, 0x2000 159; FLATSCR-NEXT: s_add_u32 s1, s33, 0x1000 160; FLATSCR-NEXT: s_add_u32 s0, s1, s0 161; FLATSCR-NEXT: scratch_load_dwordx2 v[2:3], off, s0 offset:208 162; FLATSCR-NEXT: s_add_u32 s0, s33, 0x1000 163; FLATSCR-NEXT: scratch_load_dwordx2 v[4:5], off, s0 offset:64 164; FLATSCR-NEXT: s_sub_u32 s32, s32, 0x6000 165; FLATSCR-NEXT: s_mov_b32 s33, s2 166; FLATSCR-NEXT: s_waitcnt vmcnt(0) 167; FLATSCR-NEXT: v_add_co_u32_e32 v2, vcc, v2, v4 168; FLATSCR-NEXT: v_addc_co_u32_e32 v3, vcc, v3, v5, vcc 169; FLATSCR-NEXT: global_store_dwordx2 v[0:1], v[2:3], off 170; FLATSCR-NEXT: s_waitcnt vmcnt(0) 171; FLATSCR-NEXT: s_setpc_b64 s[30:31] 172entry: 173 %pin.low = alloca i32, align 8192, addrspace(5) 174 %local.area = alloca [1060 x i64], align 4096, addrspace(5) 175 store volatile i32 0, i32 addrspace(5)* %pin.low 176 %local.area.cast = bitcast [1060 x i64] addrspace(5)* %local.area to i8 addrspace(5)* 177 call void @llvm.memset.p5i8.i32(i8 addrspace(5)* align 4 %local.area.cast, i8 0, i32 8480, i1 true) 178 %gep.large.offset = getelementptr inbounds [1060 x i64], [1060 x i64] addrspace(5)* %local.area, i64 0, i64 1050 179 %gep.small.offset = getelementptr inbounds [1060 x i64], [1060 x i64] addrspace(5)* %local.area, i64 0, i64 8 180 %load0 = load volatile i64, i64 addrspace(5)* %gep.large.offset 181 %load1 = load volatile i64, i64 addrspace(5)* %gep.small.offset 182 %add0 = add i64 %load0, %load1 183 store volatile i64 %add0, i64 addrspace(1)* %out 184 ret void 185} 186 187declare void @llvm.memset.p5i8.i32(i8 addrspace(5)* nocapture writeonly, i8, i32, i1 immarg) #0 188 189attributes #0 = { argmemonly nounwind willreturn writeonly } 190