diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-12 23:36:14 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-12 23:36:14 +0000 |
commit | bb65ebf9a115340e9359dfb955be89164d16d432 (patch) | |
tree | 1adcf098755395a2276c2267ca57103daa89bee6 /llvm/lib/Analysis/ScalarEvolutionExpander.cpp | |
parent | eda561762fe17407f602ff937663ca3eb3b48316 (diff) | |
download | bcm5719-llvm-bb65ebf9a115340e9359dfb955be89164d16d432.tar.gz bcm5719-llvm-bb65ebf9a115340e9359dfb955be89164d16d432.zip |
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.
llvm-svn: 32514
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 9432cc278b9..db23a24d606 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/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) { |