Skip to content

Commit d440809

Browse files
authored
[SCEV] Improve code using DenseMap::lookup (NFC) (#147507)
1 parent 4b22123 commit d440809

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,9 +1559,8 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
15591559
Ty = getEffectiveSCEVType(Ty);
15601560

15611561
FoldID ID(scZeroExtend, Op, Ty);
1562-
auto Iter = FoldCache.find(ID);
1563-
if (Iter != FoldCache.end())
1564-
return Iter->second;
1562+
if (const SCEV *S = FoldCache.lookup(ID))
1563+
return S;
15651564

15661565
const SCEV *S = getZeroExtendExprImpl(Op, Ty, Depth);
15671566
if (!isa<SCEVZeroExtendExpr>(S))
@@ -1894,9 +1893,8 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
18941893
Ty = getEffectiveSCEVType(Ty);
18951894

18961895
FoldID ID(scSignExtend, Op, Ty);
1897-
auto Iter = FoldCache.find(ID);
1898-
if (Iter != FoldCache.end())
1899-
return Iter->second;
1896+
if (const SCEV *S = FoldCache.lookup(ID))
1897+
return S;
19001898

19011899
const SCEV *S = getSignExtendExprImpl(Op, Ty, Depth);
19021900
if (!isa<SCEVSignExtendExpr>(S))
@@ -14498,15 +14496,15 @@ void ScalarEvolution::verify() const {
1449814496

1449914497
for (const auto &KV : ExprValueMap) {
1450014498
for (Value *V : KV.second) {
14501-
auto It = ValueExprMap.find_as(V);
14502-
if (It == ValueExprMap.end()) {
14499+
const SCEV *S = ValueExprMap.lookup(V);
14500+
if (!S) {
1450314501
dbgs() << "Value " << *V
1450414502
<< " is in ExprValueMap but not in ValueExprMap\n";
1450514503
std::abort();
1450614504
}
14507-
if (It->second != KV.first) {
14508-
dbgs() << "Value " << *V << " mapped to " << *It->second
14509-
<< " rather than " << *KV.first << "\n";
14505+
if (S != KV.first) {
14506+
dbgs() << "Value " << *V << " mapped to " << *S << " rather than "
14507+
<< *KV.first << "\n";
1451014508
std::abort();
1451114509
}
1451214510
}
@@ -14625,15 +14623,15 @@ void ScalarEvolution::verify() const {
1462514623
}
1462614624
for (auto [Expr, IDs] : FoldCacheUser) {
1462714625
for (auto &FoldID : IDs) {
14628-
auto I = FoldCache.find(FoldID);
14629-
if (I == FoldCache.end()) {
14626+
const SCEV *S = FoldCache.lookup(FoldID);
14627+
if (!S) {
1463014628
dbgs() << "Missing entry in FoldCache for expression " << *Expr
1463114629
<< "!\n";
1463214630
std::abort();
1463314631
}
14634-
if (I->second != Expr) {
14635-
dbgs() << "Entry in FoldCache doesn't match FoldCacheUser: "
14636-
<< *I->second << " != " << *Expr << "!\n";
14632+
if (S != Expr) {
14633+
dbgs() << "Entry in FoldCache doesn't match FoldCacheUser: " << *S
14634+
<< " != " << *Expr << "!\n";
1463714635
std::abort();
1463814636
}
1463914637
}
@@ -15601,8 +15599,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1560115599
// existing rewrite because we want to chain further rewrites onto the
1560215600
// already rewritten value. Otherwise returns \p S.
1560315601
auto GetMaybeRewritten = [&](const SCEV *S) {
15604-
auto I = RewriteMap.find(S);
15605-
return I != RewriteMap.end() ? I->second : S;
15602+
return RewriteMap.lookup_or(S, S);
1560615603
};
1560715604

1560815605
// Check for the SCEV expression (A /u B) * B while B is a constant, inside
@@ -15905,9 +15902,8 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
1590515902
Bitwidth > Op->getType()->getScalarSizeInBits()) {
1590615903
Type *NarrowTy = IntegerType::get(SE.getContext(), Bitwidth);
1590715904
auto *NarrowExt = SE.getZeroExtendExpr(Op, NarrowTy);
15908-
auto I = Map.find(NarrowExt);
15909-
if (I != Map.end())
15910-
return SE.getZeroExtendExpr(I->second, Ty);
15905+
if (const SCEV *S = Map.lookup(NarrowExt))
15906+
return SE.getZeroExtendExpr(S, Ty);
1591115907
Bitwidth = Bitwidth / 2;
1591215908
}
1591315909

0 commit comments

Comments
 (0)