summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-13 08:06:42 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-13 08:06:42 +0000
commitdf1f19a8efde59a35b201242c9153d7409a390e5 (patch)
tree5472ab4df12f41ecddc6245b36112a982d9664cf /llvm/lib
parenta730cf80d79b92fd3bcd2ef2feda8c87860211a0 (diff)
downloadbcm5719-llvm-df1f19a8efde59a35b201242c9153d7409a390e5.tar.gz
bcm5719-llvm-df1f19a8efde59a35b201242c9153d7409a390e5.zip
Change the interface to SCEVExpander::InsertCastOfTo to take a cast opcode
so the decision of which opcode to use is pushed upward to the caller. Adjust the callers to pass the expected opcode. llvm-svn: 32535
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/ScalarEvolutionExpander.cpp21
-rw-r--r--llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp33
2 files changed, 23 insertions, 31 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
index db23a24d606..5e395db5e23 100644
--- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -19,25 +19,8 @@ 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;
-
+Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
+ const Type *Ty) {
// FIXME: keep track of the cast instruction.
if (Constant *C = dyn_cast<Constant>(V))
return ConstantExpr::getCast(opcode, C, Ty);
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index c132aaef927..9426aa1a69d 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -177,7 +177,7 @@ namespace {
/// getCastedVersionOf - Return the specified value casted to uintptr_t.
///
- Value *getCastedVersionOf(Value *V);
+ Value *getCastedVersionOf(Instruction::CastOps opcode, Value *V);
private:
void runOnLoop(Loop *L);
bool AddUsersIfInteresting(Instruction *I, Loop *L,
@@ -203,19 +203,16 @@ FunctionPass *llvm::createLoopStrengthReducePass(const TargetLowering *TLI) {
/// getCastedVersionOf - Return the specified value casted to uintptr_t. This
/// assumes that the Value* V is of integer or pointer type only.
///
-Value *LoopStrengthReduce::getCastedVersionOf(Value *V) {
+Value *LoopStrengthReduce::getCastedVersionOf(Instruction::CastOps opcode,
+ Value *V) {
if (V->getType() == UIntPtrTy) return V;
if (Constant *CB = dyn_cast<Constant>(V))
- if (CB->getType()->isInteger())
- return ConstantExpr::getIntegerCast(CB, UIntPtrTy,
- CB->getType()->isSigned());
- else
- return ConstantExpr::getPtrToInt(CB, UIntPtrTy);
+ return ConstantExpr::getCast(opcode, CB, UIntPtrTy);
Value *&New = CastedPointers[V];
if (New) return New;
- New = SCEVExpander::InsertCastOfTo(V, UIntPtrTy);
+ New = SCEVExpander::InsertCastOfTo(opcode, V, UIntPtrTy);
DeadInsts.insert(cast<Instruction>(New));
return New;
}
@@ -258,7 +255,8 @@ SCEVHandle LoopStrengthReduce::GetExpressionSCEV(Instruction *Exp, Loop *L) {
// Build up the base expression. Insert an LLVM cast of the pointer to
// uintptr_t first.
- SCEVHandle GEPVal = SCEVUnknown::get(getCastedVersionOf(GEP->getOperand(0)));
+ SCEVHandle GEPVal = SCEVUnknown::get(
+ getCastedVersionOf(Instruction::PtrToInt, GEP->getOperand(0)));
gep_type_iterator GTI = gep_type_begin(GEP);
@@ -273,7 +271,13 @@ SCEVHandle LoopStrengthReduce::GetExpressionSCEV(Instruction *Exp, Loop *L) {
GEPVal = SCEVAddExpr::get(GEPVal,
SCEVUnknown::getIntegerSCEV(Offset, UIntPtrTy));
} else {
- Value *OpVal = getCastedVersionOf(GEP->getOperand(i));
+ unsigned GEPOpiBits =
+ GEP->getOperand(i)->getType()->getPrimitiveSizeInBits();
+ unsigned IntPtrBits = UIntPtrTy->getPrimitiveSizeInBits();
+ Instruction::CastOps opcode = (GEPOpiBits < IntPtrBits ?
+ Instruction::SExt : (GEPOpiBits > IntPtrBits ? Instruction::Trunc :
+ Instruction::BitCast));
+ Value *OpVal = getCastedVersionOf(opcode, GEP->getOperand(i));
SCEVHandle Idx = SE->getSCEV(OpVal);
uint64_t TypeSize = TD->getTypeSize(GTI.getIndexedType());
@@ -1125,8 +1129,13 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
if (L->contains(User.Inst->getParent()))
User.Inst->moveBefore(LatchBlock->getTerminator());
}
- if (RewriteOp->getType() != ReplacedTy)
- RewriteOp = SCEVExpander::InsertCastOfTo(RewriteOp, ReplacedTy);
+ if (RewriteOp->getType() != ReplacedTy) {
+ Instruction::CastOps opcode = Instruction::Trunc;
+ if (ReplacedTy->getPrimitiveSizeInBits() ==
+ RewriteOp->getType()->getPrimitiveSizeInBits())
+ opcode = Instruction::BitCast;
+ RewriteOp = SCEVExpander::InsertCastOfTo(opcode, RewriteOp, ReplacedTy);
+ }
SCEVHandle RewriteExpr = SCEVUnknown::get(RewriteOp);
OpenPOWER on IntegriCloud