1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --check-globals
2 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s | FileCheck %s
3 ; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s | FileCheck %s
5 @lds.1 = internal unnamed_addr addrspace(3) global [2 x i8] poison, align 1
7 ; CHECK: %llvm.amdgcn.kernel.k0.lds.t = type { [2 x i8] }
8 ; CHECK: %llvm.amdgcn.kernel.k1.lds.t = type { [2 x i8] }
9 ; CHECK: %llvm.amdgcn.kernel.k2.lds.t = type { i32 }
10 ; CHECK: %llvm.amdgcn.kernel.k3.lds.t = type { [32 x i8] }
11 ; CHECK: %llvm.amdgcn.kernel.k4.lds.t = type { [2 x i8] }
12 ; CHECK: %llvm.amdgcn.kernel.k5.lds.t = type { [505 x i32] }
13 ; CHECK: %llvm.amdgcn.kernel.k6.lds.t = type { [4 x i32] }
15 ; Use constant from different kernels
17 ; CHECK: @llvm.amdgcn.kernel.k0.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k0.lds.t poison, align 2
18 ; CHECK: @llvm.amdgcn.kernel.k1.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k1.lds.t poison, align 2
19 ; CHECK: @llvm.amdgcn.kernel.k2.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k2.lds.t poison, align 4
20 ; CHECK: @llvm.amdgcn.kernel.k3.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k3.lds.t poison, align 16
21 ; CHECK: @llvm.amdgcn.kernel.k4.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k4.lds.t poison, align 2
22 ; CHECK: @llvm.amdgcn.kernel.k5.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k5.lds.t poison, align 16
23 ; CHECK: @llvm.amdgcn.kernel.k6.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k6.lds.t poison, align 16
25 define amdgpu_kernel void @k0(i64 %x) {
27 ; CHECK-NEXT: %1 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.k0.lds to ptr
28 ; CHECK-NEXT: %ptr = getelementptr inbounds i8, ptr %1, i64 %x
29 ; CHECK-NEXT: store i8 1, ptr %ptr, align 1
30 ; CHECK-NEXT: ret void
32 %ptr = getelementptr inbounds i8, ptr addrspacecast (ptr addrspace(3) @lds.1 to ptr), i64 %x
33 store i8 1, ptr addrspace(0) %ptr, align 1
37 define amdgpu_kernel void @k1(i64 %x) {
39 ; CHECK-NEXT: %1 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.k1.lds to ptr
40 ; CHECK-NEXT: %ptr = getelementptr inbounds i8, ptr %1, i64 %x
41 ; CHECK-NEXT: store i8 1, ptr %ptr, align 1
42 ; CHECK-NEXT: ret void
44 %ptr = getelementptr inbounds i8, ptr addrspacecast (ptr addrspace(3) @lds.1 to ptr), i64 %x
45 store i8 1, ptr addrspace(0) %ptr, align 1
49 @lds.2 = internal unnamed_addr addrspace(3) global i32 poison, align 4
51 ; Use constant twice from the same kernel
52 define amdgpu_kernel void @k2(i64 %x) {
54 ; CHECK-NEXT: store i8 1, ptr addrspace(3) @llvm.amdgcn.kernel.k2.lds, align 4
55 ; CHECK-NEXT: store i8 2, ptr addrspace(3) @llvm.amdgcn.kernel.k2.lds, align 4
56 ; CHECK-NEXT: ret void
58 store i8 1, ptr addrspace(3) @lds.2, align 4
59 store i8 2, ptr addrspace(3) @lds.2, align 4
63 @lds.3 = internal unnamed_addr addrspace(3) global [32 x i8] poison, align 1
65 ; Use constant twice from the same kernel but a different other constant.
66 define amdgpu_kernel void @k3(i64 %x) {
68 ; CHECK-NEXT: %1 = getelementptr inbounds [32 x i8], ptr addrspace(3) @llvm.amdgcn.kernel.k3.lds, i32 0, i32 16
69 ; CHECK-NEXT: %ptr1 = addrspacecast ptr addrspace(3) %1 to ptr
70 ; CHECK-NEXT: store i64 1, ptr %ptr1, align 1
71 ; CHECK-NEXT: %2 = getelementptr inbounds [32 x i8], ptr addrspace(3) @llvm.amdgcn.kernel.k3.lds, i32 0, i32 24
72 ; CHECK-NEXT: %ptr2 = addrspacecast ptr addrspace(3) %2 to ptr
73 ; CHECK-NEXT: store i64 2, ptr %ptr2, align 8
74 ; CHECK-NEXT: ret void
76 %ptr1 = addrspacecast ptr addrspace(3) getelementptr inbounds ([32 x i8], ptr addrspace(3) @lds.3, i32 0, i32 16) to ptr
77 store i64 1, ptr %ptr1, align 1
78 %ptr2 = addrspacecast ptr addrspace(3) getelementptr inbounds ([32 x i8], ptr addrspace(3) @lds.3, i32 0, i32 24) to ptr
79 store i64 2, ptr %ptr2, align 1
83 ; @lds.1 is used from constant expressions in different kernels.
84 define amdgpu_kernel void @k4(i64 %x) {
86 ; CHECK-NEXT: %1 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.k4.lds to ptr
87 ; CHECK-NEXT: %ptr = getelementptr inbounds i8, ptr %1, i64 %x
88 ; CHECK-NEXT: store i8 1, ptr %ptr, align 1
89 ; CHECK-NEXT: ret void
91 %ptr = getelementptr inbounds i8, ptr addrspacecast (ptr addrspace(3) @lds.1 to ptr), i64 %x
92 store i8 1, ptr addrspace(0) %ptr, align 1
96 @lds.4 = internal unnamed_addr addrspace(3) global [505 x i32] poison, align 4
98 ; Multiple constexpr use in a same instruction.
99 define amdgpu_kernel void @k5() {
101 ; CHECK-NEXT: %1 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.k5.lds to ptr
102 ; CHECK-NEXT: %2 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.k5.lds to ptr
103 ; CHECK-NEXT: call void poison(ptr %1, ptr %2)
105 call void poison(ptr addrspacecast (ptr addrspace(3) @lds.4 to ptr), ptr addrspacecast (ptr addrspace(3) @lds.4 to ptr))
109 @lds.5 = internal addrspace(3) global [4 x i32] poison, align 4
111 ; Both the *value* and *pointer* operands of store instruction are constant expressions, and
112 ; both of these constant expression paths use same lds - @lds.5. Hence both of these constant
113 ; expression operands of store should be replaced by equivalent instruction sequences.
114 define amdgpu_kernel void @k6() {
117 ; CHECK-NEXT: %1 = getelementptr inbounds [4 x i32], ptr addrspace(3) @llvm.amdgcn.kernel.k6.lds, i32 0, i32 2
118 ; CHECK-NEXT: %2 = ptrtoint ptr addrspace(3) %1 to i32
119 ; CHECK-NEXT: %3 = getelementptr inbounds [4 x i32], ptr addrspace(3) @llvm.amdgcn.kernel.k6.lds, i32 0, i32 2
120 ; CHECK-NEXT: store i32 %2, ptr addrspace(3) %3, align 8
121 ; CHECK-NEXT: ret void
123 store i32 ptrtoint (ptr addrspace(3) getelementptr inbounds ([4 x i32], ptr addrspace(3) @lds.5, i32 0, i32 2) to i32), ptr addrspace(3) getelementptr inbounds ([4 x i32], ptr addrspace(3) @lds.5, i32 0, i32 2)