[llvm] [InstCombine] Avoid repeated hash lookups (NFC) (PR #123559)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 19 23:54:35 PST 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/123559

None

>From d1cba23d2ec4b8ea65b15052b1c9f3553f62b992 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 19 Jan 2025 12:07:23 -0800
Subject: [PATCH] [InstCombine] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 842881156dc67f..a2730396a0ea26 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -4179,13 +4179,14 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
     DenseMap<Value *, unsigned> Val2Idx;
     std::vector<Value *> NewLiveGc;
     for (Value *V : Bundle->Inputs) {
-      if (Val2Idx.count(V))
+      auto [It, Inserted] = Val2Idx.try_emplace(V);
+      if (!Inserted)
         continue;
       if (LiveGcValues.count(V)) {
-        Val2Idx[V] = NewLiveGc.size();
+        It->second = NewLiveGc.size();
         NewLiveGc.push_back(V);
       } else
-        Val2Idx[V] = NumOfGCLives;
+        It->second = NumOfGCLives;
     }
     // Update all gc.relocates
     for (const GCRelocateInst *Reloc : GCSP.getGCRelocates()) {



More information about the llvm-commits mailing list