From 45f5e0bc5b30db33aeadb2cbe15ebc980aa4270b Mon Sep 17 00:00:00 2001 From: Scott Linder Date: Wed, 5 Feb 2025 22:56:55 +0000 Subject: [PATCH 1/3] [AMDGPU] Remove dead function metadata after amdgpu-lower-kernel-arguments The verifier ensures function !dbg metadata is unique across the module, so ensure the old nameless function we leave behind doesn't violate this invariant. Removing the function via e.g. eraseFromParent seems like a better option, but doesn't seem to be legal from a FunctionPass. --- llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp | 1 + .../CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp index e9d009baa20af..09412d1b0f1cc 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp @@ -132,6 +132,7 @@ class PreloadKernelArgInfo { NF->setAttributes(AL); F.replaceAllUsesWith(NF); F.setCallingConv(CallingConv::C); + F.clearMetadata(); return NF; } diff --git a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll index a6a0b88dce125..8b75c383ae764 100644 --- a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll +++ b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll @@ -1,7 +1,7 @@ -; RUN: not --crash opt -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -passes='amdgpu-attributor,function(amdgpu-lower-kernel-arguments)' -amdgpu-kernarg-preload-count=16 -S < %s 2>&1 | FileCheck %s +; RUN: opt -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -passes='amdgpu-attributor,function(amdgpu-lower-kernel-arguments)' -amdgpu-kernarg-preload-count=16 -S < %s 2>&1 | FileCheck %s -; CHECK: function declaration may only have a unique !dbg attachment -; CHECK-NEXT: ptr @0 +; CHECK: define amdgpu_kernel void @preload_block_count_x{{.*}} !dbg ![[#]] +; CHECK-NOT: declare void @0{{.*}} !dbg ![[#]] define amdgpu_kernel void @preload_block_count_x(ptr addrspace(1) %out) !dbg !4 !max_work_group_size !7 { %imp_arg_ptr = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr() From f049d30d4625424d6e0300eed3993cac4cebd7d0 Mon Sep 17 00:00:00 2001 From: Scott Linder Date: Mon, 10 Feb 2025 22:47:15 +0000 Subject: [PATCH 2/3] Replace fragile CHECK-NOT with -implicit-check-not --- .../CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll index 8b75c383ae764..5727e2eaefa38 100644 --- a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll +++ b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll @@ -1,7 +1,10 @@ -; RUN: opt -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -passes='amdgpu-attributor,function(amdgpu-lower-kernel-arguments)' -amdgpu-kernarg-preload-count=16 -S < %s 2>&1 | FileCheck %s +; RUN: opt -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -passes='amdgpu-attributor,function(amdgpu-lower-kernel-arguments)' -amdgpu-kernarg-preload-count=16 -S < %s 2>&1 \ +; RUN: | FileCheck -implicit-check-not='declare {{.*}} !dbg' %s + +; The real test is via the -implicit-check-not, which confirms we do not +; leave behind a declaration which references the same DISubprogram metadata. ; CHECK: define amdgpu_kernel void @preload_block_count_x{{.*}} !dbg ![[#]] -; CHECK-NOT: declare void @0{{.*}} !dbg ![[#]] define amdgpu_kernel void @preload_block_count_x(ptr addrspace(1) %out) !dbg !4 !max_work_group_size !7 { %imp_arg_ptr = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr() From 4c241998929ab6a75422940f51f632a64c88e9ea Mon Sep 17 00:00:00 2001 From: Scott Linder Date: Wed, 12 Feb 2025 00:03:25 +0000 Subject: [PATCH 3/3] Use a simpler implicit-check-not and explicitly CHECK for every declare --- .../AMDGPU/preload-implicit-kernargs-debug-info.ll | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll index 5727e2eaefa38..b008f397318e8 100644 --- a/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll +++ b/llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll @@ -1,10 +1,13 @@ ; RUN: opt -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -passes='amdgpu-attributor,function(amdgpu-lower-kernel-arguments)' -amdgpu-kernarg-preload-count=16 -S < %s 2>&1 \ -; RUN: | FileCheck -implicit-check-not='declare {{.*}} !dbg' %s +; RUN: | FileCheck --match-full-lines --implicit-check-not='declare' %s -; The real test is via the -implicit-check-not, which confirms we do not -; leave behind a declaration which references the same DISubprogram metadata. +; Confirms we do not leave behind a declaration which references the same +; DISubprogram metadata. -; CHECK: define amdgpu_kernel void @preload_block_count_x{{.*}} !dbg ![[#]] +; CHECK: define amdgpu_kernel void @preload_block_count_x{{.*}} !dbg ![[#]] !max_work_group_size ![[#]] { +; CHECK: declare void @0{{.*}} #[[#]] +; CHECK: declare noundef align 4 ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr() #[[#]] +; CHECK: declare noundef align 4 ptr addrspace(4) @llvm.amdgcn.kernarg.segment.ptr() #[[#]] define amdgpu_kernel void @preload_block_count_x(ptr addrspace(1) %out) !dbg !4 !max_work_group_size !7 { %imp_arg_ptr = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()