From 1fd503f0382c8e2087eff5d669a08f74a54038ab Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 8 Feb 2025 14:36:20 -0800 Subject: [PATCH 1/2] [Analysis] Avoid repeated hash lookups (NFC) --- llvm/lib/Analysis/DependenceGraphBuilder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Analysis/DependenceGraphBuilder.cpp b/llvm/lib/Analysis/DependenceGraphBuilder.cpp index 7ee2adf49ebb4..82e9dcfbab23f 100644 --- a/llvm/lib/Analysis/DependenceGraphBuilder.cpp +++ b/llvm/lib/Analysis/DependenceGraphBuilder.cpp @@ -241,8 +241,8 @@ template void AbstractDependenceGraphBuilder::createDefUseEdges() { if (!UI) continue; NodeType *DstNode = nullptr; - if (IMap.find(UI) != IMap.end()) - DstNode = IMap.find(UI)->second; + if (auto It = IMap.find(UI); It != IMap.end()) + DstNode = It->second; // In the case of loops, the scope of the subgraph is all the // basic blocks (and instructions within them) belonging to the loop. We From c3da5bbcecff01541ef4f6f027b3b12a59cd8972 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 9 Feb 2025 09:06:01 -0800 Subject: [PATCH 2/2] Address a comment. --- llvm/lib/Analysis/DependenceGraphBuilder.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/llvm/lib/Analysis/DependenceGraphBuilder.cpp b/llvm/lib/Analysis/DependenceGraphBuilder.cpp index 82e9dcfbab23f..c076e52ce6e14 100644 --- a/llvm/lib/Analysis/DependenceGraphBuilder.cpp +++ b/llvm/lib/Analysis/DependenceGraphBuilder.cpp @@ -240,9 +240,7 @@ template void AbstractDependenceGraphBuilder::createDefUseEdges() { Instruction *UI = dyn_cast(U); if (!UI) continue; - NodeType *DstNode = nullptr; - if (auto It = IMap.find(UI); It != IMap.end()) - DstNode = It->second; + NodeType *DstNode = IMap.lookup(UI); // In the case of loops, the scope of the subgraph is all the // basic blocks (and instructions within them) belonging to the loop. We