summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-05-08 12:16:05 +0000
committerDuncan Sands <baldrick@free.fr>2012-05-08 12:16:05 +0000
commit3bbb1d50df60340d5eac9384b7140db29fcf9e51 (patch)
tree40b2329b4f5709fcb4c2087590677d7263fdd59e /llvm/lib
parent5eafce5c88152dc4a281bd40b92d4525c9df1976 (diff)
downloadbcm5719-llvm-3bbb1d50df60340d5eac9384b7140db29fcf9e51.tar.gz
bcm5719-llvm-3bbb1d50df60340d5eac9384b7140db29fcf9e51.zip
Calling ReassociateExpression recursively is extremely dangerous since it will
replace the operands of expressions with only one use with undef and generate a new expression for the original without using RAUW to update the original. Thus any copies of the original expression held in a vector may end up referring to some bogus value - and using a ValueHandle won't help since there is no RAUW. There is already a mechanism for getting the effect of recursion non-recursively: adding the value to be recursed on to RedoInsts. But it wasn't being used systematically. Have various places where recursion had snuck in at some point use the RedoInsts mechanism instead. Fixes PR12169. llvm-svn: 156379
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/Reassociate.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 010f17aae0b..6ef0c97d375 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -910,14 +910,14 @@ Value *Reassociate::OptimizeAdd(Instruction *I,
// A*A*B + A*A*C --> A*(A*B+A*C) --> A*(A*(B+C))
assert(NumAddedValues > 1 && "Each occurrence should contribute a value");
(void)NumAddedValues;
- V = ReassociateExpression(cast<BinaryOperator>(V));
+ RedoInsts.push_back(V);
// Create the multiply.
Value *V2 = BinaryOperator::CreateMul(V, MaxOccVal, "tmp", I);
// Rerun associate on the multiply in case the inner expression turned into
// a multiply. We want to make sure that we keep things in canonical form.
- V2 = ReassociateExpression(cast<BinaryOperator>(V2));
+ RedoInsts.push_back(V2);
// If every add operand included the factor (e.g. "A*B + A*C"), then the
// entire result expression is just the multiply "A*(B+C)".
@@ -1070,9 +1070,8 @@ Value *Reassociate::buildMinimalMultiplyDAG(IRBuilder<> &Builder,
// Reset the base value of the first factor to the new expression tree.
// We'll remove all the factors with the same power in a second pass.
- Factors[LastIdx].Base
- = ReassociateExpression(
- cast<BinaryOperator>(buildMultiplyTree(Builder, InnerProduct)));
+ Factors[LastIdx].Base = buildMultiplyTree(Builder, InnerProduct);
+ RedoInsts.push_back(Factors[LastIdx].Base);
LastIdx = Idx;
}
@@ -1098,8 +1097,9 @@ Value *Reassociate::buildMinimalMultiplyDAG(IRBuilder<> &Builder,
if (OuterProduct.size() == 1)
return OuterProduct.front();
- return ReassociateExpression(
- cast<BinaryOperator>(buildMultiplyTree(Builder, OuterProduct)));
+ Value *V = buildMultiplyTree(Builder, OuterProduct);
+ RedoInsts.push_back(V);
+ return V;
}
Value *Reassociate::OptimizeMul(BinaryOperator *I,
OpenPOWER on IntegriCloud