Skip to content

[RemoveDIs] Fix SimplifyCFG behaviour to match existing behaviour #82981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3208,8 +3208,9 @@ bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI,
// end of this block.
for (auto &It : make_range(ThenBB->begin(), ThenBB->end()))
for (DbgRecord &DR : make_early_inc_range(It.getDbgValueRange()))
if (DPValue *DPV = dyn_cast<DPValue>(&DR); DPV && !DPV->isDbgAssign())
It.dropOneDbgValue(DPV);
// Drop all records except assign-kind DPValues (dbg.assign equivalent).
if (DPValue *DPV = dyn_cast<DPValue>(&DR); !DPV || !DPV->isDbgAssign())
It.dropOneDbgValue(&DR);
Comment on lines +3212 to +3213
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this condition going to become !isa<DbgAssign> in the future-class-refactor? It's worth commenting on what you're filtering for seeing how the current arrangement makes it non-obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this condition going to become !isa in the future-class-refactor?

It may, I'm not sure we ever landed on a decision as to whether we should extract the 3 DPValue kinds into their own classes too. But yes I can add a comment, SGTM

BB->splice(BI->getIterator(), ThenBB, ThenBB->begin(),
std::prev(ThenBB->end()));

Expand Down
8 changes: 7 additions & 1 deletion llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ define i1 @foo(i32) nounwind ssp !dbg !0 {
; CHECK-NEXT: [[TMP8:%.*]] = icmp slt i32 [[TMP0]], 0
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[OR_COND2]], i1 false, i1 [[TMP8]], !dbg [[DBG7]]
; CHECK-NEXT: br label [[COMMON_RET]], !dbg [[DBG7]]
; CHECK-NOT: BB4
; CHECK: common.ret:
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[SPEC_SELECT]], [[BB2]] ]
; CHECK-NEXT: ret i1 [[COMMON_RET_OP]], !dbg [[DBG14:![0-9]+]]
;

Entry:
%1 = icmp slt i32 %0, 0, !dbg !5
br i1 %1, label %BB5, label %BB1, !dbg !5
Expand All @@ -55,6 +56,10 @@ BB3: ; preds = %BB2

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

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