diff options
Diffstat (limited to 'lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstructionCombining.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index cee27ff591..a302a46290 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/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' |