Skip to content

Commit 37661a1

Browse files
authored
[DebugInfo][JumpThreading] Fix missing debug location updates for br instructions (#96889)
Fix #96885 .
1 parent 651e916 commit 37661a1

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,8 @@ bool JumpThreadingPass::processBlock(BasicBlock *BB) {
10381038

10391039
LLVM_DEBUG(dbgs() << " In block '" << BB->getName()
10401040
<< "' folding undef terminator: " << *BBTerm << '\n');
1041-
BranchInst::Create(BBTerm->getSuccessor(BestSucc), BBTerm->getIterator());
1041+
Instruction *NewBI = BranchInst::Create(BBTerm->getSuccessor(BestSucc), BBTerm->getIterator());
1042+
NewBI->setDebugLoc(BBTerm->getDebugLoc());
10421043
++NumFolds;
10431044
BBTerm->eraseFromParent();
10441045
DTU->applyUpdatesPermissive(Updates);
@@ -1657,7 +1658,8 @@ bool JumpThreadingPass::processThreadableEdges(Value *Cond, BasicBlock *BB,
16571658

16581659
// Finally update the terminator.
16591660
Instruction *Term = BB->getTerminator();
1660-
BranchInst::Create(OnlyDest, Term->getIterator());
1661+
Instruction *NewBI = BranchInst::Create(OnlyDest, Term->getIterator());
1662+
NewBI->setDebugLoc(Term->getDebugLoc());
16611663
++NumFolds;
16621664
Term->eraseFromParent();
16631665
DTU->applyUpdatesPermissive(Updates);
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
; RUN: opt -S -passes=jump-threading < %s | FileCheck %s
2+
3+
; @process_block_branch checks that JumpThreading's processBlock() propagates
4+
; the debug location to the new branch instruction.
5+
6+
; @process_threadable_edges_branch checks that JumpThreading's processThreadableEdges()
7+
; propagates the debug location to the new branch instruction.
8+
9+
define i32 @process_block_branch(i32 %action) #0 !dbg !5 {
10+
; CHECK-LABEL: define i32 @process_block_branch(
11+
; CHECK: for.cond:
12+
; CHECK-NEXT: br label %for.cond, !dbg [[DBG10:![0-9]+]]
13+
;
14+
entry:
15+
switch i32 %action, label %lor.rhs [
16+
i32 1, label %if.then
17+
i32 0, label %lor.end
18+
], !dbg !8
19+
20+
if.then: ; preds = %for.cond, %lor.end, %entry
21+
ret i32 undef, !dbg !9
22+
23+
lor.rhs: ; preds = %entry
24+
br label %lor.end, !dbg !10
25+
26+
lor.end: ; preds = %lor.rhs, %entry
27+
%cmp103 = xor i1 undef, undef, !dbg !11
28+
br i1 %cmp103, label %for.cond, label %if.then, !dbg !12
29+
30+
for.cond: ; preds = %for.body, %lor.end
31+
br i1 undef, label %if.then, label %for.body, !dbg !13
32+
33+
for.body: ; preds = %for.cond
34+
br label %for.cond, !dbg !14
35+
}
36+
37+
define void @process_threadable_edges_branch(i32 %value) #0 !dbg !15 {
38+
; CHECK-LABEL: define void @process_threadable_edges_branch(
39+
; CHECK: L0:
40+
; CHECK: br label %L2, !dbg [[DBG17:![0-9]+]]
41+
;
42+
entry:
43+
%cmp = icmp eq i32 %value, 32, !dbg !16
44+
%add = add i32 %value, 64, !dbg !17
45+
br i1 %cmp, label %L0, label %L2, !dbg !18
46+
47+
L0: ; preds = %entry
48+
%0 = call i32 @f2(), !dbg !19
49+
%1 = call i32 @f2(), !dbg !20
50+
switch i32 %add, label %L3 [
51+
i32 32, label %L1
52+
i32 96, label %L2
53+
], !dbg !21
54+
55+
L1: ; preds = %L0
56+
call void @f3(), !dbg !22
57+
ret void, !dbg !23
58+
59+
L2: ; preds = %L0, %entry
60+
call void @f4(i32 %add), !dbg !24
61+
ret void, !dbg !25
62+
63+
L3: ; preds = %L0
64+
call void @f3(), !dbg !26
65+
ret void, !dbg !27
66+
}
67+
68+
declare i32 @f1()
69+
70+
declare i32 @f2()
71+
72+
declare void @f3()
73+
74+
declare void @f4(i32)
75+
76+
attributes #0 = { nounwind }
77+
78+
!llvm.dbg.cu = !{!0}
79+
!llvm.debugify = !{!2, !3}
80+
!llvm.module.flags = !{!4}
81+
82+
;.
83+
; CHECK: [[DBG10]] = !DILocation(line: 6,
84+
; CHECK: [[DBG17]] = !DILocation(line: 13,
85+
;.
86+
87+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
88+
!1 = !DIFile(filename: "temp.ll", directory: "/")
89+
!2 = !{i32 30}
90+
!3 = !{i32 0}
91+
!4 = !{i32 2, !"Debug Info Version", i32 3}
92+
!5 = distinct !DISubprogram(name: "process_block_branch", linkageName: "process_block_branch", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
93+
!6 = !DISubroutineType(types: !7)
94+
!7 = !{}
95+
!8 = !DILocation(line: 1, column: 1, scope: !5)
96+
!9 = !DILocation(line: 2, column: 1, scope: !5)
97+
!10 = !DILocation(line: 3, column: 1, scope: !5)
98+
!11 = !DILocation(line: 4, column: 1, scope: !5)
99+
!12 = !DILocation(line: 5, column: 1, scope: !5)
100+
!13 = !DILocation(line: 6, column: 1, scope: !5)
101+
!14 = !DILocation(line: 7, column: 1, scope: !5)
102+
!15 = distinct !DISubprogram(name: "process_threadable_edges_branch", linkageName: "process_threadable_edges_branch", scope: null, file: !1, line: 8, type: !6, scopeLine: 8, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
103+
!16 = !DILocation(line: 8, column: 1, scope: !15)
104+
!17 = !DILocation(line: 9, column: 1, scope: !15)
105+
!18 = !DILocation(line: 10, column: 1, scope: !15)
106+
!19 = !DILocation(line: 11, column: 1, scope: !15)
107+
!20 = !DILocation(line: 12, column: 1, scope: !15)
108+
!21 = !DILocation(line: 13, column: 1, scope: !15)
109+
!22 = !DILocation(line: 14, column: 1, scope: !15)
110+
!23 = !DILocation(line: 15, column: 1, scope: !15)
111+
!24 = !DILocation(line: 16, column: 1, scope: !15)
112+
!25 = !DILocation(line: 17, column: 1, scope: !15)
113+
!26 = !DILocation(line: 18, column: 1, scope: !15)
114+
!27 = !DILocation(line: 19, column: 1, scope: !15)

0 commit comments

Comments
 (0)