[llvm] [RemoveDIs] Fix SimplifyCFG behaviour to match existing behaviour (PR #82981)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 02:47:46 PST 2024
https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/82981
>From 6e201b40736c31e07489d6fdaee606a9e7d50676 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 26 Feb 2024 10:38:22 +0000
Subject: [PATCH 1/3] [RemoveDIs] Fix SimplifyCFG behaviour to match existing
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).
---
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 4 ++--
llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 9562d44400448b..df29d445e2a651 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3208,8 +3208,8 @@ 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);
+ if (DPValue *DPV = dyn_cast<DPValue>(&DR); !DPV || !DPV->isDbgAssign())
+ It.dropOneDbgValue(&DR);
BB->splice(BI->getIterator(), ThenBB, ThenBB->begin(),
std::prev(ThenBB->end()));
diff --git a/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll b/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
index 833d72773cdc83..ea21bc4ef2f892 100644
--- a/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
+++ b/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
@@ -55,6 +55,10 @@ BB3: ; preds = %BB2
BB4: ; preds = %BB3
%8 = icmp slt i32 %0, 0, !dbg !5
+ ;; Manually insreted intrinsics; these should get deletd 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
@@ -84,3 +88,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)
\ No newline at end of file
>From 0191dc1745b515407fe839deadb3c3ac038a6e5e Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 26 Feb 2024 10:44:15 +0000
Subject: [PATCH 2/3] improve test, fix whitespace
---
llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll b/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
index ea21bc4ef2f892..48e831b4206453 100644
--- a/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
+++ b/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
@@ -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
@@ -88,4 +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)
\ No newline at end of file
+!18 = !DILabel(scope: !0, name: "label", file: !1, line: 1)
>From fb19e57a09c53d5c0e48907bc6f9b16a2ab69cb2 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 26 Feb 2024 10:47:25 +0000
Subject: [PATCH 3/3] typos in comment
---
llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll b/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
index 48e831b4206453..ae43bab2f4fe59 100644
--- a/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
+++ b/llvm/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
@@ -56,7 +56,7 @@ BB3: ; preds = %BB2
BB4: ; preds = %BB3
%8 = icmp slt i32 %0, 0, !dbg !5
- ;; Manually insreted intrinsics; these should get deletd when this block is
+ ;; 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
More information about the llvm-commits
mailing list