[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Reid Spencer
reid at x10sys.com
Wed Dec 13 00:07:03 PST 2006
Changes in directory llvm/lib/Transforms/Scalar:
LoopStrengthReduce.cpp updated: 1.99 -> 1.100
---
Log message:
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.
---
Diffs of the changes: (+21 -12)
LoopStrengthReduce.cpp | 33 +++++++++++++++++++++------------
1 files changed, 21 insertions(+), 12 deletions(-)
Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.99 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.100
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.99 Mon Dec 11 23:04:59 2006
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Dec 13 02:06:42 2006
@@ -177,7 +177,7 @@
/// 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 @@
/// 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 @@
// 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 @@
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 @@
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);
More information about the llvm-commits
mailing list