diff options
author | Chris Lattner <sabre@nondot.org> | 2002-05-14 15:24:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-05-14 15:24:07 +0000 |
commit | b3bc8fa75508ae996dbc71283186502f2c43f47c (patch) | |
tree | 63fa804685b24c895c9d0aa703d369ef6b890fdf | |
parent | 0c131b6adf3fd50f7e92e72e69b4e9fa5b2b0690 (diff) |
Fix bug: test/Regression/Transforms/InstCombine/2002-05-14-TouchDeletedInst.ll
"This testcase caused instcombine to fail because it got the same instruction on
it's worklist more than once (which is ok), but then deleted the instruction.
Since the inst stayed on the worklist, as soon as it came back up to be
processed, bad things happened, and opt asserted."
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2623 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 0f676426e1..0812fca6e9 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -26,6 +26,7 @@ #include "llvm/Support/InstIterator.h" #include "llvm/Support/InstVisitor.h" #include "Support/StatisticReporter.h" +#include <algorithm> static Statistic<> NumCombined("instcombine\t- Number of insts combined"); @@ -551,8 +552,18 @@ bool InstCombiner::runOnFunction(Function *F) { if (Result) { ++NumCombined; // Should we replace the old instruction with a new one? - if (Result != I) + if (Result != I) { + // Instructions can end up on the worklist more than once. Make sure + // we do not process an instruction that has been deleted. + std::vector<Instruction*>::iterator It = std::find(WorkList.begin(), + WorkList.end(), I); + while (It != WorkList.end()) { + It = WorkList.erase(It); + It = std::find(It, WorkList.end(), I); + } + ReplaceInstWithInst(I, Result); + } WorkList.push_back(Result); AddUsesToWorkList(Result); |