[llvm] 91b2ac6 - [Transforms] Avoid repeated hash lookups (NFC) (#112654)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 07:45:06 PDT 2024


Author: Kazu Hirata
Date: 2024-10-17T07:45:02-07:00
New Revision: 91b2ac640e9b4e8369c7d09c0a914b815ae6daa9

URL: https://github.com/llvm/llvm-project/commit/91b2ac640e9b4e8369c7d09c0a914b815ae6daa9
DIFF: https://github.com/llvm/llvm-project/commit/91b2ac640e9b4e8369c7d09c0a914b815ae6daa9.diff

LOG: [Transforms] Avoid repeated hash lookups (NFC) (#112654)

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/LoopPeel.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index 760f1619e030c3..3cbde39b30b4e4 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -206,13 +206,11 @@ PhiAnalyzer::PhiAnalyzer(const Loop &L, unsigned MaxIterations)
 //   G(%y) = Unknown otherwise (including phi not in header block)
 PhiAnalyzer::PeelCounter PhiAnalyzer::calculate(const Value &V) {
   // If we already know the answer, take it from the map.
-  auto I = IterationsToInvariance.find(&V);
-  if (I != IterationsToInvariance.end())
-    return I->second;
-
-  // Place Unknown to map to avoid infinite recursion. Such
+  // Otherwise, place Unknown to map to avoid infinite recursion. Such
   // cycles can never stop on an invariant.
-  IterationsToInvariance[&V] = Unknown;
+  auto [I, Inserted] = IterationsToInvariance.try_emplace(&V, Unknown);
+  if (!Inserted)
+    return I->second;
 
   if (L.isLoopInvariant(&V))
     // Loop invariant so known at start.


        


More information about the llvm-commits mailing list