[llvm] [InstrProf] Mark __llvm_profile_runtime_user cold (PR #174174)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 1 22:22:51 PST 2026
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/174174
>From a4fcb7b056c73e3da083bebc4386cdf8e1d5fb7a Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Fri, 2 Jan 2026 03:18:26 +0000
Subject: [PATCH] [InstrProf] Mark __llvm_profile_runtime_user cold
This function is only created to use a global so that it does not get
pruned by the compiler. We could probably get rid of it
(https://reviews.llvm.org/D98325), but there are some complications
around certain platforms. Given that it will never be called, mark it as
cold.
---
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 2 ++
llvm/test/Instrumentation/InstrProfiling/profiling.ll | 2 +-
llvm/utils/profcheck-xfail.txt | 3 ---
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 8c8d16a6e3d25..c4c4446364aa2 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -2072,6 +2072,8 @@ bool InstrLowerer::emitRuntimeHook() {
User->setVisibility(GlobalValue::HiddenVisibility);
if (TT.supportsCOMDAT())
User->setComdat(M.getOrInsertComdat(User->getName()));
+ // Explicitly mark this function as cold since it is never called.
+ User->setEntryCount(0);
IRBuilder<> IRB(BasicBlock::Create(M.getContext(), "", User));
auto *Load = IRB.CreateLoad(Int32Ty, Var);
diff --git a/llvm/test/Instrumentation/InstrProfiling/profiling.ll b/llvm/test/Instrumentation/InstrProfiling/profiling.ll
index 74dd54cef50fb..316aed2c1a0fd 100644
--- a/llvm/test/Instrumentation/InstrProfiling/profiling.ll
+++ b/llvm/test/Instrumentation/InstrProfiling/profiling.ll
@@ -107,7 +107,7 @@ declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
; MACHO: %[[REG:.*]] = load i32, ptr @__llvm_profile_runtime
; MACHO: ret i32 %[[REG]]
; MACHO: }
-; COFF: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} comdat {
+; COFF: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} comdat {{.*}} {
; ELFRT-NOT: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} {
; ELFRT-NOT: %[[REG:.*]] = load i32, ptr @__llvm_profile_runtime
; PS: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() {{.*}} {
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index beffde14d5f8b..070efb0bc57a4 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -535,9 +535,6 @@ Transforms/OpenMP/spmdization_indirect.ll
Transforms/OpenMP/spmdization.ll
Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
Transforms/OpenMP/spmdization_remarks.ll
-Transforms/PGOProfile/comdat.ll
-Transforms/PGOProfile/memop_profile_funclet_wasm.ll
-Transforms/PGOProfile/X86/macho.ll
Transforms/PhaseOrdering/AArch64/constraint-elimination-placement.ll
Transforms/PhaseOrdering/AArch64/globals-aa-required-for-vectorization.ll
Transforms/PhaseOrdering/AArch64/hoist-load-from-vector-loop.ll
More information about the llvm-commits
mailing list