Skip to content

[AMDGPU] Only run AMDGPUPrintfRuntimeBindingPass at non-prelink phase #125162

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

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

shiltian
Copy link
Contributor

The pass is registered in a pipeline that will run at none LTO, LTO prelink, as
well as LTO postlink phase. It uses the current number of metadata operands as
unique id for printf handling. However, if two TUs both have printf, their
unique id will be starting with 1. After they are linked together, the id is no
longer unique anymore. To resolve this issue, the pass should not run at LTO pre
link stage.

The pass is registered in a pipeline that will run at none LTO, LTO prelink, as
well as LTO postlink phase. It uses the _current_ number of metadata operands as
unique id for printf handling. However, if two TUs both have `printf`, their
unique id will be starting with 1. After they are linked together, the id is no
longer unique anymore. To resolve this issue, the pass should not run at LTO pre
link stage.
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Shilei Tian (shiltian)

Changes

The pass is registered in a pipeline that will run at none LTO, LTO prelink, as
well as LTO postlink phase. It uses the current number of metadata operands as
unique id for printf handling. However, if two TUs both have printf, their
unique id will be starting with 1. After they are linked together, the id is no
longer unique anymore. To resolve this issue, the pass should not run at LTO pre
link stage.


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+2-1)
  • (modified) llvm/test/CodeGen/AMDGPU/print-pipeline-passes.ll (+1)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 96062b30fc0127a..3f90e05ce83babb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -791,7 +791,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
   PB.registerPipelineEarlySimplificationEPCallback(
       [](ModulePassManager &PM, OptimizationLevel Level,
          ThinOrFullLTOPhase Phase) {
-        PM.addPass(AMDGPUPrintfRuntimeBindingPass());
+        if (!isLTOPreLink(Phase))
+          PM.addPass(AMDGPUPrintfRuntimeBindingPass());
 
         if (Level == OptimizationLevel::O0)
           return;
diff --git a/llvm/test/CodeGen/AMDGPU/print-pipeline-passes.ll b/llvm/test/CodeGen/AMDGPU/print-pipeline-passes.ll
index c68143f44866f34..b1fc76f457ece26 100644
--- a/llvm/test/CodeGen/AMDGPU/print-pipeline-passes.ll
+++ b/llvm/test/CodeGen/AMDGPU/print-pipeline-passes.ll
@@ -14,6 +14,7 @@
 
 ; PRE-NOT: internalize
 ; PRE-NOT: amdgpu-attributor
+; PRE-NOT: printfToRuntime
 
 define amdgpu_kernel void @kernel() {
 entry:

@shiltian
Copy link
Contributor Author

shiltian commented Feb 3, 2025

bump

Copy link
Contributor

@jmmartinez jmmartinez left a comment

Choose a reason for hiding this comment

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

LGTM

@shiltian shiltian merged commit bde8ce6 into main Feb 10, 2025
10 checks passed
@shiltian shiltian deleted the users/shiltian/no-printf-handling-in-pre-link branch February 10, 2025 13:24
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
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.

3 participants