[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #123286)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 16 21:31:41 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/123286
None
>From c52901651d50573b75760e3c1551b3463a3da8c1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 16 Jan 2025 09:53:58 -0800
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)
---
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 4aa922635c374e..7a7a9594f47603 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1409,11 +1409,10 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::applyIterativeInference() {
auto Node = getNode(&BB);
if (!Node.isValid())
continue;
- if (BlockIndex.count(&BB)) {
- Freqs[Node.Index].Scaled = Freq[BlockIndex[&BB]];
- } else {
+ if (auto It = BlockIndex.find(&BB); It != BlockIndex.end())
+ Freqs[Node.Index].Scaled = Freq[It->second];
+ else
Freqs[Node.Index].Scaled = Scaled64::getZero();
- }
}
}
@@ -1764,8 +1763,8 @@ void BlockFrequencyInfoImpl<BT>::verifyMatch(
for (auto &Entry : ValidNodes) {
const BlockT *BB = Entry.first;
BlockNode Node = Entry.second;
- if (OtherValidNodes.count(BB)) {
- BlockNode OtherNode = OtherValidNodes[BB];
+ if (auto It = OtherValidNodes.find(BB); It != OtherValidNodes.end()) {
+ BlockNode OtherNode = It->second;
const auto &Freq = Freqs[Node.Index];
const auto &OtherFreq = Other.Freqs[OtherNode.Index];
if (Freq.Integer != OtherFreq.Integer) {
More information about the llvm-commits
mailing list