diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -682,11 +682,12 @@ 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 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/opencl-printf-pipeline.ll @@ -0,0 +1,16 @@ +; RUN: opt -mtriple=amdgcn--amdhsa -passes=amdgpu-printf-runtime-binding -S < %s | FileCheck %s +; RUN: opt -mtriple=amdgcn--amdhsa -O0 -S < %s | FileCheck %s +; RUN: opt -mtriple=amdgcn--amdhsa -O1 -S < %s | FileCheck %s + +@.str = private unnamed_addr addrspace(4) constant [7 x i8] c"hello\0A\00", align 1 + +; Check that the call to printf is removed when AMDGPUPrintfRuntimeBindingPass is executed +; And that this pass is executed in the -O0 and -OX pipelines +; CHECK-LABEL: define void @foo +; CHECK-NOT: call i32{{.*}}@printf +define void @foo() { + %call = call i32 (ptr addrspace(4), ...) @printf(ptr addrspace(4) noundef @.str) + ret void +} + +declare hidden i32 @printf(ptr addrspace(4) noundef, ...) diff --git a/llvm/test/CodeGen/AMDGPU/opt-pipeline.ll b/llvm/test/CodeGen/AMDGPU/opt-pipeline.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/opt-pipeline.ll @@ -0,0 +1,353 @@ +; UNSUPPORTED: expensive_checks +; RUN: opt -O0 -mtriple=amdgcn--amdhsa -disable-verify -debug-pass-manager -S < %s 2>&1 \ +; RUN: | FileCheck --implicit-check-not="Running pass" -check-prefix=GCN-O0 %s +; RUN: opt -O1 -mtriple=amdgcn--amdhsa -disable-verify -debug-pass-manager -S < %s 2>&1 \ +; RUN: | FileCheck --implicit-check-not="Running pass" -check-prefix=GCN-O1 %s +; RUN: opt -O2 -mtriple=amdgcn--amdhsa -disable-verify -debug-pass-manager -S < %s 2>&1 \ +; RUN: | FileCheck --implicit-check-not="Running pass" -check-prefix=GCN-O2 %s +; RUN: opt -O3 -mtriple=amdgcn--amdhsa -disable-verify -debug-pass-manager -S < %s 2>&1 \ +; RUN: | FileCheck --implicit-check-not="Running pass" -check-prefix=GCN-O3 %s + +; REQUIRES: asserts + +;GCN-O0: Running pass: AMDGPUPropagateAttributesEarlyPass +;GCN-O0: Running pass: AMDGPUUseNativeCallsPass +;GCN-O0: Running pass: AMDGPUPrintfRuntimeBindingPass on [module] +;GCN-O0: Running pass: AlwaysInlinerPass on [module] +;GCN-O0: Running pass: CoroConditionalWrapper on [module] +;GCN-O0: Running pass: AnnotationRemarksPass +;GCN-O0: Running pass: PrintModulePass on [module] + +;GCN-O1: Running pass: Annotation2MetadataPass on [module] +;GCN-O1: Running pass: ForceFunctionAttrsPass on [module] +;GCN-O1: Running pass: AMDGPUPropagateAttributesEarlyPass +;GCN-O1: Running pass: AMDGPUUseNativeCallsPass +;GCN-O1: Running pass: AMDGPUSimplifyLibCallsPass +;GCN-O1: Running pass: InferFunctionAttrsPass on [module] +;GCN-O1: Running pass: CoroEarlyPass on [module] +;GCN-O1: Running pass: LowerExpectIntrinsicPass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: SROAPass +;GCN-O1: Running pass: EarlyCSEPass +;GCN-O1: Running pass: OpenMPOptPass on [module] +;GCN-O1: Running pass: AMDGPUPrintfRuntimeBindingPass on [module] +;GCN-O1: Running pass: AMDGPUUnifyMetadataPass on [module] +;GCN-O1: Running pass: AMDGPUPropagateAttributesLatePass on [module] +;GCN-O1: Running pass: IPSCCPPass on [module] +;GCN-O1: Running pass: CalledValuePropagationPass on [module] +;GCN-O1: Running pass: GlobalOptPass on [module] +;GCN-O1: Running pass: PromotePass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: ModuleInlinerWrapperPass on [module] +;GCN-O1: Running pass: RequireAnalysisPass +;GCN-O1: Running pass: InvalidateAnalysisPass +;GCN-O1: Running pass: RequireAnalysisPass +;GCN-O1: Running pass: DevirtSCCRepeatedPass +;GCN-O1: Running pass: InlinerPass +;GCN-O1: Running pass: InlinerPass +;GCN-O1: Running pass: PostOrderFunctionAttrsPass +;GCN-O1: Running pass: InferAddressSpacesPass +;GCN-O1: Running pass: AMDGPULowerKernelAttributesPass +;GCN-O1: Running pass: AMDGPUPromoteAllocaToVectorPass +;GCN-O1: Running pass: SROAPass +;GCN-O1: Running pass: EarlyCSEPass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: LibCallsShrinkWrapPass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: ReassociatePass +;GCN-O1: Running pass: RequireAnalysisPass +;GCN-O1: Running pass: LoopSimplifyPass +;GCN-O1: Running pass: LCSSAPass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: LoopSimplifyPass +;GCN-O1: Running pass: LCSSAPass +;GCN-O1: Running pass: SROAPass +;GCN-O1: Running pass: MemCpyOptPass +;GCN-O1: Running pass: SCCPPass +;GCN-O1: Running pass: BDCEPass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: CoroElidePass +;GCN-O1: Running pass: ADCEPass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: PostOrderFunctionAttrsPass +;GCN-O1: Running pass: RequireAnalysisPass +;GCN-O1: Running pass: CoroSplitPass +;GCN-O1: Running pass: InvalidateAnalysisPass +;GCN-O1: Running pass: DeadArgumentEliminationPass on [module] +;GCN-O1: Running pass: CoroCleanupPass on [module] +;GCN-O1: Running pass: GlobalOptPass on [module] +;GCN-O1: Running pass: GlobalDCEPass on [module] +;GCN-O1: Running pass: EliminateAvailableExternallyPass on [module] +;GCN-O1: Running pass: ReversePostOrderFunctionAttrsPass on [module] +;GCN-O1: Running pass: RecomputeGlobalsAAPass on [module] +;GCN-O1: Running pass: Float2IntPass +;GCN-O1: Running pass: LowerConstantIntrinsicsPass +;GCN-O1: Running pass: LoopSimplifyPass +;GCN-O1: Running pass: LCSSAPass +;GCN-O1: Running pass: LoopDistributePass +;GCN-O1: Running pass: InjectTLIMappings +;GCN-O1: Running pass: LoopVectorizePass +;GCN-O1: Running pass: LoopLoadEliminationPass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: VectorCombinePass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: LoopUnrollPass +;GCN-O1: Running pass: WarnMissedTransformationsPass +;GCN-O1: Running pass: SROAPass +;GCN-O1: Running pass: InstCombinePass +;GCN-O1: Running pass: RequireAnalysisPass +;GCN-O1: Running pass: LoopSimplifyPass +;GCN-O1: Running pass: LCSSAPass +;GCN-O1: Running pass: AlignmentFromAssumptionsPass +;GCN-O1: Running pass: LoopSinkPass +;GCN-O1: Running pass: InstSimplifyPass +;GCN-O1: Running pass: DivRemPairsPass +;GCN-O1: Running pass: TailCallElimPass +;GCN-O1: Running pass: SimplifyCFGPass +;GCN-O1: Running pass: GlobalDCEPass on [module] +;GCN-O1: Running pass: ConstantMergePass on [module] +;GCN-O1: Running pass: CGProfilePass on [module] +;GCN-O1: Running pass: RelLookupTableConverterPass on [module] +;GCN-O1: Running pass: AnnotationRemarksPass +;GCN-O1: Running pass: PrintModulePass on [module] + +;GCN-O2: Running pass: Annotation2MetadataPass on [module] +;GCN-O2: Running pass: ForceFunctionAttrsPass on [module] +;GCN-O2: Running pass: AMDGPUPropagateAttributesEarlyPass +;GCN-O2: Running pass: AMDGPUUseNativeCallsPass +;GCN-O2: Running pass: AMDGPUSimplifyLibCallsPass +;GCN-O2: Running pass: InferFunctionAttrsPass on [module] +;GCN-O2: Running pass: CoroEarlyPass on [module] +;GCN-O2: Running pass: LowerExpectIntrinsicPass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: SROAPass +;GCN-O2: Running pass: EarlyCSEPass +;GCN-O2: Running pass: OpenMPOptPass on [module] +;GCN-O2: Running pass: AMDGPUPrintfRuntimeBindingPass on [module] +;GCN-O2: Running pass: AMDGPUUnifyMetadataPass on [module] +;GCN-O2: Running pass: AMDGPUPropagateAttributesLatePass on [module] +;GCN-O2: Running pass: IPSCCPPass on [module] +;GCN-O2: Running pass: CalledValuePropagationPass on [module] +;GCN-O2: Running pass: GlobalOptPass on [module] +;GCN-O2: Running pass: PromotePass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: ModuleInlinerWrapperPass on [module] +;GCN-O2: Running pass: RequireAnalysisPass +;GCN-O2: Running pass: InvalidateAnalysisPass +;GCN-O2: Running pass: RequireAnalysisPass +;GCN-O2: Running pass: DevirtSCCRepeatedPass +;GCN-O2: Running pass: InlinerPass +;GCN-O2: Running pass: InlinerPass +;GCN-O2: Running pass: PostOrderFunctionAttrsPass +;GCN-O2: Running pass: OpenMPOptCGSCCPass +;GCN-O2: Running pass: AMDGPUPromoteKernelArgumentsPass +;GCN-O2: Running pass: InferAddressSpacesPass +;GCN-O2: Running pass: AMDGPULowerKernelAttributesPass +;GCN-O2: Running pass: AMDGPUPromoteAllocaToVectorPass +;GCN-O2: Running pass: SROAPass +;GCN-O2: Running pass: EarlyCSEPass +;GCN-O2: Running pass: SpeculativeExecutionPass +;GCN-O2: Running pass: JumpThreadingPass +;GCN-O2: Running pass: CorrelatedValuePropagationPass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: ConstraintEliminationPass +;GCN-O2: Running pass: LibCallsShrinkWrapPass +;GCN-O2: Running pass: TailCallElimPass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: ReassociatePass +;GCN-O2: Running pass: RequireAnalysisPass +;GCN-O2: Running pass: LoopSimplifyPass +;GCN-O2: Running pass: LCSSAPass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: LoopSimplifyPass +;GCN-O2: Running pass: LCSSAPass +;GCN-O2: Running pass: SROAPass +;GCN-O2: Running pass: VectorCombinePass +;GCN-O2: Running pass: MergedLoadStoreMotionPass +;GCN-O2: Running pass: GVNPass +;GCN-O2: Running pass: SCCPPass +;GCN-O2: Running pass: BDCEPass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: JumpThreadingPass +;GCN-O2: Running pass: CorrelatedValuePropagationPass +;GCN-O2: Running pass: ADCEPass +;GCN-O2: Running pass: MemCpyOptPass +;GCN-O2: Running pass: DSEPass +;GCN-O2: Running pass: LoopSimplifyPass +;GCN-O2: Running pass: LCSSAPass +;GCN-O2: Running pass: CoroElidePass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: PostOrderFunctionAttrsPass +;GCN-O2: Running pass: RequireAnalysisPass +;GCN-O2: Running pass: CoroSplitPass +;GCN-O2: Running pass: InvalidateAnalysisPass +;GCN-O2: Running pass: DeadArgumentEliminationPass on [module] +;GCN-O2: Running pass: CoroCleanupPass on [module] +;GCN-O2: Running pass: GlobalOptPass on [module] +;GCN-O2: Running pass: GlobalDCEPass on [module] +;GCN-O2: Running pass: EliminateAvailableExternallyPass on [module] +;GCN-O2: Running pass: ReversePostOrderFunctionAttrsPass on [module] +;GCN-O2: Running pass: RecomputeGlobalsAAPass on [module] +;GCN-O2: Running pass: Float2IntPass +;GCN-O2: Running pass: LowerConstantIntrinsicsPass +;GCN-O2: Running pass: LoopSimplifyPass +;GCN-O2: Running pass: LCSSAPass +;GCN-O2: Running pass: LoopDistributePass +;GCN-O2: Running pass: InjectTLIMappings +;GCN-O2: Running pass: LoopVectorizePass +;GCN-O2: Running pass: LoopLoadEliminationPass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: SLPVectorizerPass +;GCN-O2: Running pass: VectorCombinePass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: LoopUnrollPass +;GCN-O2: Running pass: WarnMissedTransformationsPass +;GCN-O2: Running pass: SROAPass +;GCN-O2: Running pass: InstCombinePass +;GCN-O2: Running pass: RequireAnalysisPass +;GCN-O2: Running pass: LoopSimplifyPass +;GCN-O2: Running pass: LCSSAPass +;GCN-O2: Running pass: AlignmentFromAssumptionsPass +;GCN-O2: Running pass: LoopSinkPass +;GCN-O2: Running pass: InstSimplifyPass +;GCN-O2: Running pass: DivRemPairsPass +;GCN-O2: Running pass: TailCallElimPass +;GCN-O2: Running pass: SimplifyCFGPass +;GCN-O2: Running pass: GlobalDCEPass on [module] +;GCN-O2: Running pass: ConstantMergePass on [module] +;GCN-O2: Running pass: CGProfilePass on [module] +;GCN-O2: Running pass: RelLookupTableConverterPass on [module] +;GCN-O2: Running pass: AnnotationRemarksPass +;GCN-O2: Running pass: PrintModulePass on [module] + +;GCN-O3: Running pass: Annotation2MetadataPass on [module] +;GCN-O3: Running pass: ForceFunctionAttrsPass on [module] +;GCN-O3: Running pass: AMDGPUPropagateAttributesEarlyPass +;GCN-O3: Running pass: AMDGPUUseNativeCallsPass +;GCN-O3: Running pass: AMDGPUSimplifyLibCallsPass +;GCN-O3: Running pass: InferFunctionAttrsPass on [module] +;GCN-O3: Running pass: CoroEarlyPass on [module] +;GCN-O3: Running pass: LowerExpectIntrinsicPass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: SROAPass +;GCN-O3: Running pass: EarlyCSEPass +;GCN-O3: Running pass: CallSiteSplittingPass +;GCN-O3: Running pass: OpenMPOptPass on [module] +;GCN-O3: Running pass: AMDGPUPrintfRuntimeBindingPass on [module] +;GCN-O3: Running pass: AMDGPUUnifyMetadataPass on [module] +;GCN-O3: Running pass: AMDGPUPropagateAttributesLatePass on [module] +;GCN-O3: Running pass: IPSCCPPass on [module] +;GCN-O3: Running pass: CalledValuePropagationPass on [module] +;GCN-O3: Running pass: GlobalOptPass on [module] +;GCN-O3: Running pass: PromotePass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: ModuleInlinerWrapperPass on [module] +;GCN-O3: Running pass: RequireAnalysisPass +;GCN-O3: Running pass: InvalidateAnalysisPass +;GCN-O3: Running pass: RequireAnalysisPass +;GCN-O3: Running pass: DevirtSCCRepeatedPass +;GCN-O3: Running pass: InlinerPass +;GCN-O3: Running pass: InlinerPass +;GCN-O3: Running pass: PostOrderFunctionAttrsPass +;GCN-O3: Running pass: ArgumentPromotionPass +;GCN-O3: Running pass: OpenMPOptCGSCCPass +;GCN-O3: Running pass: AMDGPUPromoteKernelArgumentsPass +;GCN-O3: Running pass: InferAddressSpacesPass +;GCN-O3: Running pass: AMDGPULowerKernelAttributesPass +;GCN-O3: Running pass: AMDGPUPromoteAllocaToVectorPass +;GCN-O3: Running pass: SROAPass +;GCN-O3: Running pass: EarlyCSEPass +;GCN-O3: Running pass: SpeculativeExecutionPass +;GCN-O3: Running pass: JumpThreadingPass +;GCN-O3: Running pass: CorrelatedValuePropagationPass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: AggressiveInstCombinePass +;GCN-O3: Running pass: ConstraintEliminationPass +;GCN-O3: Running pass: LibCallsShrinkWrapPass +;GCN-O3: Running pass: TailCallElimPass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: ReassociatePass +;GCN-O3: Running pass: RequireAnalysisPass +;GCN-O3: Running pass: LoopSimplifyPass +;GCN-O3: Running pass: LCSSAPass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: LoopSimplifyPass +;GCN-O3: Running pass: LCSSAPass +;GCN-O3: Running pass: SROAPass +;GCN-O3: Running pass: VectorCombinePass +;GCN-O3: Running pass: MergedLoadStoreMotionPass +;GCN-O3: Running pass: GVNPass +;GCN-O3: Running pass: SCCPPass +;GCN-O3: Running pass: BDCEPass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: JumpThreadingPass +;GCN-O3: Running pass: CorrelatedValuePropagationPass +;GCN-O3: Running pass: ADCEPass +;GCN-O3: Running pass: MemCpyOptPass +;GCN-O3: Running pass: DSEPass +;GCN-O3: Running pass: LoopSimplifyPass +;GCN-O3: Running pass: LCSSAPass +;GCN-O3: Running pass: CoroElidePass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: PostOrderFunctionAttrsPass +;GCN-O3: Running pass: RequireAnalysisPass +;GCN-O3: Running pass: CoroSplitPass +;GCN-O3: Running pass: InvalidateAnalysisPass +;GCN-O3: Running pass: DeadArgumentEliminationPass on [module] +;GCN-O3: Running pass: CoroCleanupPass on [module] +;GCN-O3: Running pass: GlobalOptPass on [module] +;GCN-O3: Running pass: GlobalDCEPass on [module] +;GCN-O3: Running pass: EliminateAvailableExternallyPass on [module] +;GCN-O3: Running pass: ReversePostOrderFunctionAttrsPass on [module] +;GCN-O3: Running pass: RecomputeGlobalsAAPass on [module] +;GCN-O3: Running pass: Float2IntPass +;GCN-O3: Running pass: LowerConstantIntrinsicsPass +;GCN-O3: Running pass: ControlHeightReductionPass +;GCN-O3: Running pass: LoopSimplifyPass +;GCN-O3: Running pass: LCSSAPass +;GCN-O3: Running pass: LoopDistributePass +;GCN-O3: Running pass: InjectTLIMappings +;GCN-O3: Running pass: LoopVectorizePass +;GCN-O3: Running pass: LoopLoadEliminationPass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: SLPVectorizerPass +;GCN-O3: Running pass: VectorCombinePass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: LoopUnrollPass +;GCN-O3: Running pass: WarnMissedTransformationsPass +;GCN-O3: Running pass: SROAPass +;GCN-O3: Running pass: InstCombinePass +;GCN-O3: Running pass: RequireAnalysisPass +;GCN-O3: Running pass: LoopSimplifyPass +;GCN-O3: Running pass: LCSSAPass +;GCN-O3: Running pass: AlignmentFromAssumptionsPass +;GCN-O3: Running pass: LoopSinkPass +;GCN-O3: Running pass: InstSimplifyPass +;GCN-O3: Running pass: DivRemPairsPass +;GCN-O3: Running pass: TailCallElimPass +;GCN-O3: Running pass: SimplifyCFGPass +;GCN-O3: Running pass: GlobalDCEPass on [module] +;GCN-O3: Running pass: ConstantMergePass on [module] +;GCN-O3: Running pass: CGProfilePass on [module] +;GCN-O3: Running pass: RelLookupTableConverterPass on [module] +;GCN-O3: Running pass: AnnotationRemarksPass +;GCN-O3: Running pass: PrintModulePass on [module] + +define void @empty() { + ret void +}