llvm-project/llvm/test/CodeGen/AMDGPU/addrspacecast-known-non-null.ll
Venkata Ramanaiah Nalamothu 04fff547e2 [AMDGPU] Move call clobbered return address registers s[30:31] to callee saved range
Currently the return address ABI registers s[30:31], which fall in the call
clobbered register range, are added as a live-in on the function entry to
preserve its value when we have calls so that it gets saved and restored
around the calls.

But the DWARF unwind information (CFI) needs to track where the return address
resides in a frame and the above approach makes it difficult to track the
return address when the CFI information is emitted during the frame lowering,
due to the involvment of understanding the control flow.

This patch moves the return address ABI registers s[30:31] into callee saved
registers range and stops adding live-in for return address registers, so that
the CFI machinery will know where the return address resides when CSR
save/restore happen during the frame lowering.

And doing the above poses an issue that now the return instruction uses undefined
register `sgpr30_sgpr31`. This is resolved by hiding the return address register
use by the return instruction through the `SI_RETURN` pseudo instruction, which
doesn't take any input operands, until the `SI_RETURN` pseudo gets lowered to the
`S_SETPC_B64_return` during the `expandPostRAPseudo()`.

As an added benefit, this patch simplifies overall return instruction handling.

Note: The AMDGPU CFI changes are there only in the downstream code and another
version of this patch will be posted for review for the downstream code.

Reviewed By: arsenm, ronlieb

Differential Revision: https://reviews.llvm.org/D114652
2022-03-09 12:18:02 +05:30

76 lines
2.5 KiB
LLVM

; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -o - %s | FileCheck %s
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -o - %s | FileCheck %s
; Test that a null check is not emitted for lowered addrspacecast
define void @flat_user(i8* %ptr) {
store i8 0, i8* %ptr
ret void
}
; CHECK-LABEL: {{^}}cast_alloca:
; CHECK: s_getreg_b32 [[GETREG:s[0-9]+]], hwreg(HW_REG_SH_MEM_BASES, 0, 16)
; CHECK: s_lshl_b32 [[APERTURE:s[0-9]+]], [[GETREG]], 16
; CHECK: v_lshrrev_b32_e64 v0, 6, s33
; CHECK-NEXT: v_mov_b32_e32 v1, [[APERTURE]]
; CHECK-NOT: v0
; CHECK-NOT: v1
define void @cast_alloca() {
%alloca = alloca i8, addrspace(5)
%cast = addrspacecast i8 addrspace(5)* %alloca to i8*
call void @flat_user(i8* %cast)
ret void
}
@lds = internal unnamed_addr addrspace(3) global i8 undef, align 4
; CHECK-LABEL: {{^}}cast_lds_gv:
; CHECK: s_getreg_b32 [[GETREG:s[0-9]+]], hwreg(HW_REG_SH_MEM_BASES, 16, 16)
; CHECK: s_lshl_b32 [[APERTURE:s[0-9]+]], [[GETREG]], 16
; CHECK: v_mov_b32_e32 v0, 0
; CHECK: v_mov_b32_e32 v1, [[APERTURE]]
; CHECK-NOT: v0
; CHECK-NOT: v1
define void @cast_lds_gv() {
%cast = addrspacecast i8 addrspace(3)* @lds to i8*
call void @flat_user(i8* %cast)
ret void
}
; CHECK-LABEL: {{^}}cast_constant_lds_neg1_gv:
; CHECK: v_mov_b32_e32 v0, 0
; CHECK: v_mov_b32_e32 v1, 0
define void @cast_constant_lds_neg1_gv() {
call void @flat_user(i8* addrspacecast (i8 addrspace(3)* inttoptr (i32 -1 to i8 addrspace(3)*) to i8*))
ret void
}
; CHECK-LABEL: {{^}}cast_constant_private_neg1_gv:
; CHECK: v_mov_b32_e32 v0, 0
; CHECK: v_mov_b32_e32 v1, 0
define void @cast_constant_private_neg1_gv() {
call void @flat_user(i8* addrspacecast (i8 addrspace(5)* inttoptr (i32 -1 to i8 addrspace(5)*) to i8*))
ret void
}
; CHECK-LABEL: {{^}}cast_constant_lds_other_gv:
; CHECK: s_getreg_b32 [[GETREG:s[0-9]+]], hwreg(HW_REG_SH_MEM_BASES, 16, 16)
; CHECK: s_lshl_b32 [[APERTURE:s[0-9]+]], [[GETREG]], 16
; CHECK: v_mov_b32_e32 v0, 0x7b
; CHECK: v_mov_b32_e32 v1, [[APERTURE]]
define void @cast_constant_lds_other_gv() {
call void @flat_user(i8* addrspacecast (i8 addrspace(3)* inttoptr (i32 123 to i8 addrspace(3)*) to i8*))
ret void
}
; CHECK-LABEL: {{^}}cast_constant_private_other_gv:
; CHECK: s_getreg_b32 [[GETREG:s[0-9]+]], hwreg(HW_REG_SH_MEM_BASES, 0, 16)
; CHECK: s_lshl_b32 [[APERTURE:s[0-9]+]], [[GETREG]], 16
; CHECK: v_mov_b32_e32 v0, 0x7b
; CHECK: v_mov_b32_e32 v1, [[APERTURE]]
define void @cast_constant_private_other_gv() {
call void @flat_user(i8* addrspacecast (i8 addrspace(5)* inttoptr (i32 123 to i8 addrspace(5)*) to i8*))
ret void
}