[llvm] [Transforms] Avoid repeated hash lookups (NFC) (PR #112654)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 20:33:55 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/112654
None
>From 29704a5d4387514d3a8af9c6b4d24a7855cdbef1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 16 Oct 2024 06:54:50 -0700
Subject: [PATCH] [Transforms] Avoid repeated hash lookups (NFC)
---
llvm/lib/Transforms/Utils/LoopPeel.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
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