Skip to content

Commit 60d0bc1

Browse files
authored
Propagate DebugLocs on phis in BreakCriticalEdges (#133492)
The pull request discusses whether this change is needed or not. We leant towards "it can't hurt" on the basis that it's at worst slightly unecessary (but not incorret). The motivation for the patch came from reviewing code duplication sites to update for Key Instructions, finding this, trying to generate a test case and seeing the DebugLocs aren't propagated.
1 parent 4132141 commit 60d0bc1

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,16 @@ bool llvm::SplitIndirectBrCriticalEdges(Function &F,
454454
PHINode *NewIndPHI = PHINode::Create(IndPHI->getType(), 1, "ind", InsertPt);
455455
NewIndPHI->addIncoming(IndPHI->getIncomingValueForBlock(IBRPred),
456456
IBRPred);
457+
NewIndPHI->setDebugLoc(IndPHI->getDebugLoc());
457458

458459
// Create a PHI in the body block, to merge the direct and indirect
459460
// predecessors.
460461
PHINode *MergePHI = PHINode::Create(IndPHI->getType(), 2, "merge");
461462
MergePHI->insertBefore(MergeInsert);
462463
MergePHI->addIncoming(NewIndPHI, Target);
463464
MergePHI->addIncoming(DirPHI, DirectSucc);
465+
MergePHI->applyMergedLocation(DirPHI->getDebugLoc(),
466+
IndPHI->getDebugLoc());
464467

465468
IndPHI->replaceAllUsesWith(MergePHI);
466469
IndPHI->eraseFromParent();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
; CHECK: [[DBG]] = !DILocation(line: 1, column: 1, scope: ![[#]])
13+
14+
define void @test(i1 %c) !dbg !5 {
15+
entry:
16+
br label %if.else
17+
18+
if.else: ; preds = %if.else1, %entry
19+
br i1 %c, label %while.body, label %preheader
20+
21+
preheader: ; preds = %if.else
22+
br label %if.else1
23+
24+
if.then: ; preds = %if.else1
25+
unreachable
26+
27+
while.body: ; preds = %if.else1, %while.body, %if.else
28+
%dest.sroa = phi i32 [ %1, %while.body ], [ poison, %if.else1 ], [ poison, %if.else ], !dbg !8
29+
%0 = inttoptr i32 %dest.sroa to ptr
30+
%incdec.ptr = getelementptr inbounds i8, ptr %0, i32 -1
31+
%1 = ptrtoint ptr %incdec.ptr to i32
32+
store i8 0, ptr %incdec.ptr, align 1
33+
br label %while.body
34+
35+
if.else1: ; preds = %if.else1, %preheader
36+
indirectbr ptr poison, [label %if.then, label %while.body, label %if.else, label %if.else1]
37+
}
38+
39+
!llvm.dbg.cu = !{!0}
40+
!llvm.debugify = !{!2, !3}
41+
!llvm.module.flags = !{!4}
42+
43+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
44+
!1 = !DIFile(filename: "test.ll", directory: "/")
45+
!2 = !{i32 11}
46+
!3 = !{i32 0}
47+
!4 = !{i32 2, !"Debug Info Version", i32 3}
48+
!5 = distinct !DISubprogram(name: "test", linkageName: "test", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
49+
!6 = !DISubroutineType(types: !7)
50+
!7 = !{}
51+
!8 = !DILocation(line: 1, column: 1, scope: !5)

0 commit comments

Comments
 (0)