Skip to content

Commit 2188a56

Browse files
authoredNov 15, 2024··
[DebugInfo][SimplifyCFG] Fully propagate merged invoke DILocations (#114235)
Currently when we merge invokes as part of SimplifyCFG we apply a merge of the invoke DILocations to the merged invoke. We also insert an unconditional branch to the merged invoke at the positions previously occupied by the original invokes; as this branch is part of the substitution for the invoke it has replaced, we should propagate the original invoke DebugLoc to it.
1 parent 92cc805 commit 2188a56

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed
 

‎llvm/lib/Transforms/Utils/SimplifyCFG.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,10 @@ static void mergeCompatibleInvokesImpl(ArrayRef<InvokeInst *> Invokes,
29182918
// to the block with the merged `invoke`.
29192919
for (BasicBlock *OrigSuccBB : successors(II->getParent()))
29202920
OrigSuccBB->removePredecessor(II->getParent());
2921-
BranchInst::Create(MergedInvoke->getParent(), II->getParent());
2921+
auto *BI = BranchInst::Create(MergedInvoke->getParent(), II->getParent());
2922+
// The unconditional branch is part of the replacement for the original
2923+
// invoke, so should use its DebugLoc.
2924+
BI->setDebugLoc(II->getDebugLoc());
29222925
bool Success = MergedInvoke->tryIntersectAttributes(II);
29232926
assert(Success && "Merged invokes with incompatible attributes");
29242927
// For NDEBUG Compile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -p="simplifycfg<sink-common-insts>" -S | FileCheck %s
3+
4+
;; Tests that when we merge the invokes and use a select to choose the argument
5+
;; value, the merged invoke and select use the merged DILocation from the
6+
;; original invokes.
7+
8+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
9+
target triple = "x86_64-unknown-linux-gnu"
10+
11+
declare ptr @baz()
12+
13+
define i32 @foo(i1 %call66, ptr %.str.8) personality ptr null {
14+
; CHECK-LABEL: define i32 @foo(
15+
; CHECK-SAME: i1 [[CALL66:%.*]], ptr [[DOTSTR_8:%.*]]) personality ptr null {
16+
; CHECK-NEXT: [[ENTRY:.*:]]
17+
; CHECK-NEXT: [[CALL661:%.*]] = invoke i1 @bar(ptr null)
18+
; CHECK-NEXT: to label %[[INVOKE_CONT65:.*]] unwind label %[[LPAD45_LOOPEXIT_SPLIT_LP_LOOPEXIT_SPLIT_LP:.*]]
19+
; CHECK: [[COMMON_RET:.*]]:
20+
; CHECK-NEXT: ret i32 0
21+
; CHECK: [[LPAD45_LOOPEXIT_SPLIT_LP_LOOPEXIT_SPLIT_LP]]:
22+
; CHECK-NEXT: [[LPAD_LOOPEXIT_SPLIT_LP1114:%.*]] = landingpad { ptr, i32 }
23+
; CHECK-NEXT: cleanup
24+
; CHECK-NEXT: br label %[[COMMON_RET]]
25+
; CHECK: [[INVOKE_CONT65]]:
26+
; CHECK-NEXT: [[DOTSTR_8_:%.*]] = select i1 [[CALL66]], ptr [[DOTSTR_8]], ptr null, !dbg [[DBG3:![0-9]+]]
27+
; CHECK-NEXT: [[TMP0:%.*]] = invoke ptr @baz(ptr null, ptr [[DOTSTR_8_]])
28+
; CHECK-NEXT: to label %[[COMMON_RET]] unwind label %[[LPAD45_LOOPEXIT_SPLIT_LP_LOOPEXIT_SPLIT_LP]], !dbg [[DBG3]]
29+
;
30+
entry:
31+
%call661 = invoke i1 @bar(ptr null)
32+
to label %invoke.cont65 unwind label %lpad45.loopexit.split-lp.loopexit.split-lp
33+
34+
common.ret: ; preds = %if.else, %if.then67, %lpad45.loopexit.split-lp.loopexit.split-lp
35+
ret i32 0
36+
37+
lpad45.loopexit.split-lp.loopexit.split-lp: ; preds = %if.else, %if.then67, %entry
38+
%lpad.loopexit.split-lp1114 = landingpad { ptr, i32 }
39+
cleanup
40+
br label %common.ret
41+
42+
invoke.cont65: ; preds = %entry
43+
br i1 %call66, label %if.then67, label %if.else
44+
45+
if.then67: ; preds = %invoke.cont65
46+
%call69 = invoke ptr @baz(ptr null, ptr %.str.8)
47+
to label %common.ret unwind label %lpad45.loopexit.split-lp.loopexit.split-lp, !dbg !4
48+
49+
if.else: ; preds = %invoke.cont65
50+
%call71 = invoke ptr @baz(ptr null, ptr null)
51+
to label %common.ret unwind label %lpad45.loopexit.split-lp.loopexit.split-lp, !dbg !8
52+
}
53+
54+
declare i1 @bar()
55+
56+
!llvm.dbg.cu = !{!0}
57+
!llvm.module.flags = !{!3}
58+
59+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git")
60+
!1 = !DIFile(filename: "List.cpp", directory: "/tmp")
61+
!2 = !{}
62+
!3 = !{i32 2, !"Debug Info Version", i32 3}
63+
!4 = !DILocation(line: 10, column: 20, scope: !6)
64+
!6 = distinct !DISubprogram(name: "ListArchives", linkageName: "foo", scope: !1, file: !1, line: 416, type: !7, scopeLine: 425, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
65+
!7 = distinct !DISubroutineType(types: !2)
66+
!8 = !DILocation(line: 10, column: 10, scope: !6)
67+
;.
68+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
69+
; CHECK: [[META1]] = !DIFile(filename: "List.cpp", directory: {{.*}})
70+
; CHECK: [[DBG3]] = !DILocation(line: 10, scope: [[META4:![0-9]+]])
71+
; CHECK: [[META4]] = distinct !DISubprogram(name: "ListArchives", linkageName: "foo", scope: [[META1]], file: [[META1]], line: 416, type: [[META5:![0-9]+]], scopeLine: 425, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META6:![0-9]+]])
72+
; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6]])
73+
; CHECK: [[META6]] = !{}
74+
;.

0 commit comments

Comments
 (0)
Please sign in to comment.