[llvm] a3b0189 - [Transforms] Avoid repeated hash lookups (NFC) (#130890)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 12 08:48:30 PDT 2025
Author: Kazu Hirata
Date: 2025-03-12T08:48:27-07:00
New Revision: a3b0189f6daa7074a6560609b2ac0c2c1fd509f9
URL: https://github.com/llvm/llvm-project/commit/a3b0189f6daa7074a6560609b2ac0c2c1fd509f9
DIFF: https://github.com/llvm/llvm-project/commit/a3b0189f6daa7074a6560609b2ac0c2c1fd509f9.diff
LOG: [Transforms] Avoid repeated hash lookups (NFC) (#130890)
Added:
Modified:
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 967be109a7ba6..61b86d2aecef0 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -1134,21 +1134,24 @@ LoopInterchangeProfitability::isProfitablePerLoopCacheAnalysis(
// This is the new cost model returned from loop cache analysis.
// A smaller index means the loop should be placed an outer loop, and vice
// versa.
- if (CostMap.contains(InnerLoop) && CostMap.contains(OuterLoop)) {
- unsigned InnerIndex = 0, OuterIndex = 0;
- InnerIndex = CostMap.find(InnerLoop)->second;
- OuterIndex = CostMap.find(OuterLoop)->second;
- LLVM_DEBUG(dbgs() << "InnerIndex = " << InnerIndex
- << ", OuterIndex = " << OuterIndex << "\n");
- if (InnerIndex < OuterIndex)
- return std::optional<bool>(true);
- assert(InnerIndex != OuterIndex && "CostMap should assign unique "
- "numbers to each loop");
- if (CC->getLoopCost(*OuterLoop) == CC->getLoopCost(*InnerLoop))
- return std::nullopt;
- return std::optional<bool>(false);
- }
- return std::nullopt;
+ auto InnerLoopIt = CostMap.find(InnerLoop);
+ if (InnerLoopIt == CostMap.end())
+ return std::nullopt;
+ auto OuterLoopIt = CostMap.find(OuterLoop);
+ if (OuterLoopIt == CostMap.end())
+ return std::nullopt;
+
+ unsigned InnerIndex = InnerLoopIt->second;
+ unsigned OuterIndex = OuterLoopIt->second;
+ LLVM_DEBUG(dbgs() << "InnerIndex = " << InnerIndex
+ << ", OuterIndex = " << OuterIndex << "\n");
+ if (InnerIndex < OuterIndex)
+ return std::optional<bool>(true);
+ assert(InnerIndex != OuterIndex && "CostMap should assign unique "
+ "numbers to each loop");
+ if (CC->getLoopCost(*OuterLoop) == CC->getLoopCost(*InnerLoop))
+ return std::nullopt;
+ return std::optional<bool>(false);
}
std::optional<bool>
More information about the llvm-commits
mailing list