[llvm] [Transforms] Avoid repeated hash lookups (NFC) (PR #131497)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 15 21:25:54 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/131497
None
>From 9e44a5f78de46e378948da426f755b97cc551a6b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 15 Mar 2025 09:21:08 -0700
Subject: [PATCH] [Transforms] Avoid repeated hash lookups (NFC)
---
llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 1fca1b54065d4..f70686bc57ee4 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -319,8 +319,8 @@ static FunctionSummary *calculatePrevailingSummary(
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
IsPrevailing) {
- if (auto It = CachedPrevailingSummary.find(VI);
- It != CachedPrevailingSummary.end())
+ auto [It, Inserted] = CachedPrevailingSummary.try_emplace(VI);
+ if (!Inserted)
return It->second;
/// At this point, prevailing symbols have been resolved. The following leads
@@ -363,7 +363,6 @@ static FunctionSummary *calculatePrevailingSummary(
/// future this can be revisited.
/// 5. Otherwise, go conservative.
- CachedPrevailingSummary[VI] = nullptr;
FunctionSummary *Local = nullptr;
FunctionSummary *Prevailing = nullptr;
@@ -764,12 +763,12 @@ ArgumentUsesSummary collectArgumentUsesPerBlock(Argument &A, Function &F) {
auto UpdateUseInfo = [&Result](Instruction *I, ArgumentAccessInfo Info) {
auto *BB = I->getParent();
auto &BBInfo = Result.UsesPerBlock[BB];
- bool AlreadyVisitedInst = BBInfo.Insts.contains(I);
- auto &IInfo = BBInfo.Insts[I];
+ auto [It, Inserted] = BBInfo.Insts.try_emplace(I);
+ auto &IInfo = It->second;
// Instructions that have more than one use of the argument are considered
// as clobbers.
- if (AlreadyVisitedInst) {
+ if (!Inserted) {
IInfo = {ArgumentAccessInfo::AccessType::Unknown, {}};
BBInfo.HasUnknownAccess = true;
return false;
More information about the llvm-commits
mailing list