Don't count register uses when determining the maximum number of registers used by a function. Count only the defs. This is really an underestimate of the true register usage, but in practice that's not a problem because if a function uses a register, then it has either defined it earlier, or some other function that executed before has defined it. In particular, the register counts are used: 1. When launching an entry function - in which case we're safe because the register counts of the entry function will include the register counts of all callees. 2. At function boundaries in dynamic VGPR mode. In this case it's safe because whenever we set the new VGPR allocation we take into account the outgoing_vgpr_count set by the middle-end. The main advantage of doing this is that the artificial VGPR arguments used only for preserving the inactive lanes when using the llvm.amdgcn.init.whole.wave intrinsic are no longer counted. This enables us to allocate only the registers we need in dynamic VGPR mode. --------- Co-authored-by: Thomas Symalla <5754458+tsymalla@users.noreply.github.com>
36 lines
1.1 KiB
LLVM
36 lines
1.1 KiB
LLVM
; RUN: llc -mcpu=gfx1200 -o - < %s | FileCheck %s
|
|
; Check that reads of a VGPR in kernels counts towards VGPR count, but in functions, only writes of VGPRs count towards VGPR count.
|
|
target triple = "amdgcn--amdpal"
|
|
|
|
@global = addrspace(1) global i32 poison, align 4
|
|
|
|
; CHECK-LABEL: amdpal.pipelines:
|
|
|
|
; Neither uses not writes a VGPR, but the hardware initializes the VGPRs that the kernel receives, so they count as used.
|
|
; CHECK-LABEL: .entry_point_symbol: kernel_use
|
|
; CHECK: .vgpr_count: 0x20
|
|
define amdgpu_cs void @kernel_use([32 x i32] %args) {
|
|
entry:
|
|
%a = extractvalue [32 x i32] %args, 14
|
|
store i32 %a, ptr addrspace(1) @global
|
|
ret void
|
|
}
|
|
|
|
; Neither uses not writes a VGPR
|
|
; CHECK-LABEL: chain_func:
|
|
; CHECK: .vgpr_count: 0x1
|
|
define amdgpu_cs_chain void @chain_func([32 x i32] %args) {
|
|
entry:
|
|
call void (ptr, i32, {}, [32 x i32], i32, ...) @llvm.amdgcn.cs.chain.p0.i32.s.a(
|
|
ptr @chain_func, i32 0, {} inreg {}, [32 x i32] %args, i32 0)
|
|
unreachable
|
|
}
|
|
|
|
; Neither uses not writes a VGPR
|
|
; CHECK-LABEL: gfx_func:
|
|
; CHECK: .vgpr_count: 0x1
|
|
define amdgpu_gfx [32 x i32] @gfx_func([32 x i32] %args) {
|
|
entry:
|
|
ret [32 x i32] %args
|
|
}
|