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 < %s | FileCheck %s
3 ; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s | FileCheck %s
5 @lds.1 = internal unnamed_addr addrspace(3) global [2 x i8] undef, 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] }
14 ; Use constant from different kernels
16 ; CHECK: @llvm.amdgcn.kernel.k0.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k0.lds.t undef, align 2
17 ; CHECK: @llvm.amdgcn.kernel.k1.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k1.lds.t undef, align 2
18 ; CHECK: @llvm.amdgcn.kernel.k2.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k2.lds.t undef, align 4
19 ; CHECK: @llvm.amdgcn.kernel.k3.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k3.lds.t undef, align 16
20 ; CHECK: @llvm.amdgcn.kernel.k4.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k4.lds.t undef, align 2
21 ; CHECK: @llvm.amdgcn.kernel.k5.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k5.lds.t undef, align 16
23 define amdgpu_kernel void @k0(i64 %x) {
25 ; CHECK-NEXT: %1 = getelementptr inbounds [2 x i8], [2 x i8] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k0.lds.t, %llvm.amdgcn.kernel.k0.lds.t addrspace(3)* @llvm.amdgcn.kernel.k0.lds, i32 0, i32 0), i32 0, i32 0
26 ; CHECK-NEXT: %2 = addrspacecast i8 addrspace(3)* %1 to i8*
27 ; CHECK-NEXT: %ptr = getelementptr inbounds i8, i8* %2, i64 %x
28 ; CHECK-NEXT: store i8 1, i8* %ptr, align 1
29 ; CHECK-NEXT: ret void
31 %ptr = getelementptr inbounds i8, i8* addrspacecast ([2 x i8] addrspace(3)* @lds.1 to i8*), i64 %x
32 store i8 1, i8 addrspace(0)* %ptr, align 1
36 define amdgpu_kernel void @k1(i64 %x) {
38 ; CHECK-NEXT: %1 = getelementptr inbounds [2 x i8], [2 x i8] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k1.lds.t, %llvm.amdgcn.kernel.k1.lds.t addrspace(3)* @llvm.amdgcn.kernel.k1.lds, i32 0, i32 0), i32 0, i32 0
39 ; CHECK-NEXT: %2 = addrspacecast i8 addrspace(3)* %1 to i8*
40 ; CHECK-NEXT: %ptr = getelementptr inbounds i8, i8* %2, i64 %x
41 ; CHECK-NEXT: store i8 1, i8* %ptr, align 1
42 ; CHECK-NEXT: ret void
44 %ptr = getelementptr inbounds i8, i8* addrspacecast ([2 x i8] addrspace(3)* @lds.1 to i8*), i64 %x
45 store i8 1, i8 addrspace(0)* %ptr, align 1
49 @lds.2 = internal unnamed_addr addrspace(3) global i32 undef, align 4
51 ; Use constant twice from the same kernel
52 define amdgpu_kernel void @k2(i64 %x) {
54 ; CHECK-NEXT: %ptr1 = bitcast i32 addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k2.lds.t, %llvm.amdgcn.kernel.k2.lds.t addrspace(3)* @llvm.amdgcn.kernel.k2.lds, i32 0, i32 0) to i8 addrspace(3)*
55 ; CHECK-NEXT: store i8 1, i8 addrspace(3)* %ptr1, align 4
56 ; CHECK-NEXT: %ptr2 = bitcast i32 addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k2.lds.t, %llvm.amdgcn.kernel.k2.lds.t addrspace(3)* @llvm.amdgcn.kernel.k2.lds, i32 0, i32 0) to i8 addrspace(3)*
57 ; CHECK-NEXT: store i8 2, i8 addrspace(3)* %ptr2, align 4
58 ; CHECK-NEXT: ret void
60 %ptr1 = bitcast i32 addrspace(3)* @lds.2 to i8 addrspace(3)*
61 store i8 1, i8 addrspace(3)* %ptr1, align 4
62 %ptr2 = bitcast i32 addrspace(3)* @lds.2 to i8 addrspace(3)*
63 store i8 2, i8 addrspace(3)* %ptr2, align 4
67 @lds.3 = internal unnamed_addr addrspace(3) global [32 x i8] undef, align 1
69 ; Use constant twice from the same kernel but a different other constant.
70 define amdgpu_kernel void @k3(i64 %x) {
72 ; CHECK-NEXT: %1 = getelementptr inbounds [32 x i8], [32 x i8] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k3.lds.t, %llvm.amdgcn.kernel.k3.lds.t addrspace(3)* @llvm.amdgcn.kernel.k3.lds, i32 0, i32 0), i32 0, i32 16
73 ; CHECK-NEXT: %2 = bitcast i8 addrspace(3)* %1 to i64 addrspace(3)*
74 ; CHECK-NEXT: %ptr1 = addrspacecast i64 addrspace(3)* %2 to i64*
75 ; CHECK-NEXT: store i64 1, i64* %ptr1, align 1
76 ; CHECK-NEXT: %3 = getelementptr inbounds [32 x i8], [32 x i8] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k3.lds.t, %llvm.amdgcn.kernel.k3.lds.t addrspace(3)* @llvm.amdgcn.kernel.k3.lds, i32 0, i32 0), i32 0, i32 24
77 ; CHECK-NEXT: %4 = bitcast i8 addrspace(3)* %3 to i64 addrspace(3)*
78 ; CHECK-NEXT: %ptr2 = addrspacecast i64 addrspace(3)* %4 to i64*
79 ; CHECK-NEXT: store i64 2, i64* %ptr2, align 8
80 ; CHECK-NEXT: ret void
82 %ptr1 = addrspacecast i64 addrspace(3)* bitcast (i8 addrspace(3)* getelementptr inbounds ([32 x i8], [32 x i8] addrspace(3)* @lds.3, i32 0, i32 16) to i64 addrspace(3)*) to i64*
83 store i64 1, i64* %ptr1, align 1
84 %ptr2 = addrspacecast i64 addrspace(3)* bitcast (i8 addrspace(3)* getelementptr inbounds ([32 x i8], [32 x i8] addrspace(3)* @lds.3, i32 0, i32 24) to i64 addrspace(3)*) to i64*
85 store i64 2, i64* %ptr2, align 1
89 ; @lds.1 is used from constant expressions in different kernels.
90 define amdgpu_kernel void @k4(i64 %x) {
92 ; CHECK-NEXT: %1 = getelementptr inbounds [2 x i8], [2 x i8] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k4.lds.t, %llvm.amdgcn.kernel.k4.lds.t addrspace(3)* @llvm.amdgcn.kernel.k4.lds, i32 0, i32 0), i32 0, i32 0
93 ; CHECK-NEXT: %2 = addrspacecast i8 addrspace(3)* %1 to i8*
94 ; CHECK-NEXT: %ptr = getelementptr inbounds i8, i8* %2, i64 %x
95 ; CHECK-NEXT: store i8 1, i8* %ptr, align 1
96 ; CHECK-NEXT: ret void
98 %ptr = getelementptr inbounds i8, i8* addrspacecast ([2 x i8] addrspace(3)* @lds.1 to i8*), i64 %x
99 store i8 1, i8 addrspace(0)* %ptr, align 1
103 @lds.4 = internal unnamed_addr addrspace(3) global [505 x i32] undef, align 4
105 ; Multiple constexpr use in a same instruction.
106 define amdgpu_kernel void @k5() {
108 ; CHECK-NEXT: %1 = addrspacecast [505 x i32] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.k5.lds.t, %llvm.amdgcn.kernel.k5.lds.t addrspace(3)* @llvm.amdgcn.kernel.k5.lds, i32 0, i32 0) to [505 x i32]*
109 ; CHECK-NEXT: %2 = getelementptr inbounds [505 x i32], [505 x i32]* %1, i64 0, i64 0
110 ; CHECK-NEXT: call void undef(i32* %2, i32* %2)
112 call void undef(i32* getelementptr inbounds ([505 x i32], [505 x i32]* addrspacecast ([505 x i32] addrspace(3)* @lds.4 to [505 x i32]*), i64 0, i64 0), i32* getelementptr inbounds ([505 x i32], [505 x i32]* addrspacecast ([505 x i32] addrspace(3)* @lds.4 to [505 x i32]*), i64 0, i64 0))