[llvm] [LTO] Use .at instead of .lookup to avoid copies. (PR #117888)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 06:25:26 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Krzysztof Pszeniczny (amharc)

<details>
<summary>Changes</summary>

`DenseMap::lookup` returns by value (because it default-creates the returned value if the key isn't present in the map), which means that we do a lot of copying here. Since we assert that something is present in the returned value two lines below this call, it's safe to use `.at` here instead.

Copying and then destroying dense maps here is responsible for 60% of the time spent in LTO indexing in a large internal build.

---
Full diff: https://github.com/llvm/llvm-project/pull/117888.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/IPO/FunctionImport.cpp (+1-2) 


``````````diff
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index fee27f72f208b0..9cca3cdc761451 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1540,8 +1540,7 @@ void llvm::gatherImportedSummariesForModule(
     auto &SummariesForIndex =
         LookupOrCreate(ModuleToSummariesForIndex, FromModule);
 
-    const auto &DefinedGVSummaries =
-        ModuleToDefinedGVSummaries.lookup(FromModule);
+    const auto &DefinedGVSummaries = ModuleToDefinedGVSummaries.at(FromModule);
     const auto &DS = DefinedGVSummaries.find(GUID);
     assert(DS != DefinedGVSummaries.end() &&
            "Expected a defined summary for imported global value");

``````````

</details>


https://github.com/llvm/llvm-project/pull/117888


More information about the llvm-commits mailing list