Skip to content

Commit 954a048

Browse files
authored
[RemoveDIs] Fix SimplifyCFG behaviour to match existing behaviour (#82981)
llvm.dbg.labels are deleted in SpeculativelyExecuteBB so DPLabels should be too. Modify existing test to check this (NB I couldn't find a dedicated debug-info test that checks this behaviour).
1 parent b4b4904 commit 954a048

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,8 +3208,9 @@ bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI,
32083208
// end of this block.
32093209
for (auto &It : make_range(ThenBB->begin(), ThenBB->end()))
32103210
for (DbgRecord &DR : make_early_inc_range(It.getDbgValueRange()))
3211-
if (DPValue *DPV = dyn_cast<DPValue>(&DR); DPV && !DPV->isDbgAssign())
3212-
It.dropOneDbgValue(DPV);
3211+
// Drop all records except assign-kind DPValues (dbg.assign equivalent).
3212+
if (DPValue *DPV = dyn_cast<DPValue>(&DR); !DPV || !DPV->isDbgAssign())
3213+
It.dropOneDbgValue(&DR);
32133214
BB->splice(BI->getIterator(), ThenBB, ThenBB->begin(),
32143215
std::prev(ThenBB->end()));
32153216

llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ define i1 @foo(i32) nounwind ssp !dbg !0 {
2626
; CHECK-NEXT: [[TMP8:%.*]] = icmp slt i32 [[TMP0]], 0
2727
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[OR_COND2]], i1 false, i1 [[TMP8]], !dbg [[DBG7]]
2828
; CHECK-NEXT: br label [[COMMON_RET]], !dbg [[DBG7]]
29+
; CHECK-NOT: BB4
2930
; CHECK: common.ret:
3031
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[SPEC_SELECT]], [[BB2]] ]
3132
; CHECK-NEXT: ret i1 [[COMMON_RET_OP]], !dbg [[DBG14:![0-9]+]]
32-
;
33+
3334
Entry:
3435
%1 = icmp slt i32 %0, 0, !dbg !5
3536
br i1 %1, label %BB5, label %BB1, !dbg !5
@@ -55,6 +56,10 @@ BB3: ; preds = %BB2
5556

5657
BB4: ; preds = %BB3
5758
%8 = icmp slt i32 %0, 0, !dbg !5
59+
;; Manually inserted intrinsics; these should get deleted when this block is
60+
;; folded into BB2.
61+
call void @llvm.dbg.value(metadata ptr null, metadata !7, metadata !DIExpression()), !dbg !12
62+
call void @llvm.dbg.label(metadata !18), !dbg !12
5863
ret i1 %8, !dbg !14
5964

6065
BB5: ; preds = %BB3, %BB2, %BB1, %Entry
@@ -84,3 +89,4 @@ declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone
8489
!15 = !DIFile(filename: "a.c", directory: "/private/tmp")
8590
!16 = !{i32 1, !"Debug Info Version", i32 3}
8691
!17 = !{i32 2, !"Dwarf Version", i32 4}
92+
!18 = !DILabel(scope: !0, name: "label", file: !1, line: 1)

0 commit comments

Comments
 (0)