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
4 ; Variables that are not lowered by this pass are left unchanged
6 ; CHECK-NOT: llvm.amdgcn.module.lds
7 ; CHECK-NOT: llvm.amdgcn.module.lds.t
9 ; var1 is removed, var2 stays because it's in compiler.used
11 ; CHECK: @var2 = addrspace(3) global float undef
12 @var1 = addrspace(3) global i32 undef
13 @var2 = addrspace(3) global float undef
15 ; constant variables are left to the optimizer / error diagnostics
16 ; CHECK: @const_undef = addrspace(3) constant i32 undef
17 ; CHECK: @const_with_init = addrspace(3) constant i64 8
18 @const_undef = addrspace(3) constant i32 undef
19 @const_with_init = addrspace(3) constant i64 8
21 ; Use of an addrspace(3) variable with an initializer is skipped,
22 ; so as to preserve the unimplemented error from llc
23 ; CHECK: @with_init = addrspace(3) global i64 0
24 @with_init = addrspace(3) global i64 0
26 ; Only local addrspace variables are transformed
27 ; CHECK: @addr4 = addrspace(4) global i64 undef
28 @addr4 = addrspace(4) global i64 undef
30 ; Assign to self is treated as any other initializer, i.e. ignored by this pass
31 ; CHECK: @toself = addrspace(3) global ptr addrspace(3) @toself, align 8
32 @toself = addrspace(3) global ptr addrspace(3) @toself, align 8
34 ; Use by .used lists doesn't trigger lowering
35 ; CHECK-NOT: @llvm.used =
36 @llvm.used = appending global [1 x ptr] [ptr addrspacecast (ptr addrspace(3) @var1 to ptr)], section "llvm.metadata"
38 ; CHECK: @llvm.compiler.used = appending global [1 x ptr] [ptr addrspacecast (ptr addrspace(3) @var2 to ptr)], section "llvm.metadata"
39 @llvm.compiler.used = appending global [1 x ptr] [ptr addrspacecast (ptr addrspace(3) @var2 to ptr)], section "llvm.metadata"
41 ; Access from a function would cause lowering for non-excluded cases
42 ; CHECK-LABEL: @use_variables()
43 ; CHECK: %c0 = load i32, ptr addrspace(3) @const_undef, align 4
44 ; CHECK: %c1 = load i64, ptr addrspace(3) @const_with_init, align 4
45 ; CHECK: %v0 = atomicrmw add ptr addrspace(3) @with_init, i64 1 seq_cst
46 ; CHECK: %v1 = atomicrmw add ptr addrspace(4) @addr4, i64 %c1 monotonic
47 define void @use_variables() {
48 %c0 = load i32, ptr addrspace(3) @const_undef, align 4
49 %c1 = load i64, ptr addrspace(3) @const_with_init, align 4
50 %v0 = atomicrmw add ptr addrspace(3) @with_init, i64 1 seq_cst
51 %v1 = atomicrmw add ptr addrspace(4) @addr4, i64 %c1 monotonic
55 ; CHECK-LABEL: @kern_use()
56 ; CHECK: %inc = atomicrmw add ptr addrspace(3) @llvm.amdgcn.kernel.kern_use.lds, i32 1 monotonic, align 4
57 define amdgpu_kernel void @kern_use() {
58 %inc = atomicrmw add ptr addrspace(3) @var1, i32 1 monotonic
59 call void @use_variables()