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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 25 23:56:34 PDT 2025


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

None

>From d110a237d0dd9e43f3efc1a68164f30cf04d6512 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 25 Mar 2025 23:52:04 -0700
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Analysis/ScalarEvolution.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 314baa7c7aee1..69561472dc663 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -15443,9 +15443,9 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
       // Bail out, unless we have a non-wrapping, monotonic range.
       if (ExactRegion.isWrappedSet() || ExactRegion.isFullSet())
         return false;
-      auto I = RewriteMap.find(LHSUnknown);
-      const SCEV *RewrittenLHS = I != RewriteMap.end() ? I->second : LHSUnknown;
-      RewriteMap[LHSUnknown] = SE.getUMaxExpr(
+      auto [I, Inserted] = RewriteMap.try_emplace(LHSUnknown);
+      const SCEV *RewrittenLHS = Inserted ? LHSUnknown : I->second;
+      I->second = SE.getUMaxExpr(
           SE.getConstant(ExactRegion.getUnsignedMin()),
           SE.getUMinExpr(RewrittenLHS,
                          SE.getConstant(ExactRegion.getUnsignedMax())));



More information about the llvm-commits mailing list