[PATCH] D141433: AMDGPU: Don't expand printf users if printf is defined

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 10 14:04:52 PST 2023


arsenm created this revision.
arsenm added reviewers: AMDGPU, sameerds, vikramRH.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D141433

Files:
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/test/CodeGen/AMDGPU/printf-defined.ll


Index: llvm/test/CodeGen/AMDGPU/printf-defined.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -489,7 +489,7 @@
     return false;
 
   auto PrintfFunction = M.getFunction("printf");
-  if (!PrintfFunction)
+  if (!PrintfFunction || !PrintfFunction->isDeclaration())
     return false;
 
   for (auto &U : PrintfFunction->uses()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141433.487988.patch
Type: text/x-patch
Size: 1356 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230110/e876b12b/attachment.bin>


More information about the llvm-commits mailing list