[llvm] 215cfa0 - [AMDGPU][printf] Run AMDGPUPrintfRuntimeBindingPass in -O0
Juan Manuel MARTINEZ CAAMAÑO via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 27 00:44:08 PDT 2023
Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2023-03-27T09:43:36+02:00
New Revision: 215cfa01f2ba6f11d0ca0a2da87038aa81244b73
URL: https://github.com/llvm/llvm-project/commit/215cfa01f2ba6f11d0ca0a2da87038aa81244b73
DIFF: https://github.com/llvm/llvm-project/commit/215cfa01f2ba6f11d0ca0a2da87038aa81244b73.diff
LOG: [AMDGPU][printf] Run AMDGPUPrintfRuntimeBindingPass in -O0
AMDGPUPrintfRuntimeBindingPass is not run in the IR optimization
pipeline with -O0.
This means that with OpenCL the printf definition coming from
device_libs gets linked with the user's code, which blocks
AMDGPUPrintfRuntimeBindingPass from working after the linkage is done.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D146720
Added:
llvm/test/CodeGen/AMDGPU/opencl-printf-pipeline.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index ecb31df175a96..7255b14d5ce66 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -687,11 +687,12 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
PB.registerPipelineEarlySimplificationEPCallback(
[this](ModulePassManager &PM, OptimizationLevel Level) {
+ PM.addPass(AMDGPUPrintfRuntimeBindingPass());
+
if (Level == OptimizationLevel::O0)
return;
PM.addPass(AMDGPUUnifyMetadataPass());
- PM.addPass(AMDGPUPrintfRuntimeBindingPass());
if (InternalizeSymbols) {
PM.addPass(InternalizePass(mustPreserveGV));
diff --git a/llvm/test/CodeGen/AMDGPU/opencl-printf-pipeline.ll b/llvm/test/CodeGen/AMDGPU/opencl-printf-pipeline.ll
new file mode 100644
index 0000000000000..b54976cd686c7
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/opencl-printf-pipeline.ll
@@ -0,0 +1,30 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -mtriple=amdgcn--amdhsa -passes=amdgpu-printf-runtime-binding -S < %s | FileCheck %s
+; RUN: opt -mtriple=amdgcn--amdhsa -O0 -S < %s | FileCheck %s
+
+; Check that the call to printf is removed when AMDGPUPrintfRuntimeBindingPass is executed
+; And that this pass is executed in the -O0 and -OX pipelines
+
+ at .str = private unnamed_addr addrspace(4) constant [7 x i8] c"hello\0A\00", align 1
+
+define void @foo() {
+; CHECK-LABEL: define void @foo() {
+; CHECK-NEXT: [[PRINTF_ALLOC_FN:%.*]] = call ptr addrspace(1) @__printf_alloc(i32 4)
+; CHECK-NEXT: br label [[DOTSPLIT:%.*]]
+; CHECK: .split:
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ne ptr addrspace(1) [[PRINTF_ALLOC_FN]], null
+; CHECK-NEXT: br i1 [[TMP1]], label [[TMP2:%.*]], label [[TMP3:%.*]]
+; CHECK: 2:
+; CHECK-NEXT: [[PRINTBUFFID:%.*]] = getelementptr i8, ptr addrspace(1) [[PRINTF_ALLOC_FN]], i32 0
+; CHECK-NEXT: [[PRINTBUFFIDCAST:%.*]] = bitcast ptr addrspace(1) [[PRINTBUFFID]] to ptr addrspace(1)
+; CHECK-NEXT: store i32 1, ptr addrspace(1) [[PRINTBUFFIDCAST]], align 4
+; CHECK-NEXT: [[PRINTBUFFGEP:%.*]] = getelementptr i8, ptr addrspace(1) [[PRINTF_ALLOC_FN]], i32 4
+; CHECK-NEXT: br label [[TMP3]]
+; CHECK: 3:
+; CHECK-NEXT: ret void
+;
+ %call = call i32 @printf(ptr addrspace(4) @.str)
+ ret void
+}
+
+declare hidden i32 @printf(ptr addrspace(4), ...)
More information about the llvm-commits
mailing list