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 {