summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorWojciech Matyjewicz <wmatyjewicz@fastmail.fm>2008-06-15 19:07:39 +0000
committerWojciech Matyjewicz <wmatyjewicz@fastmail.fm>2008-06-15 19:07:39 +0000
commitae9753b29d63ee83a0bafe51d037b219b0f8ed7a (patch)
tree1c33ea976117d40facebf04f4d247463d67c21c2 /llvm/lib/Analysis/ScalarEvolutionExpander.cpp
parentc6a6618e6ac368fde0f4e46325654fe3affd80b2 (diff)
downloadbcm5719-llvm-ae9753b29d63ee83a0bafe51d037b219b0f8ed7a.tar.gz
bcm5719-llvm-ae9753b29d63ee83a0bafe51d037b219b0f8ed7a.zip
Fix PR2434. When scanning for exising binary operator to reuse don't
take into account the instrucion pointed by InsertPt. Thanks to it, returning the new value of InsertPt to the InsertBinop() caller can be avoided. The bug was, actually, in visitAddRecExpr() method which wasn't correctly handling changes of InsertPt. There shouldn't be any performance regression, as -gvn pass (run after -indvars) removes any redundant binops. llvm-svn: 52291
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolutionExpander.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
index a241960b374..9872ced519e 100644
--- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -73,7 +73,7 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
/// InsertBinop - Insert the specified binary operator, doing a small amount
/// of work to avoid inserting an obviously redundant operation.
Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
- Value *RHS, Instruction *&InsertPt) {
+ Value *RHS, Instruction *InsertPt) {
// Fold a binop with constant operands.
if (Constant *CLHS = dyn_cast<Constant>(LHS))
if (Constant *CRHS = dyn_cast<Constant>(RHS))
@@ -81,21 +81,21 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
// Do a quick scan to see if we have this binop nearby. If so, reuse it.
unsigned ScanLimit = 6;
- for (BasicBlock::iterator IP = InsertPt, E = InsertPt->getParent()->begin();
- ScanLimit; --IP, --ScanLimit) {
- if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(IP))
- if (BinOp->getOpcode() == Opcode && BinOp->getOperand(0) == LHS &&
- BinOp->getOperand(1) == RHS) {
- // If we found the instruction *at* the insert point, insert later
- // instructions after it.
- if (BinOp == InsertPt)
- InsertPt = ++IP;
- return BinOp;
- }
- if (IP == E) break;
+ BasicBlock::iterator BlockBegin = InsertPt->getParent()->begin();
+ if (InsertPt != BlockBegin) {
+ // Scanning starts from the last instruction before InsertPt.
+ BasicBlock::iterator IP = InsertPt;
+ --IP;
+ for (; ScanLimit; --IP, --ScanLimit) {
+ if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(IP))
+ if (BinOp->getOpcode() == Opcode && BinOp->getOperand(0) == LHS &&
+ BinOp->getOperand(1) == RHS)
+ return BinOp;
+ if (IP == BlockBegin) break;
+ }
}
-
- // If we don't have
+
+ // If we haven't found this binop, insert it.
return BinaryOperator::Create(Opcode, LHS, RHS, "tmp", InsertPt);
}
OpenPOWER on IntegriCloud