summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-12-14 16:52:55 +0000
committerDan Gohman <gohman@apple.com>2009-12-14 16:52:55 +0000
commit67b94fb73d3cc1b93348b3a5675ad395b9f27227 (patch)
treeb8098eba1023c1a175c3024414df22fefc9c627c /lib/Transforms/Scalar/LoopStrengthReduce.cpp
parentb058ceda5689b790cb05c33270da35c74dc06e48 (diff)
downloadllvm-67b94fb73d3cc1b93348b3a5675ad395b9f27227.tar.gz
llvm-67b94fb73d3cc1b93348b3a5675ad395b9f27227.tar.bz2
llvm-67b94fb73d3cc1b93348b3a5675ad395b9f27227.tar.xz
Remove the code in LSR that manually hoists expansions out of loops;
SCEVExpander does this automatically. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91281 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp38
1 files changed, 9 insertions, 29 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 5920925341..b114f2ef2d 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -109,8 +109,7 @@ namespace {
public:
static char ID; // Pass ID, replacement for typeid
explicit LoopStrengthReduce(const TargetLowering *tli = NULL) :
- LoopPass(&ID), TLI(tli) {
- }
+ LoopPass(&ID), TLI(tli) {}
bool runOnLoop(Loop *L, LPPassManager &LPM);
@@ -381,14 +380,12 @@ namespace {
void RewriteInstructionToUseNewBase(const SCEV *const &NewBase,
Instruction *InsertPt,
SCEVExpander &Rewriter, Loop *L, Pass *P,
- LoopInfo &LI,
SmallVectorImpl<WeakVH> &DeadInsts);
Value *InsertCodeForBaseAtPosition(const SCEV *const &NewBase,
const Type *Ty,
SCEVExpander &Rewriter,
- Instruction *IP, Loop *L,
- LoopInfo &LI);
+ Instruction *IP);
void dump() const;
};
}
@@ -402,27 +399,11 @@ void BasedUser::dump() const {
Value *BasedUser::InsertCodeForBaseAtPosition(const SCEV *const &NewBase,
const Type *Ty,
SCEVExpander &Rewriter,
- Instruction *IP, Loop *L,
- LoopInfo &LI) {
- // Figure out where we *really* want to insert this code. In particular, if
- // the user is inside of a loop that is nested inside of L, we really don't
- // want to insert this expression before the user, we'd rather pull it out as
- // many loops as possible.
- Instruction *BaseInsertPt = IP;
-
- // Figure out the most-nested loop that IP is in.
- Loop *InsertLoop = LI.getLoopFor(IP->getParent());
-
- // If InsertLoop is not L, and InsertLoop is nested inside of L, figure out
- // the preheader of the outer-most loop where NewBase is not loop invariant.
- if (L->contains(IP->getParent()))
- while (InsertLoop && NewBase->isLoopInvariant(InsertLoop)) {
- BaseInsertPt = InsertLoop->getLoopPreheader()->getTerminator();
- InsertLoop = InsertLoop->getParentLoop();
- }
-
- Value *Base = Rewriter.expandCodeFor(NewBase, 0, BaseInsertPt);
+ Instruction *IP) {
+ Value *Base = Rewriter.expandCodeFor(NewBase, 0, IP);
+ // Wrap the base in a SCEVUnknown so that ScalarEvolution doesn't try to
+ // re-analyze it.
const SCEV *NewValSCEV = SE->getUnknown(Base);
// Always emit the immediate into the same block as the user.
@@ -441,7 +422,6 @@ Value *BasedUser::InsertCodeForBaseAtPosition(const SCEV *const &NewBase,
void BasedUser::RewriteInstructionToUseNewBase(const SCEV *const &NewBase,
Instruction *NewBasePt,
SCEVExpander &Rewriter, Loop *L, Pass *P,
- LoopInfo &LI,
SmallVectorImpl<WeakVH> &DeadInsts) {
if (!isa<PHINode>(Inst)) {
// By default, insert code at the user instruction.
@@ -471,7 +451,7 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEV *const &NewBase,
}
Value *NewVal = InsertCodeForBaseAtPosition(NewBase,
OperandValToReplace->getType(),
- Rewriter, InsertPt, L, LI);
+ Rewriter, InsertPt);
// Replace the use of the operand Value with the new Phi we just created.
Inst->replaceUsesOfWith(OperandValToReplace, NewVal);
@@ -533,7 +513,7 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEV *const &NewBase,
PHIPred->getTerminator() :
OldLoc->getParent()->getTerminator();
Code = InsertCodeForBaseAtPosition(NewBase, PN->getType(),
- Rewriter, InsertPt, L, LI);
+ Rewriter, InsertPt);
DEBUG(errs() << " Changing PHI use to ");
DEBUG(WriteAsOperand(errs(), Code, /*PrintType=*/false));
@@ -1778,7 +1758,7 @@ LoopStrengthReduce::StrengthReduceIVUsersOfStride(const SCEV *const &Stride,
RewriteExpr = SE->getAddExpr(RewriteExpr, SE->getUnknown(BaseV));
User.RewriteInstructionToUseNewBase(RewriteExpr, NewBasePt,
- Rewriter, L, this, *LI,
+ Rewriter, L, this,
DeadInsts);
// Mark old value we replaced as possibly dead, so that it is eliminated