[llvm] [AMDGPU] Only run `AMDGPUPrintfRuntimeBindingPass` at non-prelink phase (PR #125162)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 30 20:23:55 PST 2025
https://github.com/shiltian created https://github.com/llvm/llvm-project/pull/125162
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.
>From 8d3736d87bcf7e7e5935c6f1c72c84ca4f125668 Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Thu, 30 Jan 2025 23:14:57 -0500
Subject: [PATCH] [AMDGPU] Only run `AMDGPUPrintfRuntimeBindingPass` at
non-prelink phase
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.
---
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 3 ++-
llvm/test/CodeGen/AMDGPU/print-pipeline-passes.ll | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
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:
More information about the llvm-commits
mailing list