diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2233,6 +2233,7 @@ II->setDebugLoc(CI->getDebugLoc()); II->setCallingConv(CI->getCallingConv()); II->setAttributes(CI->getAttributes()); + II->setMetadata(LLVMContext::MD_prof, CI->getMetadata(LLVMContext::MD_prof)); if (DTU) DTU->applyUpdates({{DominatorTree::Insert, BB, UnwindEdge}}); diff --git a/llvm/test/Transforms/Inline/profile_meta_invoke.ll b/llvm/test/Transforms/Inline/profile_meta_invoke.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/Inline/profile_meta_invoke.ll @@ -0,0 +1,30 @@ +; Make sure that profile metadata is preserved when cloning a call. +; RUN: opt < %s -S -inline | FileCheck %s +; RUN: opt < %s -S -passes='cgscc(inline)' | FileCheck %s + +declare i32 @__gxx_personality_v0(...) + +define void @callee(void ()* %func) { + call void %func(), !prof !0 + ret void +} + +define void @caller(void ()* %func) personality i32 (...)* @__gxx_personality_v0 { + invoke void @callee(void ()* %func) + to label %ret unwind label %lpad + +ret: + ret void + +lpad: + %exn = landingpad {i8*, i32} + cleanup + unreachable +} + +!0 = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398} + +; CHECK-LABEL: @caller( +; CHECK: invoke void %func() +; CHECK-NEXT: {{.*}} !prof ![[PROF:[0-9]+]] +; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398}