diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 972e4e984c6..a3a6ff33332 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -225,8 +225,6 @@ SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty) assert((Op->getType()->isInteger() || isa(Op->getType())) && (Ty->isInteger() || isa(Ty)) && "Cannot zero extend non-integer value!"); - assert(Op->getType()->getPrimitiveSizeInBits() < Ty->getPrimitiveSizeInBits() - && "This is not an extending conversion!"); } SCEVZeroExtendExpr::~SCEVZeroExtendExpr() { @@ -674,7 +672,12 @@ SCEVHandle ScalarEvolution::getTruncateExpr(const SCEVHandle &Op, const Type *Ty return Result; } -SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op, const Type *Ty) { +SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op, + const Type *Ty) { + assert(getTargetData().getTypeSizeInBits(Op->getType()) < + getTargetData().getTypeSizeInBits(Ty) && + "This is not an extending conversion!"); + if (SCEVConstant *SC = dyn_cast(Op)) { const Type *IntTy = Ty; if (isa(IntTy)) IntTy = getTargetData().getIntPtrType(); diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index 6300f1ff113..0e0eb55a058 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -281,17 +281,21 @@ Value *SCEVExpander::visitTruncateExpr(SCEVTruncateExpr *S) { } Value *SCEVExpander::visitZeroExtendExpr(SCEVZeroExtendExpr *S) { + const Type *Ty = S->getType(); + if (isa(Ty)) Ty = TD.getIntPtrType(); Value *V = expand(S->getOperand()); if (isa(V->getType())) V = InsertCastOfTo(Instruction::PtrToInt, V, TD.getIntPtrType()); - return CastInst::CreateZExtOrBitCast(V, S->getType(), "tmp.", InsertPt); + return CastInst::CreateZExtOrBitCast(V, Ty, "tmp.", InsertPt); } Value *SCEVExpander::visitSignExtendExpr(SCEVSignExtendExpr *S) { + const Type *Ty = S->getType(); + if (isa(Ty)) Ty = TD.getIntPtrType(); Value *V = expand(S->getOperand()); if (isa(V->getType())) V = InsertCastOfTo(Instruction::PtrToInt, V, TD.getIntPtrType()); - return CastInst::CreateSExtOrBitCast(V, S->getType(), "tmp.", InsertPt); + return CastInst::CreateSExtOrBitCast(V, Ty, "tmp.", InsertPt); } Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {