Skip to content

[AMDGPU] Push amdgpu-preload-kern-arg-prolog after livedebugvalues #126148

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

This is effectively a workaround for a bug in livedebugvalues, but seems
to potentially be a general improvement, as BB sections seems like it
could ruin the special 256-byte prelude scheme that
amdgpu-preload-kern-arg-prolog requires anyway. Moving it even later
doesn't seem to have any material impact, and just adds livedebugvalues
to the list of things which no longer have to deal with pseudo
multiple-entry functions.

AMDGPU debug-info isn't supported upstream yet, so the bug being avoided
isn't testable here. I am posting the patch upstream to avoid an
unnecessary diff with AMD's fork.

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

This is effectively a workaround for a bug in livedebugvalues, but seems
to potentially be a general improvement, as BB sections seems like it
could ruin the special 256-byte prelude scheme that
amdgpu-preload-kern-arg-prolog requires anyway. Moving it even later
doesn't seem to have any material impact, and just adds livedebugvalues
to the list of things which no longer have to deal with pseudo
multiple-entry functions.

AMDGPU debug-info isn't supported upstream yet, so the bug being avoided
isn't testable here. I am posting the patch upstream to avoid an
unnecessary diff with AMD's fork.


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

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+6)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index fffd30b26dc1d5..67b155e4e74001 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1147,6 +1147,7 @@ class GCNPassConfig final : public AMDGPUPassConfig {
   void addPostRegAlloc() override;
   void addPreSched2() override;
   void addPreEmitPass() override;
+  void addPostBBSections() override;
 };
 
 } // end anonymous namespace
@@ -1686,6 +1687,11 @@ void GCNPassConfig::addPreEmitPass() {
     addPass(&AMDGPUInsertDelayAluID);
 
   addPass(&BranchRelaxationPassID);
+}
+
+void GCNPassConfig::addPostBBSections() {
+  // We run this later to avoid passes like livedebugvalues and BBSections
+  // having to deal with the apparent multi-entry functions we may generate.
   addPass(createAMDGPUPreloadKernArgPrologLegacyPass());
 }
 

@slinder1 slinder1 force-pushed the users/slinder1/02-06-_amdgpu_push_amdgpu-preload-kern-arg-prolog_after_livedebugvalues branch from bcb8f4a to 87d26ba Compare February 6, 2025 23:57
Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

lgtm, assuming there's a downstream test for whatever bug this is avoiding

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 LGTM but I think previous PR in stack should be obsolete after #123547

@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
@slinder1 slinder1 force-pushed the users/slinder1/02-06-_amdgpu_push_amdgpu-preload-kern-arg-prolog_after_livedebugvalues branch 2 times, most recently from 5862e32 to 890236b Compare February 12, 2025 00:03
Copy link
Contributor Author

I do have an llvm-reduce'd test case for downstream, just waiting on things to flow down first. I can't actually add the test at all without a fix for the duplicated metadata so didn't seem worth posting the review yet

@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
@slinder1 slinder1 force-pushed the users/slinder1/02-06-_amdgpu_push_amdgpu-preload-kern-arg-prolog_after_livedebugvalues branch from 890236b to 075a702 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:28 PM EST: Graphite rebased this pull request as part of a merge.
  • Feb 17, 1:29 PM EST: A user merged this pull request with Graphite.

Base automatically changed from users/slinder1/02-06-_amdgpu_remove_dead_function_metadata_after_amdgpu-lower-kernel-arguments to main February 17, 2025 18:27
This is effectively a workaround for a bug in livedebugvalues, but seems
to potentially be a general improvement, as BB sections seems like it
could ruin the special 256-byte prelude scheme that
amdgpu-preload-kern-arg-prolog requires anyway. Moving it even later
doesn't seem to have any material impact, and just adds livedebugvalues
to the list of things which no longer have to deal with pseudo
multiple-entry functions.

AMDGPU debug-info isn't supported upstream yet, so the bug being avoided
isn't testable here. I am posting the patch upstream to avoid an
unnecessary diff with AMD's fork.
@slinder1 slinder1 force-pushed the users/slinder1/02-06-_amdgpu_push_amdgpu-preload-kern-arg-prolog_after_livedebugvalues branch from 075a702 to 158abad Compare February 17, 2025 18:27
@slinder1 slinder1 merged commit 29ca3b8 into main Feb 17, 2025
5 of 7 checks passed
@slinder1 slinder1 deleted the users/slinder1/02-06-_amdgpu_push_amdgpu-preload-kern-arg-prolog_after_livedebugvalues branch February 17, 2025 18:29
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Feb 19, 2025
Cherry-pick of remaining stack from
llvm#126148 plus a downstream test.

This is a combination of 2 commits.

[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.

[AMDGPU] Push amdgpu-preload-kern-arg-prolog after livedebugvalues

This is effectively a workaround for a bug in livedebugvalues, but seems
to potentially be a general improvement, as BB sections seems like it
could ruin the special 256-byte prelude scheme that
amdgpu-preload-kern-arg-prolog requires anyway. Moving it even later
doesn't seem to have any material impact, and just adds livedebugvalues
to the list of things which no longer have to deal with pseudo
multiple-entry functions.
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