[llvm-branch-commits] [llvm] [InstrProf] Deduplicate VP values (PR #196649)
Aiden Grossman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu May 14 06:27:23 PDT 2026
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/196649
>From aa1e92c87136d749b274e98beefde43327eb7c36 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Fri, 8 May 2026 21:45:12 +0000
Subject: [PATCH 1/2] fix
Created using spr 1.3.7
---
llvm/lib/ProfileData/InstrProf.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index f669f53589306..1c2e3a5e145e7 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -1049,6 +1049,10 @@ void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
InstrProfSymtab *ValueMap) {
// Remap values.
std::vector<InstrProfValueData> RemappedVD;
+ // Zero values might occur multiple times (e.g., multiple functions that
+ // cannot be remapped). Deduplicate them to enforce the variant that
+ // values are unique, which allows passes to make some simplifying
+ // assumptions.
std::optional<size_t> ZeroIndex = std::nullopt;
RemappedVD.reserve(VData.size());
for (const auto &V : VData) {
>From ffb2cfc8b2189d91c8381b719ce26e32c4c74f29 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 14 May 2026 13:27:12 +0000
Subject: [PATCH 2/2] feedback
Created using spr 1.3.7
---
llvm/lib/ProfileData/InstrProf.cpp | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 5ddfe1a9b69ec..628be437f05a8 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -1370,17 +1370,14 @@ void annotateValueSite(Module &M, Instruction &Inst,
// These are rare and should only come from corrupted profiles, so we
// just skip them. Remove this when they are fixed properly in
// llvm-profdata.
- std::optional<uint64_t> ZeroCount = std::nullopt;
+ uint64_t ZeroCount = 0;
DenseSet<uint64_t> VisitedValues;
for (const auto &VD : VDs) {
if (VD.Value != 0 && VisitedValues.contains(VD.Value))
continue;
VisitedValues.insert(VD.Value);
if (VD.Value == 0) {
- if (ZeroCount.has_value())
- ZeroCount = *ZeroCount + VD.Count;
- else
- ZeroCount = VD.Count;
+ ZeroCount += VD.Count;
} else {
Vals.push_back(MDHelper.createConstant(
ConstantInt::get(Type::getInt64Ty(Ctx), VD.Value)));
@@ -1390,11 +1387,11 @@ void annotateValueSite(Module &M, Instruction &Inst,
if (--MDCount == 0)
break;
}
- if (ZeroCount.has_value()) {
+ if (ZeroCount != 0) {
Vals.push_back(
MDHelper.createConstant(ConstantInt::get(Type::getInt64Ty(Ctx), 0)));
Vals.push_back(MDHelper.createConstant(
- ConstantInt::get(Type::getInt64Ty(Ctx), *ZeroCount)));
+ ConstantInt::get(Type::getInt64Ty(Ctx), ZeroCount)));
}
Inst.setMetadata(LLVMContext::MD_prof, MDNode::get(Ctx, Vals));
}
More information about the llvm-branch-commits
mailing list