Skip to content

Commit e45de3d

Browse files
authored
Move RemoveRedundantDbgInstrs outside of inner loop in JumpThreading (#123008)
This cleanup action only needs to be performed once when the entire optimization is converged. Doing it in every iteration has a very high time-complexity, as it queries every dbg value in a dense map Compare before and after for one internal source file with many basic blocks ![image](https://github.com/user-attachments/assets/1dac76a9-a974-4068-9aa1-4041f963fa8e) ![image](https://github.com/user-attachments/assets/73ea2ef1-d1f4-4064-8826-8c13fb539b8d) >90% reduction in this extreme case.
1 parent b9813ce commit e45de3d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
330330
while (processBlock(&BB)) // Thread all of the branches we can over BB.
331331
Changed = ChangedSinceLastAnalysisUpdate = true;
332332

333-
// Jump threading may have introduced redundant debug values into BB
334-
// which should be removed.
335-
if (Changed)
336-
RemoveRedundantDbgInstrs(&BB);
337-
338333
// Stop processing BB if it's the entry or is now deleted. The following
339334
// routines attempt to eliminate BB and locating a suitable replacement
340335
// for the entry is non-trivial.
@@ -366,7 +361,6 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
366361
// detect and transform nested loops later.
367362
!LoopHeaders.count(&BB) && !LoopHeaders.count(Succ) &&
368363
TryToSimplifyUncondBranchFromEmptyBlock(&BB, DTU.get())) {
369-
RemoveRedundantDbgInstrs(Succ);
370364
// BB is valid for cleanup here because we passed in DTU. F remains
371365
// BB's parent until a DTU->getDomTree() event.
372366
LVI->eraseBlock(&BB);
@@ -377,6 +371,13 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
377371
EverChanged |= Changed;
378372
} while (Changed);
379373

374+
// Jump threading may have introduced redundant debug values into F which
375+
// should be removed.
376+
if (EverChanged)
377+
for (auto &BB : *F) {
378+
RemoveRedundantDbgInstrs(&BB);
379+
}
380+
380381
LoopHeaders.clear();
381382
return EverChanged;
382383
}

llvm/test/Transforms/JumpThreading/thread-debug-info.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ exit: ; preds = %bb.f4, %bb.f3, %bb.
9696
; being threaded, the `and` in the function below is optimised away, but its
9797
; debug-info should still be preserved.
9898
; Similarly, the call to f1 gets cloned, its dbg.value should be cloned too.
99+
; Duplicated debug value in land.end.thr_comm is removed by
100+
; RemoveRedundantDbgInstrs pass at the end.
99101
define void @test16(i1 %c, i1 %c2, i1 %c3, i1 %c4) nounwind ssp !dbg !30 {
100102
; CHECK-LABEL: define void @test16(i1
101103
entry:
@@ -109,7 +111,6 @@ lor.lhs.false.i:
109111
br i1 %c3, label %land.end, label %land.end, !dbg !33
110112

111113
; CHECK-LABEL: land.end.thr_comm:
112-
; CHECK-NEXT: #dbg_value(i32 0,
113114
; CHECK-NEXT: #dbg_value(i32 1,
114115
; CHECK-NEXT: call void @f1()
115116
; CHECK-NEXT: br i1 %c4,

0 commit comments

Comments
 (0)