1 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds < %s | FileCheck %s
2 ; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s | FileCheck %s
5 ; @lds.1: is aliased with @alias.to.lds.1, and @alias.to.lds.1 is used within kernel @k0.
6 ; Hence, @lds.1 is lowered.
7 ; @lds.2: is aliased with @alias.to.lds.2, and @alias.to.lds.2 is used within non-kernel @f0,
8 ; Hence, @lds.2 is lowered.
9 ; @lds.3: is used as initializer to global @gptr.3, and @gptr.3 is aliased with @alias.to.gptr.3,
10 ; and @alias.to.gptr.3 is used within kernel @k1. Hence, @lds.3 is lowered.
11 ; @lds.4: is used as initializer to global @gptr.4, and @gptr.4 is aliased with @alias.to.gptr.4,
12 ; and @alias.to.gptr.4 is used within non-kernel @f1. Hence, @lds.4 is lowered.
13 ; @lds.5: is aliased with @alias.to.lds.5, but neither @lds.5 nor @alias.to.lds.5 is used anywhere.
14 ; Hence, @lds.5 is not lowered.
15 ; @lds.6: is used as initializer to global @gptr.6, and @gptr.6 is aliased with @alias.to.gptr.6.
16 ; But none of them are used anywhere. Hence, @lds.6 is not lowered.
19 ; CHECK: %llvm.amdgcn.module.lds.t = type { [4 x i8], [3 x i8], [1 x i8], [2 x i8] }
25 ; CHECK: @lds.5 = internal unnamed_addr addrspace(3) global [5 x i8] undef, align 8
26 ; CHECK: @lds.6 = internal unnamed_addr addrspace(3) global [6 x i8] undef, align 8
27 @lds.1 = internal unnamed_addr addrspace(3) global [1 x i8] undef, align 1
28 @lds.2 = internal unnamed_addr addrspace(3) global [2 x i8] undef, align 2
29 @lds.3 = internal unnamed_addr addrspace(3) global [3 x i8] undef, align 4
30 @lds.4 = internal unnamed_addr addrspace(3) global [4 x i8] undef, align 4
31 @lds.5 = internal unnamed_addr addrspace(3) global [5 x i8] undef, align 8
32 @lds.6 = internal unnamed_addr addrspace(3) global [6 x i8] undef, align 8
34 ; CHECK: @gptr.3 = addrspace(1) global i64* addrspacecast (i64 addrspace(3)* bitcast ([3 x i8] addrspace(3)* getelementptr inbounds (%llvm.amdgcn.module.lds.t, %llvm.amdgcn.module.lds.t addrspace(3)* @llvm.amdgcn.module.lds, i32 0, i32 1) to i64 addrspace(3)*) to i64*), align 8
35 ; CHECK: @gptr.4 = addrspace(1) global i64* addrspacecast (i64 addrspace(3)* bitcast (%llvm.amdgcn.module.lds.t addrspace(3)* @llvm.amdgcn.module.lds to i64 addrspace(3)*) to i64*), align 8
36 ; CHECK: @gptr.6 = addrspace(1) global i64* addrspacecast (i64 addrspace(3)* bitcast ([6 x i8] addrspace(3)* @lds.6 to i64 addrspace(3)*) to i64*), align 8
37 @gptr.3 = addrspace(1) global i64* addrspacecast ([3 x i8] addrspace(3)* @lds.3 to i64*), align 8
38 @gptr.4 = addrspace(1) global i64* addrspacecast ([4 x i8] addrspace(3)* @lds.4 to i64*), align 8
39 @gptr.6 = addrspace(1) global i64* addrspacecast ([6 x i8] addrspace(3)* @lds.6 to i64*), align 8
41 ; CHECK: @llvm.amdgcn.module.lds = internal addrspace(3) global %llvm.amdgcn.module.lds.t undef, align 4
42 ; CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(3)* getelementptr inbounds (%llvm.amdgcn.module.lds.t, %llvm.amdgcn.module.lds.t addrspace(3)* @llvm.amdgcn.module.lds, i32 0, i32 0, i32 0) to i8*)], section "llvm.metadata"
44 ; CHECK: @alias.to.lds.1 = alias [1 x i8], getelementptr inbounds (%llvm.amdgcn.module.lds.t, %llvm.amdgcn.module.lds.t addrspace(3)* @llvm.amdgcn.module.lds, i32 0, i32 2)
45 ; CHECK: @alias.to.lds.2 = alias [2 x i8], getelementptr inbounds (%llvm.amdgcn.module.lds.t, %llvm.amdgcn.module.lds.t addrspace(3)* @llvm.amdgcn.module.lds, i32 0, i32 3)
46 ; CHECK: @alias.to.gptr.3 = alias i64*, i64* addrspace(1)* @gptr.3
47 ; CHECK: @alias.to.gptr.4 = alias i64*, i64* addrspace(1)* @gptr.4
48 ; CHECK: @alias.to.lds.5 = alias [5 x i8], [5 x i8] addrspace(3)* @lds.5
49 ; CHECK: @alias.to.gptr.6 = alias i64*, i64* addrspace(1)* @gptr.6
50 @alias.to.lds.1 = alias [1 x i8], [1 x i8] addrspace(3)* @lds.1
51 @alias.to.lds.2 = alias [2 x i8], [2 x i8] addrspace(3)* @lds.2
52 @alias.to.gptr.3 = alias i64*, i64* addrspace(1)* @gptr.3
53 @alias.to.gptr.4 = alias i64*, i64* addrspace(1)* @gptr.4
54 @alias.to.lds.5 = alias [5 x i8], [5 x i8] addrspace(3)* @lds.5
55 @alias.to.gptr.6 = alias i64*, i64* addrspace(1)* @gptr.6
58 ; CHECK: %ld = load i64*, i64* addrspace(1)* @alias.to.gptr.4, align 8
61 %ld = load i64*, i64* addrspace(1)* @alias.to.gptr.4
66 ; CHECK: %bc = bitcast [2 x i8] addrspace(3)* @alias.to.lds.2 to i8 addrspace(3)*
67 ; CHECK: store i8 1, i8 addrspace(3)* %bc, align 2
70 %bc = bitcast [2 x i8] addrspace(3)* @alias.to.lds.2 to i8 addrspace(3)*
71 store i8 1, i8 addrspace(3)* %bc, align 2
76 ; CHECK-LABEL: call void @llvm.donothing() [ "ExplicitUse"(%llvm.amdgcn.module.lds.t addrspace(3)* @llvm.amdgcn.module.lds) ]
77 ; CHECK-LABEL: %ld = load i64*, i64* addrspace(1)* @alias.to.gptr.3, align 8
78 ; CHECK-LABEL: ret void
79 define amdgpu_kernel void @k1() {
80 %ld = load i64*, i64* addrspace(1)* @alias.to.gptr.3
85 ; CHECK-LABEL: call void @llvm.donothing() [ "ExplicitUse"(%llvm.amdgcn.module.lds.t addrspace(3)* @llvm.amdgcn.module.lds) ]
86 ; CHECK-LABEL: %bc = bitcast [1 x i8] addrspace(3)* @alias.to.lds.1 to i8 addrspace(3)*
87 ; CHECK-LABEL: store i8 1, i8 addrspace(3)* %bc, align 1
88 ; CHECK-LABEL: ret void
89 define amdgpu_kernel void @k0() {
90 %bc = bitcast [1 x i8] addrspace(3)* @alias.to.lds.1 to i8 addrspace(3)*
91 store i8 1, i8 addrspace(3)* %bc, align 1