[flang-commits] [clang] [clang-tools-extra] [compiler-rt] [llvm] [libcxx] [lldb] [lld] [libc] [flang] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

Stanislav Mekhanoshin via flang-commits flang-commits at lists.llvm.org
Tue Dec 19 10:51:34 PST 2023


rampitec wrote:

> Test case:
> 
> ```
> @lds.0 = internal addrspace(3) global [64 x float] poison, align 16
> @lds.1 = internal addrspace(3) global [64 x float] poison, align 16
> 
> declare void @llvm.amdgcn.raw.buffer.load.lds(<4 x i32> %rsrc, ptr addrspace(3) nocapture, i32 %size, i32 %voffset, i32 %soffset, i32 %offset, i32 %aux)
> 
> define amdgpu_kernel void @f(<4 x i32> %rsrc, i32 %i1, i32 %i2, ptr addrspace(1) %out, ptr addrspace(3) %ptr) {
> main_body:
>   call void @llvm.amdgcn.raw.buffer.load.lds(<4 x i32> %rsrc, ptr addrspace(3) @lds.0, i32 4, i32 0, i32 0, i32 0, i32 0)
>   call void @llvm.amdgcn.raw.buffer.load.lds(<4 x i32> %rsrc, ptr addrspace(3) %ptr, i32 4, i32 0, i32 0, i32 0, i32 0)
>   %gep.0 = getelementptr float, ptr addrspace(3) @lds.0, i32 %i1
>   %gep.1 = getelementptr float, ptr addrspace(3) @lds.1, i32 %i2
>   %val.0 = load volatile float, ptr addrspace(3) %gep.0, align 4
>   %val.1 = load volatile float, ptr addrspace(3) %gep.1, align 4
>   %out.gep.1 = getelementptr float, ptr addrspace(1) %out, i32 1
>   store float %val.0, ptr addrspace(1) %out
>   store float %val.1, ptr addrspace(1) %out.gep.1
>   ret void
> }
> ```
> 
> Generates:
> 
> ```
> 	s_load_dwordx8 s[4:11], s[0:1], 0x24
> 	s_load_dword s2, s[0:1], 0x44
> 	s_mov_b32 m0, 0
> 	v_mov_b32_e32 v2, 0
> 	s_waitcnt lgkmcnt(0)
> 	buffer_load_dword off, s[4:7], 0 lds
> 	s_mov_b32 m0, s2
> 	s_lshl_b32 s0, s8, 2
> 	buffer_load_dword off, s[4:7], 0 lds
> 	s_lshl_b32 s1, s9, 2
> 	v_mov_b32_e32 v0, s0
> 	v_mov_b32_e32 v1, s1
> 	s_waitcnt vmcnt(1)
> 	ds_read_b32 v0, v0
> 	s_waitcnt vmcnt(0)
> 	ds_read_b32 v1, v1 offset:256
> 	s_waitcnt lgkmcnt(0)
> 	global_store_dwordx2 v2, v[0:1], s[10:11]
> 	s_endpgm
> ```
> 
> The `s_waitcnt vmcnt(1)` seems incorrect, because the second buffer-load-to-lds might clobber `@lds.0`.

This is still correct, pointer argument cannot alias module global. A pointer argument to a kernel is an LDS external requested by the host side, and host cannot see module LDS.

https://github.com/llvm/llvm-project/pull/74537


More information about the flang-commits mailing list