Skip to content

Commit 218f71d

Browse files
authored
[DebugInfo][LowerConstantIntrinsics] Fix the missing debug location of new branch instruction (#97145)
Fix #97142 .
1 parent 3cab132 commit 218f71d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ static bool replaceConditionalBranchesOnConstant(Instruction *II,
8585
if (Target && Target != Other) {
8686
BasicBlock *Source = BI->getParent();
8787
Other->removePredecessor(Source);
88+
89+
Instruction *NewBI = BranchInst::Create(Target, Source);
90+
NewBI->setDebugLoc(BI->getDebugLoc());
8891
BI->eraseFromParent();
89-
BranchInst::Create(Target, Source);
92+
9093
if (DTU)
9194
DTU->applyUpdates({{DominatorTree::Delete, Source, Other}});
9295
if (pred_empty(Other))
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: opt -S -passes=lower-constant-intrinsics < %s | FileCheck %s
2+
3+
; Check that LowerConstantIntrinsics's replaceConditionalBranchesOnConstant() correctly
4+
; propagates the debug location from the old br instruction to the new one.
5+
6+
; Function Attrs: nounwind
7+
define i32 @test_branch(i32 %in) !dbg !5 {
8+
; CHECK-LABEL: define i32 @test_branch(
9+
; CHECK: br label %[[FALSE:.*]], !dbg [[DBG8:![0-9]+]]
10+
; CHECK: [[FALSE]]:
11+
;
12+
%v = call i1 @llvm.is.constant.i32(i32 %in), !dbg !8
13+
br i1 %v, label %True, label %False, !dbg !9
14+
15+
True: ; preds = %0
16+
%call1 = tail call i32 @subfun_1(), !dbg !10
17+
ret i32 %call1, !dbg !11
18+
19+
False: ; preds = %0
20+
%call2 = tail call i32 @subfun_2(), !dbg !12
21+
ret i32 %call2, !dbg !13
22+
}
23+
24+
declare i32 @subfun_1()
25+
declare i32 @subfun_2()
26+
27+
declare i1 @llvm.is.constant.i32(i32)
28+
29+
!llvm.dbg.cu = !{!0}
30+
!llvm.debugify = !{!2, !3}
31+
!llvm.module.flags = !{!4}
32+
33+
; CHECK: [[DBG8]] = !DILocation(line: 2,
34+
35+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
36+
!1 = !DIFile(filename: "main.ll", directory: "/")
37+
!2 = !{i32 6}
38+
!3 = !{i32 0}
39+
!4 = !{i32 2, !"Debug Info Version", i32 3}
40+
!5 = distinct !DISubprogram(name: "test_branch", linkageName: "test_branch", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
41+
!6 = !DISubroutineType(types: !7)
42+
!7 = !{}
43+
!8 = !DILocation(line: 1, column: 1, scope: !5)
44+
!9 = !DILocation(line: 2, column: 1, scope: !5)
45+
!10 = !DILocation(line: 3, column: 1, scope: !5)
46+
!11 = !DILocation(line: 4, column: 1, scope: !5)
47+
!12 = !DILocation(line: 5, column: 1, scope: !5)
48+
!13 = !DILocation(line: 6, column: 1, scope: !5)

0 commit comments

Comments
 (0)