diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index f41eaed2e3e7e617a43bfd15bb460f612422e0ab..e2bda38b81dbb94438c383f8fa0c8014a6f01eef 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -429,11 +429,6 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_, while (processBlock(&BB)) // Thread all of the branches we can over BB. Changed = true; - // Jump threading may have introduced redundant debug values into BB - // which should be removed. - if (Changed) - RemoveRedundantDbgInstrs(&BB); - // Stop processing BB if it's the entry or is now deleted. The following // routines attempt to eliminate BB and locating a suitable replacement // for the entry is non-trivial. @@ -465,7 +460,6 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_, // detect and transform nested loops later. !LoopHeaders.count(&BB) && !LoopHeaders.count(Succ) && TryToSimplifyUncondBranchFromEmptyBlock(&BB, DTU)) { - RemoveRedundantDbgInstrs(Succ); // BB is valid for cleanup here because we passed in DTU. F remains // BB's parent until a DTU->getDomTree() event. LVI->eraseBlock(&BB); @@ -476,6 +470,13 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_, EverChanged |= Changed; } while (Changed); + // Jump threading may have introduced redundant debug values into F which + // should be removed. + if (EverChanged) + for (auto &BB : F) { + RemoveRedundantDbgInstrs(&BB); + } + LoopHeaders.clear(); return EverChanged; }