diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 3f9614254ae7a..69714a112310e 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -15867,49 +15867,45 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const { } const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) { - auto I = Map.find(Expr); - if (I == Map.end()) { - // If we didn't find the extact ZExt expr in the map, check if there's - // an entry for a smaller ZExt we can use instead. - Type *Ty = Expr->getType(); - const SCEV *Op = Expr->getOperand(0); - unsigned Bitwidth = Ty->getScalarSizeInBits() / 2; - while (Bitwidth % 8 == 0 && Bitwidth >= 8 && - Bitwidth > Op->getType()->getScalarSizeInBits()) { - Type *NarrowTy = IntegerType::get(SE.getContext(), Bitwidth); - auto *NarrowExt = SE.getZeroExtendExpr(Op, NarrowTy); - auto I = Map.find(NarrowExt); - if (I != Map.end()) - return SE.getZeroExtendExpr(I->second, Ty); - Bitwidth = Bitwidth / 2; - } + if (const SCEV *S = Map.lookup(Expr)) + return S; - return SCEVRewriteVisitor::visitZeroExtendExpr( - Expr); + // If we didn't find the extact ZExt expr in the map, check if there's + // an entry for a smaller ZExt we can use instead. + Type *Ty = Expr->getType(); + const SCEV *Op = Expr->getOperand(0); + unsigned Bitwidth = Ty->getScalarSizeInBits() / 2; + while (Bitwidth % 8 == 0 && Bitwidth >= 8 && + Bitwidth > Op->getType()->getScalarSizeInBits()) { + Type *NarrowTy = IntegerType::get(SE.getContext(), Bitwidth); + auto *NarrowExt = SE.getZeroExtendExpr(Op, NarrowTy); + auto I = Map.find(NarrowExt); + if (I != Map.end()) + return SE.getZeroExtendExpr(I->second, Ty); + Bitwidth = Bitwidth / 2; } - return I->second; + + return SCEVRewriteVisitor::visitZeroExtendExpr( + Expr); } const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) { - auto I = Map.find(Expr); - if (I == Map.end()) - return SCEVRewriteVisitor::visitSignExtendExpr( - Expr); - return I->second; + if (const SCEV *S = Map.lookup(Expr)) + return S; + return SCEVRewriteVisitor::visitSignExtendExpr( + Expr); } const SCEV *visitUMinExpr(const SCEVUMinExpr *Expr) { - auto I = Map.find(Expr); - if (I == Map.end()) - return SCEVRewriteVisitor::visitUMinExpr(Expr); - return I->second; + if (const SCEV *S = Map.lookup(Expr)) + return S; + return SCEVRewriteVisitor::visitUMinExpr(Expr); } const SCEV *visitSMinExpr(const SCEVSMinExpr *Expr) { - auto I = Map.find(Expr); - if (I == Map.end()) - return SCEVRewriteVisitor::visitSMinExpr(Expr); - return I->second; + if (const SCEV *S = Map.lookup(Expr)) + return S; + return SCEVRewriteVisitor::visitSMinExpr(Expr); } const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {