From 789b301a32325884aec6c732e045c9ae87d8652e Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 10 Mar 2025 10:21:51 -0700 Subject: [PATCH] [AMDGPU] Avoid repeated hash lookups (NFC) --- llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp index 8d3e7829e10e1..75eb440d99c03 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp @@ -89,13 +89,12 @@ const RegBankLegalizeRules &getRules(const GCNSubtarget &ST, static SmallDenseMap> CacheForRuleSet; std::lock_guard Lock(GlobalMutex); - if (!CacheForRuleSet.contains(ST.getGeneration())) { - auto Rules = std::make_unique(ST, MRI); - CacheForRuleSet[ST.getGeneration()] = std::move(Rules); - } else { - CacheForRuleSet[ST.getGeneration()]->refreshRefs(ST, MRI); - } - return *CacheForRuleSet[ST.getGeneration()]; + auto [It, Inserted] = CacheForRuleSet.try_emplace(ST.getGeneration()); + if (Inserted) + It->second = std::make_unique(ST, MRI); + else + It->second->refreshRefs(ST, MRI); + return *It->second; } class AMDGPURegBankLegalizeCombiner {