Skip to content

Commit 4e4a75d

Browse files
committed
Propagate DebugLocs on phis in BreakCriticalEdges
1 parent 1f03a5d commit 4e4a75d

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,16 @@ bool llvm::SplitIndirectBrCriticalEdges(Function &F,
445445
PHINode *NewIndPHI = PHINode::Create(IndPHI->getType(), 1, "ind", InsertPt);
446446
NewIndPHI->addIncoming(IndPHI->getIncomingValueForBlock(IBRPred),
447447
IBRPred);
448+
NewIndPHI->setDebugLoc(IndPHI->getDebugLoc());
448449

449450
// Create a PHI in the body block, to merge the direct and indirect
450451
// predecessors.
451452
PHINode *MergePHI = PHINode::Create(IndPHI->getType(), 2, "merge");
452453
MergePHI->insertBefore(MergeInsert);
453454
MergePHI->addIncoming(NewIndPHI, Target);
454455
MergePHI->addIncoming(DirPHI, DirectSucc);
456+
MergePHI->applyMergedLocation(DirPHI->getDebugLoc(),
457+
IndPHI->getDebugLoc());
455458

456459
IndPHI->replaceAllUsesWith(MergePHI);
457460
IndPHI->eraseFromParent();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; RUN: opt -passes='require<profile-summary>,function(codegenprepare)' -S -mtriple=x86_64 < %s \
2+
; RUN: | FileCheck %s
3+
4+
;; Check debug locations are propagated onto new PHIs.
5+
6+
; CHECK: .split:
7+
; CHECK-NEXT: %merge = phi i32 [ poison, %while.body ], [ %dest.sroa.clone, %while.body.clone ], !dbg [[DBG:!.*]]
8+
9+
; CHECK: while.body.clone:
10+
; CHECK-NEXT: %dest.sroa.clone = phi i32 [ %1, %.split ], [ poison, %if.else ], !dbg [[DBG]]
11+
12+
define void @test(i1 %c) !dbg !5 {
13+
entry:
14+
br label %if.else
15+
16+
if.else: ; preds = %if.else1, %entry
17+
br i1 %c, label %while.body, label %preheader
18+
19+
preheader: ; preds = %if.else
20+
br label %if.else1
21+
22+
if.then: ; preds = %if.else1
23+
unreachable
24+
25+
while.body: ; preds = %if.else1, %while.body, %if.else
26+
%dest.sroa = phi i32 [ %1, %while.body ], [ poison, %if.else1 ], [ poison, %if.else ], !dbg !8
27+
%0 = inttoptr i32 %dest.sroa to ptr
28+
%incdec.ptr = getelementptr inbounds i8, ptr %0, i32 -1
29+
%1 = ptrtoint ptr %incdec.ptr to i32
30+
store i8 0, ptr %incdec.ptr, align 1
31+
br label %while.body
32+
33+
if.else1: ; preds = %if.else1, %preheader
34+
indirectbr ptr poison, [label %if.then, label %while.body, label %if.else, label %if.else1]
35+
}
36+
37+
!llvm.dbg.cu = !{!0}
38+
!llvm.debugify = !{!2, !3}
39+
!llvm.module.flags = !{!4}
40+
41+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
42+
!1 = !DIFile(filename: "test.ll", directory: "/")
43+
!2 = !{i32 11}
44+
!3 = !{i32 0}
45+
!4 = !{i32 2, !"Debug Info Version", i32 3}
46+
!5 = distinct !DISubprogram(name: "test", linkageName: "test", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
47+
!6 = !DISubroutineType(types: !7)
48+
!7 = !{}
49+
!8 = !DILocation(line: 1, column: 1, scope: !5)

0 commit comments

Comments
 (0)