1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 3; RUN: opt -S -codegenprepare -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1030 < %s | FileCheck -check-prefix=OPT %s 4; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1030 < %s | FileCheck -check-prefix=GCN %s 5 6; Make sure we match the addressing mode offset of csub intrinsics across blocks. 7 8define amdgpu_kernel void @test_sink_small_offset_global_atomic_csub_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) { 9; OPT-LABEL: @test_sink_small_offset_global_atomic_csub_i32( 10; OPT-NEXT: entry: 11; OPT-NEXT: [[OUT_GEP:%.*]] = getelementptr i32, i32 addrspace(1)* [[OUT:%.*]], i32 999999 12; OPT-NEXT: [[TID:%.*]] = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #3 13; OPT-NEXT: [[CMP:%.*]] = icmp eq i32 [[TID]], 0 14; OPT-NEXT: br i1 [[CMP]], label [[ENDIF:%.*]], label [[IF:%.*]] 15; OPT: if: 16; OPT-NEXT: [[TMP0:%.*]] = bitcast i32 addrspace(1)* [[IN:%.*]] to i8 addrspace(1)* 17; OPT-NEXT: [[SUNKADDR:%.*]] = getelementptr i8, i8 addrspace(1)* [[TMP0]], i64 28 18; OPT-NEXT: [[TMP1:%.*]] = bitcast i8 addrspace(1)* [[SUNKADDR]] to i32 addrspace(1)* 19; OPT-NEXT: [[VAL:%.*]] = call i32 @llvm.amdgcn.global.atomic.csub.p1i32(i32 addrspace(1)* [[TMP1]], i32 2) 20; OPT-NEXT: br label [[ENDIF]] 21; OPT: endif: 22; OPT-NEXT: [[X:%.*]] = phi i32 [ [[VAL]], [[IF]] ], [ 0, [[ENTRY:%.*]] ] 23; OPT-NEXT: store i32 [[X]], i32 addrspace(1)* [[OUT_GEP]], align 4 24; OPT-NEXT: ret void 25; 26; GCN-LABEL: test_sink_small_offset_global_atomic_csub_i32: 27; GCN: ; %bb.0: ; %entry 28; GCN-NEXT: s_load_dwordx4 s[0:3], s[4:5], 0x0 29; GCN-NEXT: v_mbcnt_lo_u32_b32_e64 v0, -1, 0 30; GCN-NEXT: v_cmp_ne_u32_e32 vcc_lo, 0, v0 31; GCN-NEXT: v_mov_b32_e32 v0, 0 32; GCN-NEXT: s_and_saveexec_b32 s4, vcc_lo 33; GCN-NEXT: s_cbranch_execz BB0_2 34; GCN-NEXT: ; %bb.1: ; %if 35; GCN-NEXT: v_mov_b32_e32 v0, 0 36; GCN-NEXT: v_mov_b32_e32 v1, 2 37; GCN-NEXT: s_waitcnt lgkmcnt(0) 38; GCN-NEXT: global_atomic_csub v0, v0, v1, s[2:3] offset:28 glc 39; GCN-NEXT: BB0_2: ; %endif 40; GCN-NEXT: s_or_b32 exec_lo, exec_lo, s4 41; GCN-NEXT: v_mov_b32_e32 v1, 0x3d0800 42; GCN-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0) 43; GCN-NEXT: global_store_dword v1, v0, s[0:1] offset:252 44; GCN-NEXT: s_endpgm 45entry: 46 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 999999 47 %in.gep = getelementptr i32, i32 addrspace(1)* %in, i32 7 48 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 49 %cmp = icmp eq i32 %tid, 0 50 br i1 %cmp, label %endif, label %if 51 52if: 53 %val = call i32 @llvm.amdgcn.global.atomic.csub.p1i32(i32 addrspace(1)* %in.gep, i32 2) 54 br label %endif 55 56endif: 57 %x = phi i32 [ %val, %if ], [ 0, %entry ] 58 store i32 %x, i32 addrspace(1)* %out.gep 59 br label %done 60 61done: 62 ret void 63} 64 65declare i32 @llvm.amdgcn.global.atomic.csub.p1i32(i32 addrspace(1)* nocapture, i32) #0 66declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #1 67 68attributes #0 = { argmemonly nounwind } 69attributes #1 = { nounwind readnone willreturn } 70attributes #2 = { argmemonly nounwind willreturn } 71