diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-22 05:02:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-22 05:02:01 +0000 |
commit | 18b3c97bc773b24a66eb779e85da1820b0f16b31 (patch) | |
tree | 540674aef19964f6b0a047c8a29b175801d5fb0c | |
parent | f045328dd11ffcba04f437ed244e4cd2d352fe3d (diff) | |
download | external_llvm-18b3c97bc773b24a66eb779e85da1820b0f16b31.zip external_llvm-18b3c97bc773b24a66eb779e85da1820b0f16b31.tar.gz external_llvm-18b3c97bc773b24a66eb779e85da1820b0f16b31.tar.bz2 |
Implement IndVarsSimplify/pointer-indvars.ll, transforming pointer
arithmetic into "array subscripts"
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10580 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 954844b..ac986ea 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -17,8 +17,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Constants.h" #include "llvm/Type.h" -#include "llvm/iPHINode.h" -#include "llvm/iOther.h" +#include "llvm/Instructions.h" #include "llvm/Analysis/InductionVariable.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/CFG.h" @@ -195,12 +194,12 @@ bool IndVarSimplify::runOnLoop(Loop *Loop) { while (isa<PHINode>(AfterPHIIt)) ++AfterPHIIt; - // Don't do math with pointers... - const Type *IVTy = IV->Phi->getType(); - if (isa<PointerType>(IVTy)) IVTy = Type::ULongTy; - // Don't modify the canonical indvar or unrecognized indvars... if (IV != Canonical && IV->InductionType != InductionVariable::Unknown) { + const Type *IVTy = IV->Phi->getType(); + if (isa<PointerType>(IVTy)) // If indexing into a pointer, make the + IVTy = TD->getIntPtrType(); // index the appropriate type. + Instruction *Val = IterCount; if (!isa<ConstantInt>(IV->Step) || // If the step != 1 !cast<ConstantInt>(IV->Step)->equalsInt(1)) { @@ -216,15 +215,26 @@ bool IndVarSimplify::runOnLoop(Loop *Loop) { IV->Phi->getName()+"-scale", AfterPHIIt); } - // If the start != 0 - if (IV->Start != Constant::getNullValue(IV->Start->getType())) { + // If this is a pointer indvar... + if (isa<PointerType>(IV->Phi->getType())) { + std::vector<Value*> Idx; + // FIXME: this should not be needed when we fix PR82! + if (Val->getType() != Type::LongTy) + Val = new CastInst(Val, Type::LongTy, Val->getName(), AfterPHIIt); + Idx.push_back(Val); + Val = new GetElementPtrInst(IV->Start, Idx, + IV->Phi->getName()+"-offset", + AfterPHIIt); + + } else if (!isa<Constant>(IV->Start) || // If Start != 0... + !cast<Constant>(IV->Start)->isNullValue()) { // If the types are not compatible, insert a cast now... if (Val->getType() != IVTy) Val = new CastInst(Val, IVTy, Val->getName(), AfterPHIIt); if (IV->Start->getType() != IVTy) IV->Start = new CastInst(IV->Start, IVTy, IV->Start->getName(), AfterPHIIt); - + // Insert the instruction after the phi nodes... Val = BinaryOperator::create(Instruction::Add, Val, IV->Start, IV->Phi->getName()+"-offset", AfterPHIIt); |