Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SCEVLoopGuardRewriter>::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<SCEVLoopGuardRewriter>::visitZeroExtendExpr(
Expr);
}

const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
auto I = Map.find(Expr);
if (I == Map.end())
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSignExtendExpr(
Expr);
return I->second;
if (const SCEV *S = Map.lookup(Expr))
return S;
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSignExtendExpr(
Expr);
}

const SCEV *visitUMinExpr(const SCEVUMinExpr *Expr) {
auto I = Map.find(Expr);
if (I == Map.end())
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitUMinExpr(Expr);
return I->second;
if (const SCEV *S = Map.lookup(Expr))
return S;
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitUMinExpr(Expr);
}

const SCEV *visitSMinExpr(const SCEVSMinExpr *Expr) {
auto I = Map.find(Expr);
if (I == Map.end())
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSMinExpr(Expr);
return I->second;
if (const SCEV *S = Map.lookup(Expr))
return S;
return SCEVRewriteVisitor<SCEVLoopGuardRewriter>::visitSMinExpr(Expr);
}

const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
Expand Down