Skip to content

Commit a3b0189

Browse files
[Transforms] Avoid repeated hash lookups (NFC) (#130890)
1 parent db3fdbc commit a3b0189

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,21 +1134,24 @@ LoopInterchangeProfitability::isProfitablePerLoopCacheAnalysis(
11341134
// This is the new cost model returned from loop cache analysis.
11351135
// A smaller index means the loop should be placed an outer loop, and vice
11361136
// versa.
1137-
if (CostMap.contains(InnerLoop) && CostMap.contains(OuterLoop)) {
1138-
unsigned InnerIndex = 0, OuterIndex = 0;
1139-
InnerIndex = CostMap.find(InnerLoop)->second;
1140-
OuterIndex = CostMap.find(OuterLoop)->second;
1141-
LLVM_DEBUG(dbgs() << "InnerIndex = " << InnerIndex
1142-
<< ", OuterIndex = " << OuterIndex << "\n");
1143-
if (InnerIndex < OuterIndex)
1144-
return std::optional<bool>(true);
1145-
assert(InnerIndex != OuterIndex && "CostMap should assign unique "
1146-
"numbers to each loop");
1147-
if (CC->getLoopCost(*OuterLoop) == CC->getLoopCost(*InnerLoop))
1148-
return std::nullopt;
1149-
return std::optional<bool>(false);
1150-
}
1151-
return std::nullopt;
1137+
auto InnerLoopIt = CostMap.find(InnerLoop);
1138+
if (InnerLoopIt == CostMap.end())
1139+
return std::nullopt;
1140+
auto OuterLoopIt = CostMap.find(OuterLoop);
1141+
if (OuterLoopIt == CostMap.end())
1142+
return std::nullopt;
1143+
1144+
unsigned InnerIndex = InnerLoopIt->second;
1145+
unsigned OuterIndex = OuterLoopIt->second;
1146+
LLVM_DEBUG(dbgs() << "InnerIndex = " << InnerIndex
1147+
<< ", OuterIndex = " << OuterIndex << "\n");
1148+
if (InnerIndex < OuterIndex)
1149+
return std::optional<bool>(true);
1150+
assert(InnerIndex != OuterIndex && "CostMap should assign unique "
1151+
"numbers to each loop");
1152+
if (CC->getLoopCost(*OuterLoop) == CC->getLoopCost(*InnerLoop))
1153+
return std::nullopt;
1154+
return std::optional<bool>(false);
11521155
}
11531156

11541157
std::optional<bool>

0 commit comments

Comments
 (0)