[llvm] [AMDGPU] Suppress OpenCL rewriting of printf where it is not linked (PR #215153)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 9 14:48:06 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
Summary:
This triple intentionally does not link this library so this will always
be unresolved. We already suppress this for OpenMP so this should be
fine.
---
Full diff: https://github.com/llvm/llvm-project/pull/215153.diff
2 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp (+5-2)
- (added) llvm/test/CodeGen/AMDGPU/printf-runtime-binding-disabled.ll (+30)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
index 98928e26f8de0..74d2451bd1d9c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -428,9 +428,12 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
}
bool AMDGPUPrintfRuntimeBindingImpl::run(Module &M) {
+ if (M.getModuleFlag("openmp") ||
+ M.getTargetTriple().getEnvironment() == Triple::LLVM)
+ return false;
+
auto *PrintfFunction = M.getFunction("printf");
- if (!PrintfFunction || !PrintfFunction->isDeclaration() ||
- M.getModuleFlag("openmp"))
+ if (!PrintfFunction || !PrintfFunction->isDeclaration())
return false;
// Verify the signature of the printf function and skip if it isn't correct.
diff --git a/llvm/test/CodeGen/AMDGPU/printf-runtime-binding-disabled.ll b/llvm/test/CodeGen/AMDGPU/printf-runtime-binding-disabled.ll
new file mode 100644
index 0000000000000..008b5d077ac0e
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/printf-runtime-binding-disabled.ll
@@ -0,0 +1,30 @@
+; RUN: split-file %s %t
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-printf-runtime-binding -S < %t/openmp.ll | FileCheck %s
+; RUN: opt -mtriple=amdgcn-amd-amdhsa-llvm -passes=amdgpu-printf-runtime-binding -S < %t/llvm-env.ll | FileCheck %s
+
+; CHECK-LABEL: define void @test(
+; CHECK: call i32 (ptr addrspace(4), ...) @printf(ptr addrspace(4) @format.str, i32 %n)
+; CHECK-NOT: __printf_alloc
+
+;--- openmp.ll
+ at format.str = private unnamed_addr addrspace(4) constant [8 x i8] c"arst %d\00", align 1
+
+define void @test(i32 %n) {
+ %call = call i32 (ptr addrspace(4), ...) @printf(ptr addrspace(4) @format.str, i32 %n)
+ ret void
+}
+
+declare i32 @printf(ptr addrspace(4), ...)
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"openmp", i32 51}
+
+;--- llvm-env.ll
+ at format.str = private unnamed_addr addrspace(4) constant [8 x i8] c"arst %d\00", align 1
+
+define void @test(i32 %n) {
+ %call = call i32 (ptr addrspace(4), ...) @printf(ptr addrspace(4) @format.str, i32 %n)
+ ret void
+}
+
+declare i32 @printf(ptr addrspace(4), ...)
``````````
</details>
https://github.com/llvm/llvm-project/pull/215153
More information about the llvm-commits
mailing list