Skip to content

[AMDGPU] Remove dead function metadata after amdgpu-lower-kernel-arguments #126147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

slinder1
Copy link
Contributor

@slinder1 slinder1 commented Feb 6, 2025

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.

Copy link
Contributor Author

slinder1 commented Feb 6, 2025

@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Scott Linder (slinder1)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/126147.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp (+1)
  • (modified) llvm/test/CodeGen/AMDGPU/preload-implicit-kernargs-debug-info.ll (+3-3)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
index e9d009baa20af2..09412d1b0f1cc9 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 fe110cbcafc465..4b47a218f1be45 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 {
   %imp_arg_ptr = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()

Copy link
Member

@kerbowa kerbowa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed after #123547, there are other bugs besides this caused by the leftover declarations.

@slinder1 slinder1 force-pushed the users/slinder1/02-06-_amdgpu_remove_dead_function_metadata_after_amdgpu-lower-kernel-arguments branch from bc50ff1 to 2fe5d5c Compare February 10, 2025 22:53
@@ -1,7 +1,10 @@
; 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 \
; RUN: | FileCheck -implicit-check-not='declare {{.*}} !dbg' %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still a big aggressive for check-not, and I'm not sure it supports regex. Can you simplify to just check-not=declare and explicitly check the few declares that are expected?

Copy link
Contributor Author

@slinder1 slinder1 Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had already double-checked that --implicit-check-not supports regex (just --implicit-check-not='{{.*}}' will fail on the first line)

I went that route to avoid the awkward CHECKs for the irrelevant declares of llvm.amdgcn.implicitarg.ptr and llvm.amdgcn.kernarg.segment.ptr, but I posted a version with --implicit-check-not=declare and the extra CHECKs; let me know what you think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason pushing didn't clear your approval, but I wanted to double check your thoughts on the test change so I re-requested

Base automatically changed from users/slinder1/02-06-_amdgpu_add_test_for_failure_with_function_dbg_info_in_amdgpu-lower-kernel-arguments to main February 13, 2025 20:58
@slinder1 slinder1 requested a review from arsenm February 13, 2025 20:59
@slinder1
Copy link
Contributor Author

I am not certain I understand the github interface, but it seems to be saying you approved the latest patch, so I will land and anything else can be resolved post-commit

…ments

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.
@slinder1 slinder1 force-pushed the users/slinder1/02-06-_amdgpu_remove_dead_function_metadata_after_amdgpu-lower-kernel-arguments branch from 07f4086 to 4c24199 Compare February 17, 2025 18:22
Copy link
Contributor Author

slinder1 commented Feb 17, 2025

Merge activity

  • Feb 17, 1:26 PM EST: A user started a stack merge that includes this pull request via Graphite.
  • Feb 17, 1:27 PM EST: A user merged this pull request with Graphite.

@slinder1 slinder1 merged commit eaa460c into main Feb 17, 2025
5 of 7 checks passed
@slinder1 slinder1 deleted the users/slinder1/02-06-_amdgpu_remove_dead_function_metadata_after_amdgpu-lower-kernel-arguments branch February 17, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants