[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #125813)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 23:18:21 PST 2025


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

None

>From 8016bfa936633e78628a604be0f7c5f1e8e6c741 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 4 Feb 2025 09:50:46 -0800
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)

---
 llvm/include/llvm/Analysis/VectorUtils.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/llvm/include/llvm/Analysis/VectorUtils.h b/llvm/include/llvm/Analysis/VectorUtils.h
index 5d41d1cd14ef45..f21594c557e0ec 100644
--- a/llvm/include/llvm/Analysis/VectorUtils.h
+++ b/llvm/include/llvm/Analysis/VectorUtils.h
@@ -748,12 +748,11 @@ class InterleavedAccessInfo {
   /// \returns the newly created interleave group.
   InterleaveGroup<Instruction> *
   createInterleaveGroup(Instruction *Instr, int Stride, Align Alignment) {
-    assert(!InterleaveGroupMap.count(Instr) &&
-           "Already in an interleaved access group");
-    InterleaveGroupMap[Instr] =
-        new InterleaveGroup<Instruction>(Instr, Stride, Alignment);
-    InterleaveGroups.insert(InterleaveGroupMap[Instr]);
-    return InterleaveGroupMap[Instr];
+    auto [It, Inserted] = InterleaveGroupMap.try_emplace(Instr);
+    assert(Inserted && "Already in an interleaved access group");
+    It->second = new InterleaveGroup<Instruction>(Instr, Stride, Alignment);
+    InterleaveGroups.insert(It->second);
+    return It->second;
   }
 
   /// Release the group and remove all the relationships.



More information about the llvm-commits mailing list