[llvm] [Coroutines] Avoid repeated hash lookps (NFC) (PR #110076)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 20:21:25 PDT 2024


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

None

>From 3e94aef6671c0be03305e1c21eb9cd234e335f6d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 25 Sep 2024 06:37:58 -0700
Subject: [PATCH] [Coroutines] Avoid repeated hash lookps (NFC)

---
 llvm/lib/Transforms/Coroutines/SpillUtils.cpp | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Transforms/Coroutines/SpillUtils.cpp b/llvm/lib/Transforms/Coroutines/SpillUtils.cpp
index f213ac1c8d7d57..96b5c8440e5f9a 100644
--- a/llvm/lib/Transforms/Coroutines/SpillUtils.cpp
+++ b/llvm/lib/Transforms/Coroutines/SpillUtils.cpp
@@ -397,13 +397,11 @@ struct AllocaUseVisitor : PtrUseVisitor<AllocaUseVisitor> {
     if (!IsOffsetKnown) {
       AliasOffetMap[&I].reset();
     } else {
-      auto Itr = AliasOffetMap.find(&I);
-      if (Itr == AliasOffetMap.end()) {
-        AliasOffetMap[&I] = Offset;
-      } else if (Itr->second && *Itr->second != Offset) {
+      auto [Itr, Inserted] = AliasOffetMap.try_emplace(&I, Offset);
+      if (!Inserted && Itr->second && *Itr->second != Offset) {
         // If we have seen two different possible values for this alias, we set
         // it to empty.
-        AliasOffetMap[&I].reset();
+        Itr->second.reset();
       }
     }
   }



More information about the llvm-commits mailing list