summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/Reassociate.cpp
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
commita33701098936ffba12326d96e98d388357f3e098 (patch)
treecff3195892a74d216f1bdeff1d08179567796517 /lib/Transforms/Scalar/Reassociate.cpp
parent1f9838347fdcc75cead228ec1758063074b89c6a (diff)
downloadllvm-a33701098936ffba12326d96e98d388357f3e098.tar.gz
llvm-a33701098936ffba12326d96e98d388357f3e098.tar.bz2
llvm-a33701098936ffba12326d96e98d388357f3e098.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/Reassociate.cpp')
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index 010f17aae0..6ef0c97d37 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/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,