diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 300a564e222e1..7b221a814aabd 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -330,11 +330,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_, while (processBlock(&BB)) // Thread all of the branches we can over BB. Changed = ChangedSinceLastAnalysisUpdate = 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. @@ -366,7 +361,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_, // detect and transform nested loops later. !LoopHeaders.count(&BB) && !LoopHeaders.count(Succ) && TryToSimplifyUncondBranchFromEmptyBlock(&BB, DTU.get())) { - 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); @@ -377,6 +371,13 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_, 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; } diff --git a/llvm/test/Transforms/JumpThreading/thread-debug-info.ll b/llvm/test/Transforms/JumpThreading/thread-debug-info.ll index 4727413b35a60..5a338593e5691 100644 --- a/llvm/test/Transforms/JumpThreading/thread-debug-info.ll +++ b/llvm/test/Transforms/JumpThreading/thread-debug-info.ll @@ -96,6 +96,8 @@ exit: ; preds = %bb.f4, %bb.f3, %bb. ; being threaded, the `and` in the function below is optimised away, but its ; debug-info should still be preserved. ; Similarly, the call to f1 gets cloned, its dbg.value should be cloned too. +; Duplicated debug value in land.end.thr_comm is removed by +; RemoveRedundantDbgInstrs pass at the end. define void @test16(i1 %c, i1 %c2, i1 %c3, i1 %c4) nounwind ssp !dbg !30 { ; CHECK-LABEL: define void @test16(i1 entry: @@ -109,7 +111,6 @@ lor.lhs.false.i: br i1 %c3, label %land.end, label %land.end, !dbg !33 ; CHECK-LABEL: land.end.thr_comm: -; CHECK-NEXT: #dbg_value(i32 0, ; CHECK-NEXT: #dbg_value(i32 1, ; CHECK-NEXT: call void @f1() ; CHECK-NEXT: br i1 %c4,