diff options
author | Dan Gohman <gohman@apple.com> | 2009-04-23 15:16:49 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-04-23 15:16:49 +0000 |
commit | 752ec7da506f5d41c08bd37e195750b57550ce68 (patch) | |
tree | 29c9aa4f22339fc36ee937332eb664934ada172a /lib/Transforms/Scalar | |
parent | b1f321b5539a7f14864c0dc7ed44176785c62d14 (diff) | |
download | external_llvm-752ec7da506f5d41c08bd37e195750b57550ce68.zip external_llvm-752ec7da506f5d41c08bd37e195750b57550ce68.tar.gz external_llvm-752ec7da506f5d41c08bd37e195750b57550ce68.tar.bz2 |
Change SCEVExpander's expandCodeFor to provide more flexibility
with the persistent insertion point, and change IndVars to make
use of it. This fixes a bug where IndVars was holding on to a
stale insertion point and forcing the SCEVExpander to continue to
use it.
This fixes PR4038.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69892 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 63ef021..cc3919d 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -543,8 +543,7 @@ static Value *getSignExtendedTruncVar(const SCEVAddRecExpr *AR, ScalarEvolution *SE, const Type *LargestType, Loop *L, const Type *myType, - SCEVExpander &Rewriter, - BasicBlock::iterator InsertPt) { + SCEVExpander &Rewriter) { SCEVHandle ExtendedStart = SE->getSignExtendExpr(AR->getStart(), LargestType); SCEVHandle ExtendedStep = @@ -553,15 +552,14 @@ static Value *getSignExtendedTruncVar(const SCEVAddRecExpr *AR, SE->getAddRecExpr(ExtendedStart, ExtendedStep, L); if (LargestType != myType) ExtendedAddRec = SE->getTruncateExpr(ExtendedAddRec, myType); - return Rewriter.expandCodeFor(ExtendedAddRec, myType, InsertPt); + return Rewriter.expandCodeFor(ExtendedAddRec, myType); } static Value *getZeroExtendedTruncVar(const SCEVAddRecExpr *AR, ScalarEvolution *SE, const Type *LargestType, Loop *L, const Type *myType, - SCEVExpander &Rewriter, - BasicBlock::iterator InsertPt) { + SCEVExpander &Rewriter) { SCEVHandle ExtendedStart = SE->getZeroExtendExpr(AR->getStart(), LargestType); SCEVHandle ExtendedStep = @@ -570,7 +568,7 @@ static Value *getZeroExtendedTruncVar(const SCEVAddRecExpr *AR, SE->getAddRecExpr(ExtendedStart, ExtendedStep, L); if (LargestType != myType) ExtendedAddRec = SE->getTruncateExpr(ExtendedAddRec, myType); - return Rewriter.expandCodeFor(ExtendedAddRec, myType, InsertPt); + return Rewriter.expandCodeFor(ExtendedAddRec, myType); } /// allUsesAreSameTyped - See whether all Uses of I are instructions @@ -699,6 +697,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // recurrences in terms of the induction variable. Start with the auxillary // induction variables, and recursively rewrite any of their uses. BasicBlock::iterator InsertPt = Header->getFirstNonPHI(); + Rewriter.setInsertionPoint(InsertPt); // If there were induction variables of other sizes, cast the primary // induction variable to the right size for them, avoiding the need for the @@ -718,7 +717,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { while (!IndVars.empty()) { PHINode *PN = IndVars.back().first; const SCEVAddRecExpr *AR = cast<SCEVAddRecExpr>(IndVars.back().second); - Value *NewVal = Rewriter.expandCodeFor(AR, PN->getType(), InsertPt); + Value *NewVal = Rewriter.expandCodeFor(AR, PN->getType()); DOUT << "INDVARS: Rewrote IV '" << *AR << "' " << *PN << " into = " << *NewVal << "\n"; NewVal->takeName(PN); @@ -732,7 +731,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { Instruction *UInst = dyn_cast<Instruction>(*UI); if (UInst && isa<SExtInst>(UInst) && NoSignedWrap) { Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, L, - UInst->getType(), Rewriter, InsertPt); + UInst->getType(), Rewriter); UInst->replaceAllUsesWith(TruncIndVar); DeadInsts.insert(UInst); } @@ -753,8 +752,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { SExtInst* oldSext = dyn_cast<SExtInst>(UInst->use_begin()); uint64_t truncSize = oldSext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, - L, oldSext->getType(), Rewriter, - InsertPt); + L, oldSext->getType(), Rewriter); APInt APnewAddRHS = APInt(AddRHS->getValue()).sext(newBitSize); if (newBitSize > truncSize) APnewAddRHS = APnewAddRHS.trunc(truncSize); @@ -784,8 +782,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { SExtInst* oldSext = dyn_cast<SExtInst>(UInst->use_begin()); uint64_t truncSize = oldSext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, - L, oldSext->getType(), Rewriter, - InsertPt); + L, oldSext->getType(), Rewriter); APInt APnewOrRHS = APInt(RHS->getValue()).sext(newBitSize); if (newBitSize > truncSize) APnewOrRHS = APnewOrRHS.trunc(truncSize); @@ -805,7 +802,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // A zext of a signed variable known not to overflow is still safe. if (UInst && isa<ZExtInst>(UInst) && (NoUnsignedWrap || NoSignedWrap)) { Value *TruncIndVar = getZeroExtendedTruncVar(AR, SE, LargestType, L, - UInst->getType(), Rewriter, InsertPt); + UInst->getType(), Rewriter); UInst->replaceAllUsesWith(TruncIndVar); DeadInsts.insert(UInst); } @@ -822,7 +819,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { ZExtInst* oldZext = dyn_cast<ZExtInst>(UInst->use_begin()); uint64_t truncSize = oldZext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, - L, oldZext->getType(), Rewriter, InsertPt); + L, oldZext->getType(), Rewriter); APInt APnewAndRHS = APInt(AndRHS->getValue()).zext(newBitSize); if (newBitSize > truncSize) APnewAndRHS = APnewAndRHS.trunc(truncSize); @@ -858,7 +855,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { ZExtInst* oldZext = dyn_cast<ZExtInst>(UInst2->use_begin()); uint64_t truncSize = oldZext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, - L, oldZext->getType(), Rewriter, InsertPt); + L, oldZext->getType(), Rewriter); ConstantInt* AndRHS = dyn_cast<ConstantInt>(UInst2->getOperand(1)); APInt APnewAddRHS = APInt(AddRHS->getValue()).zext(newBitSize); if (newBitSize > truncSize) |