aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp8
-rw-r--r--lib/Analysis/ConstantRange.cpp8
-rw-r--r--lib/Analysis/ScalarEvolution.cpp21
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp26
4 files changed, 42 insertions, 21 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index ce55b4de42..b1ea1969f3 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -459,11 +459,11 @@ static bool IndexOperandsEqual(Value *V1, Value *V2) {
if (Constant *C2 = dyn_cast<Constant>(V2)) {
// Sign extend the constants to long types, if necessary
if (C1->getType()->getPrimitiveSizeInBits() < 64)
- C1 = ConstantExpr::getSignExtend(C1, Type::LongTy);
+ C1 = ConstantExpr::getSExt(C1, Type::LongTy);
else if (C1->getType() == Type::ULongTy)
C1 = ConstantExpr::getBitCast(C1, Type::LongTy);
if (C2->getType()->getPrimitiveSizeInBits() < 64)
- C2 = ConstantExpr::getSignExtend(C2, Type::LongTy);
+ C2 = ConstantExpr::getSExt(C2, Type::LongTy);
else if (C2->getType() == Type::ULongTy)
C2 = ConstantExpr::getBitCast(C2, Type::LongTy);
return C1 == C2;
@@ -555,11 +555,11 @@ BasicAliasAnalysis::CheckGEPInstructions(
if (G1OC->getType() != G2OC->getType()) {
// Sign extend both operands to long.
if (G1OC->getType()->getPrimitiveSizeInBits() < 64)
- G1OC = ConstantExpr::getSignExtend(G1OC, Type::LongTy);
+ G1OC = ConstantExpr::getSExt(G1OC, Type::LongTy);
else if (G1OC->getType() == Type::ULongTy)
G1OC = ConstantExpr::getBitCast(G1OC, Type::LongTy);
if (G2OC->getType()->getPrimitiveSizeInBits() < 64)
- G2OC = ConstantExpr::getSignExtend(G2OC, Type::LongTy);
+ G2OC = ConstantExpr::getSExt(G2OC, Type::LongTy);
else if (G2OC->getType() == Type::ULongTy)
G2OC = ConstantExpr::getBitCast(G2OC, Type::LongTy);
GEP1Ops[FirstConstantOper] = G1OC;
diff --git a/lib/Analysis/ConstantRange.cpp b/lib/Analysis/ConstantRange.cpp
index 2c215866c6..762d5c358a 100644
--- a/lib/Analysis/ConstantRange.cpp
+++ b/lib/Analysis/ConstantRange.cpp
@@ -340,8 +340,8 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
Constant *Lower = getLower();
Constant *Upper = getUpper();
- return ConstantRange(ConstantExpr::getCast(Instruction::ZExt, Lower, Ty),
- ConstantExpr::getCast(Instruction::ZExt, Upper, Ty));
+ return ConstantRange(ConstantExpr::getZExt(Lower, Ty),
+ ConstantExpr::getZExt(Upper, Ty));
}
/// truncate - Return a new range in the specified integer type, which must be
@@ -356,8 +356,8 @@ ConstantRange ConstantRange::truncate(const Type *Ty) const {
return ConstantRange(getType());
return ConstantRange(
- ConstantExpr::getCast(Instruction::Trunc, getLower(), Ty),
- ConstantExpr::getCast(Instruction::Trunc, getUpper(), Ty));
+ ConstantExpr::getTrunc(getLower(), Ty),
+ ConstantExpr::getTrunc(getUpper(), Ty));
}
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 46b8f2629c..7d73d7d398 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -584,7 +584,7 @@ SCEVHandle SCEVTruncateExpr::get(const SCEVHandle &Op, const Type *Ty) {
SCEVHandle SCEVZeroExtendExpr::get(const SCEVHandle &Op, const Type *Ty) {
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
return SCEVUnknown::get(
- ConstantExpr::getZeroExtend(SC->getValue(), Ty));
+ ConstantExpr::getZExt(SC->getValue(), Ty));
// FIXME: If the input value is a chrec scev, and we can prove that the value
// did not overflow the old, smaller, value, we can zero extend all of the
@@ -2000,11 +2000,14 @@ SCEVHandle ScalarEvolutionsImpl::getSCEVAtScope(SCEV *V, const Loop *L) {
} else {
SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L);
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV))
- Operands.push_back(ConstantExpr::getCast(SC->getValue(),
- Op->getType()));
+ Operands.push_back(ConstantExpr::getIntegerCast(SC->getValue(),
+ Op->getType(),
+ false));
else if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
if (Constant *C = dyn_cast<Constant>(SU->getValue()))
- Operands.push_back(ConstantExpr::getCast(C, Op->getType()));
+ Operands.push_back(ConstantExpr::getIntegerCast(C,
+ Op->getType(),
+ false));
else
return V;
} else {
@@ -2122,7 +2125,7 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec) {
// Compute floor(sqrt(B^2-4ac))
ConstantInt *SqrtVal =
- cast<ConstantInt>(ConstantExpr::getCast(SqrtTerm,
+ cast<ConstantInt>(ConstantExpr::getBitCast(SqrtTerm,
SqrtTerm->getType()->getUnsignedVersion()));
uint64_t SqrtValV = SqrtVal->getZExtValue();
uint64_t SqrtValV2 = (uint64_t)sqrt((double)SqrtValV);
@@ -2135,16 +2138,16 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec) {
}
SqrtVal = ConstantInt::get(Type::ULongTy, SqrtValV2);
- SqrtTerm = ConstantExpr::getCast(SqrtVal, SqrtTerm->getType());
+ SqrtTerm = ConstantExpr::getTruncOrBitCast(SqrtVal, SqrtTerm->getType());
Constant *NegB = ConstantExpr::getNeg(B);
Constant *TwoA = ConstantExpr::getMul(A, Two);
// The divisions must be performed as signed divisions.
const Type *SignedTy = NegB->getType()->getSignedVersion();
- NegB = ConstantExpr::getCast(NegB, SignedTy);
- TwoA = ConstantExpr::getCast(TwoA, SignedTy);
- SqrtTerm = ConstantExpr::getCast(SqrtTerm, SignedTy);
+ NegB = ConstantExpr::getBitCast(NegB, SignedTy);
+ TwoA = ConstantExpr::getBitCast(TwoA, SignedTy);
+ SqrtTerm = ConstantExpr::getBitCast(SqrtTerm, SignedTy);
Constant *Solution1 =
ConstantExpr::getSDiv(ConstantExpr::getAdd(NegB, SqrtTerm), TwoA);
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index 9432cc278b..db23a24d60 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -20,9 +20,27 @@ using namespace llvm;
/// InsertCastOfTo - Insert a cast of V to the specified type, doing what
/// we can to share the casts.
Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
+ // Compute the Cast opcode to use
+ Instruction::CastOps opcode = Instruction::BitCast;
+ if (Ty->isIntegral()) {
+ if (V->getType()->getTypeID() == Type::PointerTyID)
+ opcode = Instruction::PtrToInt;
+ else {
+ unsigned SrcBits = V->getType()->getPrimitiveSizeInBits();
+ unsigned DstBits = Ty->getPrimitiveSizeInBits();
+ opcode = (SrcBits > DstBits ? Instruction::Trunc :
+ (SrcBits == DstBits ? Instruction::BitCast :
+ (V->getType()->isSigned() ? Instruction::SExt :
+ Instruction::ZExt)));
+ }
+ } else if (Ty->isFloatingPoint())
+ opcode = Instruction::UIToFP;
+ else if (Ty->getTypeID() == Type::PointerTyID && V->getType()->isIntegral())
+ opcode = Instruction::IntToPtr;
+
// FIXME: keep track of the cast instruction.
if (Constant *C = dyn_cast<Constant>(V))
- return ConstantExpr::getCast(C, Ty);
+ return ConstantExpr::getCast(opcode, C, Ty);
if (Argument *A = dyn_cast<Argument>(V)) {
// Check to see if there is already a cast!
@@ -38,8 +56,8 @@ Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
return CI;
}
}
- return CastInst::createInferredCast(
- V, Ty, V->getName(), A->getParent()->getEntryBlock().begin());
+ return CastInst::create(opcode, V, Ty, V->getName(),
+ A->getParent()->getEntryBlock().begin());
}
Instruction *I = cast<Instruction>(V);
@@ -64,7 +82,7 @@ Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
if (InvokeInst *II = dyn_cast<InvokeInst>(I))
IP = II->getNormalDest()->begin();
while (isa<PHINode>(IP)) ++IP;
- return CastInst::createInferredCast(V, Ty, V->getName(), IP);
+ return CastInst::create(opcode, V, Ty, V->getName(), IP);
}
Value *SCEVExpander::visitMulExpr(SCEVMulExpr *S) {