[llvm] [IndVars] Avoid repeated hash lookups (NFC) (PR #107513)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 20:50:24 PDT 2024


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

None

>From 8049476bdf16b6be08aec718fd2492a22b2d7e8c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 5 Sep 2024 20:40:38 -0700
Subject: [PATCH] [IndVars] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index a950a4f57ef486..ff13c0653e9b96 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1103,10 +1103,8 @@ class WidenIV {
 
   void updatePostIncRangeInfo(Value *Def, Instruction *UseI, ConstantRange R) {
     DefUserPair Key(Def, UseI);
-    auto It = PostIncRangeInfos.find(Key);
-    if (It == PostIncRangeInfos.end())
-      PostIncRangeInfos.insert({Key, R});
-    else
+    auto [It, Inserted] = PostIncRangeInfos.try_emplace(Key, R);
+    if (!Inserted)
       It->second = R.intersectWith(It->second);
   }
 



More information about the llvm-commits mailing list