Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit c9ed111

Browse files
taewookohadrian-prantl
authored andcommitted
[TailDuplicator] Maintain DebugLoc for branch instructions
Summary: Existing implementation of duplicateSimpleBB function drops DebugLoc metadata of branch instructions during the transformation. This patch addresses this issue by making newly created branch instructions to keep the metadata of replaced branch instructions. Reviewers: qcolombet, craig.topper, aprantl, MatzeB, sanjoy, dblaikie Reviewed By: dblaikie Subscribers: dblaikie, llvm-commits Differential Revision: https://reviews.llvm.org/D30026 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296371 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 6a73128)
1 parent a4c98c3 commit c9ed111

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

lib/CodeGen/TailDuplicator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ bool TailDuplicator::duplicateSimpleBB(
725725
if (PredTBB == NextBB && PredFBB == nullptr)
726726
PredTBB = nullptr;
727727

728+
auto DL = PredBB->findBranchDebugLoc();
728729
TII->removeBranch(*PredBB);
729730

730731
if (!PredBB->isSuccessor(NewTarget))
@@ -735,7 +736,7 @@ bool TailDuplicator::duplicateSimpleBB(
735736
}
736737

737738
if (PredTBB)
738-
TII->insertBranch(*PredBB, PredTBB, PredFBB, PredCond, DebugLoc());
739+
TII->insertBranch(*PredBB, PredTBB, PredFBB, PredCond, DL);
739740

740741
TDBBs.push_back(PredBB);
741742
}

test/CodeGen/X86/tail-dup-debugloc.ll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; RUN: llc -stop-after=tailduplication -march=x86-64 < %s | FileCheck %s
2+
;
3+
; Check that DebugLoc attached to the branch instruction of
4+
; 'while.cond1.preheader.lr.ph' survives after tailduplication pass.
5+
;
6+
; CHECK: [[DLOC:![0-9]+]] = !DILocation(line: 9, column: 5, scope: !{{[0-9]+}})
7+
; CHECK: [[VREG:%[^ ]+]] = COPY %rdi
8+
; CHECK: TEST64rr [[VREG]], [[VREG]]
9+
; CHECK-NEXT: JE_1 {{.+}}, debug-location [[DLOC]]
10+
; CHECK-NEXT: JMP_1 {{.+}}, debug-location [[DLOC]]
11+
12+
target triple = "x86_64-unknown-linux-gnu"
13+
14+
%struct.Node = type { %struct.Node* }
15+
16+
define i32 @foo(%struct.Node* readonly %node, %struct.Node* readnone %root) !dbg !6 {
17+
entry:
18+
%cmp = icmp eq %struct.Node* %node, %root, !dbg !8
19+
br i1 %cmp, label %while.end4, label %while.cond1.preheader.lr.ph, !dbg !10
20+
21+
while.cond1.preheader.lr.ph: ; preds = %entry
22+
%tobool = icmp eq %struct.Node* %node, null
23+
br i1 %tobool, label %while.cond1.preheader.us.preheader, label %while.body2.preheader, !dbg !11
24+
25+
while.body2.preheader: ; preds = %while.cond1.preheader.lr.ph
26+
br label %while.body2, !dbg !11
27+
28+
while.cond1.preheader.us.preheader: ; preds = %while.cond1.preheader.lr.ph
29+
br label %while.cond1.preheader.us, !dbg !10
30+
31+
while.cond1.preheader.us: ; preds = %while.cond1.preheader.us.preheader, %while.cond1.preheader.us
32+
br label %while.cond1.preheader.us, !dbg !10
33+
34+
while.body2: ; preds = %while.body2.preheader, %while.body2
35+
br label %while.body2, !dbg !11
36+
37+
while.end4: ; preds = %entry
38+
ret i32 0, !dbg !12
39+
}
40+
41+
!llvm.dbg.cu = !{!0}
42+
!llvm.module.flags = !{!3, !4}
43+
44+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, emissionKind: LineTablesOnly)
45+
!1 = !DIFile(filename: "foo.c", directory: "b/")
46+
!2 = !{}
47+
!3 = !{i32 2, !"Dwarf Version", i32 4}
48+
!4 = !{i32 2, !"Debug Info Version", i32 3}
49+
!5 = !{}
50+
!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !7, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
51+
!7 = !DISubroutineType(types: !2)
52+
!8 = !DILocation(line: 7, column: 15, scope: !9)
53+
!9 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 2)
54+
!10 = !DILocation(line: 7, column: 3, scope: !9)
55+
!11 = !DILocation(line: 9, column: 5, scope: !9)
56+
!12 = !DILocation(line: 14, column: 3, scope: !6)

0 commit comments

Comments
 (0)