[llvm] 0e7a83f - AMDGPU: Don't expand printf users if printf is defined
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 13 09:32:10 PST 2023
Author: Matt Arsenault
Date: 2023-01-13T12:32:04-05:00
New Revision: 0e7a83f502497602bdba927bf82d14387ef28611
URL: https://github.com/llvm/llvm-project/commit/0e7a83f502497602bdba927bf82d14387ef28611
DIFF: https://github.com/llvm/llvm-project/commit/0e7a83f502497602bdba927bf82d14387ef28611.diff
LOG: AMDGPU: Don't expand printf users if printf is defined
Added:
llvm/test/CodeGen/AMDGPU/printf-defined.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
index a28721cc7262d..7018f0a8c2a58 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -489,7 +489,7 @@ bool AMDGPUPrintfRuntimeBindingImpl::run(Module &M) {
return false;
auto PrintfFunction = M.getFunction("printf");
- if (!PrintfFunction)
+ if (!PrintfFunction || !PrintfFunction->isDeclaration())
return false;
for (auto &U : PrintfFunction->uses()) {
diff --git a/llvm/test/CodeGen/AMDGPU/printf-defined.ll b/llvm/test/CodeGen/AMDGPU/printf-defined.ll
new file mode 100644
index 0000000000000..22740a008f900
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/printf-defined.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple=amdgcn-- -passes=amdgpu-printf-runtime-binding -mcpu=fiji -S < %s | FileCheck --check-prefix=GCN %s
+
+ at format.str = private unnamed_addr addrspace(4) constant [8 x i8] c"arst %d\00", align 1
+
+define i32 @printf(ptr addrspace(4), ...) {
+; GCN-LABEL: @printf(
+; GCN-NEXT: ret i32 0
+;
+ ret i32 0
+}
+
+define void @printf_caller(i32 %n) {
+; GCN-LABEL: @printf_caller(
+; GCN-NEXT: [[CALL:%.*]] = call i32 @printf(ptr addrspace(4) @format.str, i32 [[N:%.*]])
+; GCN-NEXT: ret void
+;
+ %call = call i32 @printf(ptr addrspace(4) @format.str, i32 %n)
+ ret void
+}
More information about the llvm-commits
mailing list