diff options
author | Chad Rosier <mcrosier@codeaurora.org> | 2016-08-17 14:16:45 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@codeaurora.org> | 2016-08-17 14:16:45 +0000 |
commit | cf3e8121a6c03518b2473250b277a4ce1326f5ed (patch) | |
tree | 7b63ff29b22383570cf3a7fd7e357241b2e74a5c /llvm/lib/Transforms/Scalar/Reassociate.cpp | |
parent | 7a79422536d8ca8779fef9e78911def1d7eaf6f9 (diff) | |
download | bcm5719-llvm-cf3e8121a6c03518b2473250b277a4ce1326f5ed.tar.gz bcm5719-llvm-cf3e8121a6c03518b2473250b277a4ce1326f5ed.zip |
[Reassociate] Avoid iterator invalidation when negating value.
Differential Revision: https://reviews.llvm.org/D23464
PR28367
llvm-svn: 278928
Diffstat (limited to 'llvm/lib/Transforms/Scalar/Reassociate.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index b930a8fb7e9..5b3e7c50e50 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -842,6 +842,13 @@ static Value *NegateValue(Value *V, Instruction *BI, if (TheNeg->getParent()->getParent() != BI->getParent()->getParent()) continue; + // Don't move the negate if it's in the block we're currently optimizing as + // this may invalidate our iterator. + // FIXME: We should find a more robust solution as we're missing local CSE + // opportunities because of this constraint. + if (TheNeg->getParent() == BI->getParent()) + continue; + BasicBlock::iterator InsertPt; if (Instruction *InstInput = dyn_cast<Instruction>(V)) { if (InvokeInst *II = dyn_cast<InvokeInst>(InstInput)) { @@ -1863,6 +1870,8 @@ void ReassociatePass::RecursivelyEraseDeadInsts( /// Zap the given instruction, adding interesting operands to the work list. void ReassociatePass::EraseInst(Instruction *I) { assert(isInstructionTriviallyDead(I) && "Trivially dead instructions only!"); + DEBUG(dbgs() << "Erasing dead inst: "; I->dump()); + SmallVector<Value*, 8> Ops(I->op_begin(), I->op_end()); // Erase the dead instruction. ValueRankMap.erase(I); |