Skip to content

Commit acd6294

Browse files
authored
[SCEV] Improve code in SCEVLoopGuardRewriter (NFC) (#139257)
Prefer DenseMap::lookup over DenseMap::find.
1 parent c11aba9 commit acd6294

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15867,49 +15867,45 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
1586715867
}
1586815868

1586915869
const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
15870-
auto I = Map.find(Expr);
15871-
if (I == Map.end()) {
15872-
// If we didn't find the extact ZExt expr in the map, check if there's
15873-
// an entry for a smaller ZExt we can use instead.
15874-
Type *Ty = Expr->getType();
15875-
const SCEV *Op = Expr->getOperand(0);
15876-
unsigned Bitwidth = Ty->getScalarSizeInBits() / 2;
15877-
while (Bitwidth % 8 == 0 && Bitwidth >= 8 &&
15878-
Bitwidth > Op->getType()->getScalarSizeInBits()) {
15879-
Type *NarrowTy = IntegerType::get(SE.getContext(), Bitwidth);
15880-
auto *NarrowExt = SE.getZeroExtendExpr(Op, NarrowTy);
15881-
auto I = Map.find(NarrowExt);
15882-
if (I != Map.end())
15883-
return SE.getZeroExtendExpr(I->second, Ty);
15884-
Bitwidth = Bitwidth / 2;
15885-
}
15870+
if (const SCEV *S = Map.lookup(Expr))
15871+
return S;
1588615872

15887-
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitZeroExtendExpr(
15888-
Expr);
15873+
// If we didn't find the extact ZExt expr in the map, check if there's
15874+
// an entry for a smaller ZExt we can use instead.
15875+
Type *Ty = Expr->getType();
15876+
const SCEV *Op = Expr->getOperand(0);
15877+
unsigned Bitwidth = Ty->getScalarSizeInBits() / 2;
15878+
while (Bitwidth % 8 == 0 && Bitwidth >= 8 &&
15879+
Bitwidth > Op->getType()->getScalarSizeInBits()) {
15880+
Type *NarrowTy = IntegerType::get(SE.getContext(), Bitwidth);
15881+
auto *NarrowExt = SE.getZeroExtendExpr(Op, NarrowTy);
15882+
auto I = Map.find(NarrowExt);
15883+
if (I != Map.end())
15884+
return SE.getZeroExtendExpr(I->second, Ty);
15885+
Bitwidth = Bitwidth / 2;
1588915886
}
15890-
return I->second;
15887+
15888+
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitZeroExtendExpr(
15889+
Expr);
1589115890
}
1589215891

1589315892
const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
15894-
auto I = Map.find(Expr);
15895-
if (I == Map.end())
15896-
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSignExtendExpr(
15897-
Expr);
15898-
return I->second;
15893+
if (const SCEV *S = Map.lookup(Expr))
15894+
return S;
15895+
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSignExtendExpr(
15896+
Expr);
1589915897
}
1590015898

1590115899
const SCEV *visitUMinExpr(const SCEVUMinExpr *Expr) {
15902-
auto I = Map.find(Expr);
15903-
if (I == Map.end())
15904-
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitUMinExpr(Expr);
15905-
return I->second;
15900+
if (const SCEV *S = Map.lookup(Expr))
15901+
return S;
15902+
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitUMinExpr(Expr);
1590615903
}
1590715904

1590815905
const SCEV *visitSMinExpr(const SCEVSMinExpr *Expr) {
15909-
auto I = Map.find(Expr);
15910-
if (I == Map.end())
15911-
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSMinExpr(Expr);
15912-
return I->second;
15906+
if (const SCEV *S = Map.lookup(Expr))
15907+
return S;
15908+
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSMinExpr(Expr);
1591315909
}
1591415910

1591515911
const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {

0 commit comments

Comments
 (0)