[amdgpu] Always, instead of mostly, remove unused LDS symbols
authorJon Chesterfield <jonathanchesterfield@gmail.com>
Wed, 7 Sep 2022 17:28:14 +0000 (18:28 +0100)
committerJon Chesterfield <jonathanchesterfield@gmail.com>
Wed, 7 Sep 2022 17:28:16 +0000 (18:28 +0100)
Currently LDS variables are removed by the lower module pass
if they have a use which is caught by the replace with struct control flow.
This makes tests brittle to changes to that control flow which induces
noise when trying to improve lowering. Some tests already check that
variables are removed, while others checked that they are not removed.

LDS variables are not (currently) externally accessible, and if that
changes the machinery which makes them externally accessible will look
like a use. This change therefore breaks no applications.

Reviewed By: rampitec

Differential Revision: https://reviews.llvm.org/D133028

llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
llvm/test/CodeGen/AMDGPU/lower-kernel-lds-super-align.ll
llvm/test/CodeGen/AMDGPU/lower-kernel-lds.ll

index bc0558c..243d9ce 100644 (file)
@@ -244,6 +244,10 @@ public:
       }
     }
 
+    for (auto &GV : make_early_inc_range(M.globals()))
+      if (AMDGPU::isLDSVariableToLower(GV) && GV.use_empty())
+        GV.eraseFromParent();
+    
     return Changed;
   }
 
index a6225bc..dfad39c 100644 (file)
@@ -12,6 +12,8 @@
 ; SUPER-ALIGN_OFF: @lds.unused = addrspace(3) global i32 undef, align 2
 @lds.unused = addrspace(3) global i32 undef, align 2
 
+@llvm.used = appending global [1 x i8*] [i8* addrspacecast (i32 addrspace(3)* @lds.unused to i8*)], section "llvm.metadata"
+
 ; CHECK-NOT: @lds.1
 @lds.1 = internal unnamed_addr addrspace(3) global [32 x i8] undef, align 1
 
index c8592c7..29159f1 100644 (file)
@@ -4,14 +4,12 @@
 @lds.size.1.align.1 = internal unnamed_addr addrspace(3) global [1 x i8] undef, align 1
 @lds.size.2.align.2 = internal unnamed_addr addrspace(3) global [2 x i8] undef, align 2
 @lds.size.4.align.4 = internal unnamed_addr addrspace(3) global [4 x i8] undef, align 4
-@lds.size.8.align.8 = internal unnamed_addr addrspace(3) global [8 x i8] undef, align 8
 @lds.size.16.align.16 = internal unnamed_addr addrspace(3) global [16 x i8] undef, align 16
 
 ; CHECK: %llvm.amdgcn.kernel.k0.lds.t = type { [16 x i8], [4 x i8], [2 x i8], [1 x i8] }
 ; CHECK: %llvm.amdgcn.kernel.k1.lds.t = type { [16 x i8], [4 x i8], [2 x i8] }
 
 ;.
-; CHECK: @lds.size.8.align.8 = internal unnamed_addr addrspace(3) global [8 x i8] undef, align 8
 ; CHECK: @lds.k2 = addrspace(3) global [1 x i8] undef, align 1
 ; CHECK: @llvm.amdgcn.kernel.k0.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k0.lds.t undef, align 16
 ; CHECK: @llvm.amdgcn.kernel.k1.lds = internal addrspace(3) global %llvm.amdgcn.kernel.k1.lds.t undef, align 16