Skip to content

Commit 8f9d156

Browse files
authored
[DebugInfo][SeparateConstOffsetFromGEP] Fix missing debug location updates (#96849)
Fix #96841 .
1 parent d03e812 commit 8f9d156

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ bool SeparateConstOffsetFromGEP::reuniteExts(Instruction *I) {
12381238
new SExtInst(Dom, I->getType(), "", I->getIterator());
12391239
NewSExt->takeName(I);
12401240
I->replaceAllUsesWith(NewSExt);
1241+
NewSExt->setDebugLoc(I->getDebugLoc());
12411242
RecursivelyDeleteTriviallyDeadInstructions(I);
12421243
return true;
12431244
}
@@ -1250,6 +1251,7 @@ bool SeparateConstOffsetFromGEP::reuniteExts(Instruction *I) {
12501251
new SExtInst(Dom, I->getType(), "", I->getIterator());
12511252
NewSExt->takeName(I);
12521253
I->replaceAllUsesWith(NewSExt);
1254+
NewSExt->setDebugLoc(I->getDebugLoc());
12531255
RecursivelyDeleteTriviallyDeadInstructions(I);
12541256
return true;
12551257
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; RUN: opt -S -passes=separate-const-offset-from-gep < %s | FileCheck %s
2+
3+
; Check that SeparateConstOffsetFromGEP's reuniteExts() propagates the debug location
4+
; to the new sext instruction, which replaces the old add/sub instruction (`%add.sext`/`%sub.sext`).
5+
6+
define i64 @add_sext__dominating_add_nsw(i32 %arg0, i32 %arg1) !dbg !5 {
7+
; CHECK-LABEL: define i64 @add_sext__dominating_add_nsw(
8+
; CHECK: entry:
9+
; CHECK: [[ADD_SEXT:%.*]] = sext i32 [[ADD_NSW:%.*]] to i64, !dbg [[DBG9:![0-9]+]]
10+
;
11+
entry:
12+
%add.nsw = add nsw i32 %arg0, %arg1, !dbg !8
13+
%arg0.sext = sext i32 %arg0 to i64, !dbg !9
14+
%arg1.sext = sext i32 %arg1 to i64, !dbg !10
15+
%add.sext = add i64 %arg0.sext, %arg1.sext, !dbg !11
16+
call void @use.i32(i32 %add.nsw), !dbg !12
17+
ret i64 %add.sext, !dbg !13
18+
}
19+
20+
define i64 @sub_sext__dominating_sub_nsw(i32 %arg0, i32 %arg1) !dbg !14 {
21+
; CHECK-LABEL: define i64 @sub_sext__dominating_sub_nsw(
22+
; CHECK: entry:
23+
; CHECK: [[SUB_SEXT:%.*]] = sext i32 [[SUB_NSW:%.*]] to i64, !dbg [[DBG14:![0-9]+]]
24+
25+
;
26+
entry:
27+
%sub.nsw = sub nsw i32 %arg0, %arg1, !dbg !15
28+
%arg0.sext = sext i32 %arg0 to i64, !dbg !16
29+
%arg1.sext = sext i32 %arg1 to i64, !dbg !17
30+
%sub.sext = sub i64 %arg0.sext, %arg1.sext, !dbg !18
31+
call void @use.i32(i32 %sub.nsw), !dbg !19
32+
ret i64 %sub.sext, !dbg !20
33+
}
34+
35+
declare void @use.i32(i32 noundef)
36+
37+
!llvm.dbg.cu = !{!0}
38+
!llvm.debugify = !{!2, !3}
39+
!llvm.module.flags = !{!4}
40+
41+
; CHECK: [[DBG9]] = !DILocation(line: 4,
42+
; CHECK: [[DBG14]] = !DILocation(line: 10,
43+
44+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
45+
!1 = !DIFile(filename: "test.ll", directory: "/")
46+
!2 = !{i32 12}
47+
!3 = !{i32 0}
48+
!4 = !{i32 2, !"Debug Info Version", i32 3}
49+
!5 = distinct !DISubprogram(name: "add_sext__dominating_add_nsw", linkageName: "add_sext__dominating_add_nsw", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
50+
!6 = !DISubroutineType(types: !7)
51+
!7 = !{}
52+
!8 = !DILocation(line: 1, column: 1, scope: !5)
53+
!9 = !DILocation(line: 2, column: 1, scope: !5)
54+
!10 = !DILocation(line: 3, column: 1, scope: !5)
55+
!11 = !DILocation(line: 4, column: 1, scope: !5)
56+
!12 = !DILocation(line: 5, column: 1, scope: !5)
57+
!13 = !DILocation(line: 6, column: 1, scope: !5)
58+
!14 = distinct !DISubprogram(name: "sub_sext__dominating_sub_nsw", linkageName: "sub_sext__dominating_sub_nsw", scope: null, file: !1, line: 7, type: !6, scopeLine: 7, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
59+
!15 = !DILocation(line: 7, column: 1, scope: !14)
60+
!16 = !DILocation(line: 8, column: 1, scope: !14)
61+
!17 = !DILocation(line: 9, column: 1, scope: !14)
62+
!18 = !DILocation(line: 10, column: 1, scope: !14)
63+
!19 = !DILocation(line: 11, column: 1, scope: !14)
64+
!20 = !DILocation(line: 12, column: 1, scope: !14)

0 commit comments

Comments
 (0)