From 8fe66774b06579cedcba6030bbd2b146a4755d9d Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 10 Mar 2025 10:24:12 -0700 Subject: [PATCH 1/2] [Transforms] Avoid repeated hash lookups (NFC) --- llvm/lib/Transforms/IPO/SampleProfileProbe.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp index ec2594b0d9dc1..e40b2cdc37f70 100644 --- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp @@ -148,7 +148,8 @@ void PseudoProbeVerifier::verifyProbeFactors( auto &PrevProbeFactors = FunctionProbeFactors[F->getName()]; for (const auto &I : ProbeFactors) { float CurProbeFactor = I.second; - if (PrevProbeFactors.count(I.first)) { + auto [It, Inserted] = PrevProbeFactors.try_emplace(I.first); + if (!Inserted) { float PrevProbeFactor = PrevProbeFactors[I.first]; if (std::abs(CurProbeFactor - PrevProbeFactor) > DistributionFactorVariance) { @@ -163,7 +164,7 @@ void PseudoProbeVerifier::verifyProbeFactors( } // Update - PrevProbeFactors[I.first] = I.second; + It->second = I.second; } } From 01a61c899cb7ec00db596959382bf81c70a483bf Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 11 Mar 2025 07:39:03 -0700 Subject: [PATCH 2/2] Address a comment. --- llvm/lib/Transforms/IPO/SampleProfileProbe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp index e40b2cdc37f70..a614e2d169534 100644 --- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp @@ -150,7 +150,7 @@ void PseudoProbeVerifier::verifyProbeFactors( float CurProbeFactor = I.second; auto [It, Inserted] = PrevProbeFactors.try_emplace(I.first); if (!Inserted) { - float PrevProbeFactor = PrevProbeFactors[I.first]; + float PrevProbeFactor = It->second; if (std::abs(CurProbeFactor - PrevProbeFactor) > DistributionFactorVariance) { if (!BannerPrinted) {