aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-12 23:36:14 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-12 23:36:14 +0000
commitd977d8651a5cd26a3e1088267f31cade405f2adf (patch)
tree56a269fe411951fa288d6a08c32f3d74b8bf8794 /lib/Analysis/ScalarEvolutionExpander.cpp
parentebc0922eeb5b728d33a68d4bea8128413f62e369 (diff)
Replace inferred getCast(V,Ty) calls with more strict variants.
Rename getZeroExtend and getSignExtend to getZExt and getSExt to match the the casting mnemonics in the rest of LLVM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32514 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp26
1 files changed, 22 insertions, 4 deletions
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) {