1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=hybrid < %s | FileCheck %s
4 ;; Reduced from a larger test case. Checks that functions and kernels that use only dynamic lds
5 ;; are lowered successfully. Previously they only worked if the kernel happened to also use static lds
6 ;; variables. Artefact of implementing dynamic variables by adapting existing code for static.
8 @A = external addrspace(3) global [8 x ptr]
9 @B = external addrspace(3) global [0 x i32]
11 define amdgpu_kernel void @kernel_0() {
12 ; CHECK-LABEL: define amdgpu_kernel void @kernel_0() #0 !llvm.amdgcn.lds.kernel.id !1 {
13 ; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.kernel.kernel_0.lds) ]
14 ; CHECK-NEXT: call void @call_store_A()
15 ; CHECK-NEXT: ret void
17 call void @call_store_A()
21 define amdgpu_kernel void @kernel_1() {
22 ; CHECK-LABEL: define amdgpu_kernel void @kernel_1() !llvm.amdgcn.lds.kernel.id !2 {
23 ; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.kernel_1.dynlds) ]
24 ; CHECK-NEXT: [[PTR:%.*]] = call ptr @get_B_ptr()
25 ; CHECK-NEXT: ret void
27 %ptr = call ptr @get_B_ptr()
31 define amdgpu_kernel void @kernel_2() {
32 ; CHECK-LABEL: define amdgpu_kernel void @kernel_2() #0 !llvm.amdgcn.lds.kernel.id !3 {
33 ; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.kernel.kernel_2.lds) ]
34 ; CHECK-NEXT: call void @store_A()
35 ; CHECK-NEXT: ret void
41 define amdgpu_kernel void @kernel_3() {
42 ; CHECK-LABEL: define amdgpu_kernel void @kernel_3() !llvm.amdgcn.lds.kernel.id !4 {
43 ; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.kernel_3.dynlds) ]
44 ; CHECK-NEXT: [[PTR:%.*]] = call ptr @get_B_ptr()
45 ; CHECK-NEXT: ret void
47 %ptr = call ptr @get_B_ptr()
51 define private void @call_store_A() {
52 ; CHECK-LABEL: define private void @call_store_A() {
53 ; CHECK-NEXT: call void @store_A()
54 ; CHECK-NEXT: ret void
60 define private void @store_A() {
61 ; CHECK-LABEL: define private void @store_A() {
62 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.amdgcn.lds.kernel.id()
63 ; CHECK-NEXT: [[A:%.*]] = getelementptr inbounds [4 x [1 x i32]], ptr addrspace(4) @llvm.amdgcn.lds.offset.table, i32 0, i32 [[TMP1]], i32 0
64 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr addrspace(4) [[A]], align 4
65 ; CHECK-NEXT: [[A1:%.*]] = inttoptr i32 [[TMP2]] to ptr addrspace(3)
66 ; CHECK-NEXT: [[TMP3:%.*]] = addrspacecast ptr addrspace(3) [[A1]] to ptr
67 ; CHECK-NEXT: store ptr [[TMP3]], ptr null, align 8
68 ; CHECK-NEXT: ret void
70 store ptr addrspacecast (ptr addrspace(3) @A to ptr), ptr null
74 define private ptr @get_B_ptr() {
75 ; CHECK-LABEL: define private ptr @get_B_ptr() {
76 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.amdgcn.lds.kernel.id()
77 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds [4 x i32], ptr addrspace(4) @llvm.amdgcn.dynlds.offset.table, i32 0, i32 [[TMP1]]
78 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr addrspace(4) [[B]], align 4
79 ; CHECK-NEXT: [[B1:%.*]] = inttoptr i32 [[TMP2]] to ptr addrspace(3)
80 ; CHECK-NEXT: [[TMP3:%.*]] = addrspacecast ptr addrspace(3) [[B1]] to ptr
81 ; CHECK-NEXT: ret ptr [[TMP3]]
83 ret ptr addrspacecast (ptr addrspace(3) @B to ptr)
86 ; CHECK: attributes #0 = { "amdgpu-lds-size"="64" }