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 3 4; Variables that are not lowered by this pass are left unchanged 5; CHECK-NOT: asm 6; CHECK-NOT: llvm.amdgcn.module.lds 7; CHECK-NOT: llvm.amdgcn.module.lds.t 8 9; var1, var2 would be transformed were they used from a non-kernel function 10; CHECK-NOT: @var1 = 11; CHECK: @var2 = addrspace(3) global float undef 12@var1 = addrspace(3) global i32 undef 13@var2 = addrspace(3) global float undef 14 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 20 21; External and constant are both left to the optimizer / error diagnostics 22; CHECK: @extern = external addrspace(3) global i32 23@extern = external addrspace(3) global i32 24 25; Use of an addrspace(3) variable with an initializer is skipped, 26; so as to preserve the unimplemented error from llc 27; CHECK: @with_init = addrspace(3) global i64 0 28@with_init = addrspace(3) global i64 0 29 30; Only local addrspace variables are transformed 31; CHECK: @addr4 = addrspace(4) global i64 undef 32@addr4 = addrspace(4) global i64 undef 33 34; Assign to self is treated as any other initializer, i.e. ignored by this pass 35; CHECK: @toself = addrspace(3) global float addrspace(3)* bitcast (float addrspace(3)* addrspace(3)* @toself to float addrspace(3)*), align 8 36@toself = addrspace(3) global float addrspace(3)* bitcast (float addrspace(3)* addrspace(3)* @toself to float addrspace(3)*), align 8 37 38; Use by .used lists doesn't trigger lowering 39; CHECK-NOT: @llvm.used = 40@llvm.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(3)* bitcast (i32 addrspace(3)* @var1 to i8 addrspace(3)*) to i8*)], section "llvm.metadata" 41 42; CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(3)* bitcast (float addrspace(3)* @var2 to i8 addrspace(3)*) to i8*)], section "llvm.metadata" 43@llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(3)* bitcast (float addrspace(3)* @var2 to i8 addrspace(3)*) to i8*)], section "llvm.metadata" 44 45; Access from a function would cause lowering for non-excluded cases 46; CHECK-LABEL: @use_variables() 47; CHECK: %c0 = load i32, i32 addrspace(3)* @const_undef, align 4 48; CHECK: %c1 = load i64, i64 addrspace(3)* @const_with_init, align 4 49; CHECK: %v0 = atomicrmw add i64 addrspace(3)* @with_init, i64 1 seq_cst 50; CHECK: %v1 = cmpxchg i32 addrspace(3)* @extern, i32 4, i32 %c0 acq_rel monotonic 51; CHECK: %v2 = atomicrmw add i64 addrspace(4)* @addr4, i64 %c1 monotonic 52define void @use_variables() { 53 %c0 = load i32, i32 addrspace(3)* @const_undef, align 4 54 %c1 = load i64, i64 addrspace(3)* @const_with_init, align 4 55 %v0 = atomicrmw add i64 addrspace(3)* @with_init, i64 1 seq_cst 56 %v1 = cmpxchg i32 addrspace(3)* @extern, i32 4, i32 %c0 acq_rel monotonic 57 %v2 = atomicrmw add i64 addrspace(4)* @addr4, i64 %c1 monotonic 58 ret void 59} 60 61; CHECK-LABEL: @kern_use() 62; CHECK: %inc = atomicrmw add i32 addrspace(3)* getelementptr inbounds (%llvm.amdgcn.kernel.kern_use.lds.t, %llvm.amdgcn.kernel.kern_use.lds.t addrspace(3)* @llvm.amdgcn.kernel.kern_use.lds, i32 0, i32 0), i32 1 monotonic, align 4 63define amdgpu_kernel void @kern_use() { 64 %inc = atomicrmw add i32 addrspace(3)* @var1, i32 1 monotonic 65 call void @use_variables() 66 ret void 67} 68