Skip to content

Commit 9d725b5

Browse files
authored
Merge pull request #2051 from vedantk/eng/PR-66563987
[Utils] Skip RemoveRedundantDbgInstrs in MergeBlockIntoPredecessor (PR47746)
2 parents 082bba6 + da1cc65 commit 9d725b5

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ bool CodeGenPrepare::eliminateFallThrough(Function &F) {
622622
for (auto &Block : llvm::make_range(std::next(F.begin()), F.end()))
623623
Blocks.push_back(&Block);
624624

625+
SmallSet<WeakTrackingVH, 16> Preds;
625626
for (auto &Block : Blocks) {
626627
auto *BB = cast_or_null<BasicBlock>(Block);
627628
if (!BB)
@@ -640,8 +641,16 @@ bool CodeGenPrepare::eliminateFallThrough(Function &F) {
640641

641642
// Merge BB into SinglePred and delete it.
642643
MergeBlockIntoPredecessor(BB);
644+
Preds.insert(SinglePred);
643645
}
644646
}
647+
648+
// (Repeatedly) merging blocks into their predecessors can create redundant
649+
// debug intrinsics.
650+
for (auto &Pred : Preds)
651+
if (auto *BB = cast_or_null<BasicBlock>(Pred))
652+
RemoveRedundantDbgInstrs(BB);
653+
645654
return Changed;
646655
}
647656

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,6 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
285285
// Add unreachable to now empty BB.
286286
new UnreachableInst(BB->getContext(), BB);
287287

288-
// Eliminate duplicate/redundant dbg.values. This seems to be a good place to
289-
// do that since we might end up with redundant dbg.values describing the
290-
// entry PHI node post-splice.
291-
RemoveRedundantDbgInstrs(PredBB);
292-
293288
// Inherit predecessors name if it exists.
294289
if (!PredBB->hasName())
295290
PredBB->takeName(BB);

llvm/lib/Transforms/Utils/LoopRotationUtils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,10 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
575575
// connected by an unconditional branch. This is just a cleanup so the
576576
// emitted code isn't too gross in this common case.
577577
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
578-
MergeBlockIntoPredecessor(OrigHeader, &DTU, LI, MSSAU);
578+
BasicBlock *PredBB = OrigHeader->getUniquePredecessor();
579+
bool DidMerge = MergeBlockIntoPredecessor(OrigHeader, &DTU, LI, MSSAU);
580+
if (DidMerge)
581+
RemoveRedundantDbgInstrs(PredBB);
579582

580583
if (MSSAU && VerifyMemorySSA)
581584
MSSAU->getMemorySSA()->verifyMemorySSA();

llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ init:
88

99
; CHECK: %vala = load i64, i64* %ptr
1010
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD:![0-9]*]]
11+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 %vala, metadata [[MD]]
1112
; CHECK-NEXT: %valbmasked = and i64 %vala, 1
1213

1314
a: ; preds = %init
@@ -26,6 +27,8 @@ test.exit: ; preds = %a, %b
2627
ret i64 %retv
2728
}
2829

30+
; CHECK: [[MD]] = !DILocalVariable(name: "var"
31+
2932
; Function Attrs: nounwind readnone speculatable
3033
declare void @llvm.dbg.value(metadata, metadata, metadata) #0
3134

0 commit comments

Comments
 (0)