summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/Reassociate.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-06-29 19:03:05 +0000
committerDuncan Sands <baldrick@free.fr>2012-06-29 19:03:05 +0000
commit2923bca2b5fe46189c4c5572047e1d95946ac549 (patch)
tree33fd7c9d836b0294798e4ec439c9fd190dd13a6b /lib/Transforms/Scalar/Reassociate.cpp
parent7d539716e2ef6c953bed51cfab5edba98b557657 (diff)
downloadllvm-2923bca2b5fe46189c4c5572047e1d95946ac549.tar.gz
llvm-2923bca2b5fe46189c4c5572047e1d95946ac549.tar.bz2
llvm-2923bca2b5fe46189c4c5572047e1d95946ac549.tar.xz
Rework this to clarify where the removal of nodes from the queue is
really happening. No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159451 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/Reassociate.cpp')
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index 547a51e7d4..bcf34b5256 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -667,15 +667,13 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
/// the new expression into.
SmallVector<BinaryOperator*, 8> NodesToRewrite;
unsigned Opcode = I->getOpcode();
- NodesToRewrite.push_back(I);
+ BinaryOperator *Op = I;
// ExpressionChanged - Non-null if the rewritten expression differs from the
// original in some non-trivial way, requiring the clearing of optional flags.
// Flags are cleared from the operator in ExpressionChanged up to I inclusive.
BinaryOperator *ExpressionChanged = 0;
for (unsigned i = 0; ; ++i) {
- BinaryOperator *Op = NodesToRewrite.pop_back_val();
-
// The last operation (which comes earliest in the IR) is special as both
// operands will come from Ops, rather than just one with the other being
// a subexpression.
@@ -746,7 +744,7 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
// from the original expression then just rewrite the rest of the expression
// into it.
if (BinaryOperator *BO = isReassociableOp(Op->getOperand(0), Opcode)) {
- NodesToRewrite.push_back(BO);
+ Op = BO;
continue;
}
@@ -757,19 +755,22 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
// hard (finding the mimimal number of multiplications needed to realize a
// multiplication expression is NP-complete). Whatever the reason, smart or
// stupid, create a new node if there are none left.
+ BinaryOperator *NewOp;
if (NodesToRewrite.empty()) {
Constant *Undef = UndefValue::get(I->getType());
- BinaryOperator *N = BinaryOperator::Create(Instruction::BinaryOps(Opcode),
- Undef, Undef, "", I);
- NodesToRewrite.push_back(N);
+ NewOp = BinaryOperator::Create(Instruction::BinaryOps(Opcode),
+ Undef, Undef, "", I);
+ } else {
+ NewOp = NodesToRewrite.pop_back_val();
}
DEBUG(dbgs() << "RA: " << *Op << '\n');
- Op->setOperand(0, NodesToRewrite.back());
+ Op->setOperand(0, NewOp);
DEBUG(dbgs() << "TO: " << *Op << '\n');
ExpressionChanged = Op;
MadeChange = true;
++NumChanged;
+ Op = NewOp;
}
// If the expression changed non-trivially then clear out all subclass data