Skip to content

Commit f735f65

Browse files
committed
[SCEV] Improve code using DenseMap::lookup (NFC)
1 parent 1113224 commit f735f65

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))
@@ -14521,15 +14519,15 @@ void ScalarEvolution::verify() const {
1452114519

1452214520
for (const auto &KV : ExprValueMap) {
1452314521
for (Value *V : KV.second) {
14524-
auto It = ValueExprMap.find_as(V);
14525-
if (It == ValueExprMap.end()) {
14522+
const SCEV *S = ValueExprMap.lookup(V);
14523+
if (!S) {
1452614524
dbgs() << "Value " << *V
1452714525
<< " is in ExprValueMap but not in ValueExprMap\n";
1452814526
std::abort();
1452914527
}
14530-
if (It->second != KV.first) {
14531-
dbgs() << "Value " << *V << " mapped to " << *It->second
14532-
<< " rather than " << *KV.first << "\n";
14528+
if (S != KV.first) {
14529+
dbgs() << "Value " << *V << " mapped to " << *S << " rather than "
14530+
<< *KV.first << "\n";
1453314531
std::abort();
1453414532
}
1453514533
}
@@ -14648,15 +14646,15 @@ void ScalarEvolution::verify() const {
1464814646
}
1464914647
for (auto [Expr, IDs] : FoldCacheUser) {
1465014648
for (auto &FoldID : IDs) {
14651-
auto I = FoldCache.find(FoldID);
14652-
if (I == FoldCache.end()) {
14649+
const SCEV *S = FoldCache.lookup(FoldID);
14650+
if (!S) {
1465314651
dbgs() << "Missing entry in FoldCache for expression " << *Expr
1465414652
<< "!\n";
1465514653
std::abort();
1465614654
}
14657-
if (I->second != Expr) {
14658-
dbgs() << "Entry in FoldCache doesn't match FoldCacheUser: "
14659-
<< *I->second << " != " << *Expr << "!\n";
14655+
if (S != Expr) {
14656+
dbgs() << "Entry in FoldCache doesn't match FoldCacheUser: " << *S
14657+
<< " != " << *Expr << "!\n";
1466014658
std::abort();
1466114659
}
1466214660
}
@@ -15624,8 +15622,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1562415622
// existing rewrite because we want to chain further rewrites onto the
1562515623
// already rewritten value. Otherwise returns \p S.
1562615624
auto GetMaybeRewritten = [&](const SCEV *S) {
15627-
auto I = RewriteMap.find(S);
15628-
return I != RewriteMap.end() ? I->second : S;
15625+
return RewriteMap.lookup_or(S, S);
1562915626
};
1563015627

1563115628
// Check for the SCEV expression (A /u B) * B while B is a constant, inside
@@ -15928,9 +15925,8 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
1592815925
Bitwidth > Op->getType()->getScalarSizeInBits()) {
1592915926
Type *NarrowTy = IntegerType::get(SE.getContext(), Bitwidth);
1593015927
auto *NarrowExt = SE.getZeroExtendExpr(Op, NarrowTy);
15931-
auto I = Map.find(NarrowExt);
15932-
if (I != Map.end())
15933-
return SE.getZeroExtendExpr(I->second, Ty);
15928+
if (const SCEV *S = Map.lookup(NarrowExt))
15929+
return SE.getZeroExtendExpr(S, Ty);
1593415930
Bitwidth = Bitwidth / 2;
1593515931
}
1593615932

0 commit comments

Comments
 (0)