diff options
| author | Jim Grosbach <grosbach@apple.com> | 2011-10-05 20:05:00 +0000 | 
|---|---|---|
| committer | Jim Grosbach <grosbach@apple.com> | 2011-10-05 20:05:00 +0000 | 
| commit | e37e0301372667edae46092b5bef93a6cd3e0e3a (patch) | |
| tree | d7acc2f85a34c7241edd1863f491e4a4f92c0c08 /llvm/lib/Transforms | |
| parent | 9b1311df26041d76129d933f7eec796f559b88c9 (diff) | |
| download | bcm5719-llvm-e37e0301372667edae46092b5bef93a6cd3e0e3a.tar.gz bcm5719-llvm-e37e0301372667edae46092b5bef93a6cd3e0e3a.zip | |
Update InstCombine worklist after instruction transform is complete.
When updating the worklist for InstCombine, the Add/AddUsersToWorklist
functions may access the instruction(s) being added, for debug output for
example. If the instructions aren't yet added to the basic block, this
can result in a crash. Finish the instruction transformation before
adjusting the worklist instead.
rdar://10238555
llvm-svn: 141203
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 17 | 
1 files changed, 9 insertions, 8 deletions
| diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index cee27ff5913..a302a46290e 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2009,21 +2009,18 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {        ++NumCombined;        // Should we replace the old instruction with a new one?        if (Result != I) { -        DEBUG(errs() << "IC: Old = " << *I << '\n' -                     << "    New = " << *Result << '\n'); -          if (!I->getDebugLoc().isUnknown())            Result->setDebugLoc(I->getDebugLoc());          // Everything uses the new instruction now.          I->replaceAllUsesWith(Result); -        // Push the new instruction and any users onto the worklist. -        Worklist.Add(Result); -        Worklist.AddUsersToWorkList(*Result); - -        // Move the name to the new instruction first. +        // Move the name to the new instruction.          Result->takeName(I); +        DEBUG(errs() << "IC: Old = " << *I << '\n' +                     << "    New = " << *Result << '\n'); + +          // Insert the new instruction into the basic block...          BasicBlock *InstParent = I->getParent();          BasicBlock::iterator InsertPos = I; @@ -2035,6 +2032,10 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {          InstParent->getInstList().insert(InsertPos, Result);          EraseInstFromFunction(*I); + +        // Push the new instruction and any users onto the worklist. +        Worklist.Add(Result); +        Worklist.AddUsersToWorkList(*Result);        } else {  #ifndef NDEBUG          DEBUG(errs() << "IC: Mod = " << OrigI << '\n' | 

