[llvm] [DebugInfo][SeparateConstOffsetFromGEP] Fix missing debug location updates (PR #96849)
Shan Huang via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 21:55:58 PDT 2024
https://github.com/Apochens updated https://github.com/llvm/llvm-project/pull/96849
>From 399111e49a7698a86d1d2bfebcffad901500d508 Mon Sep 17 00:00:00 2001
From: Apochens <52285902006 at stu.ecnu.edu.cn>
Date: Thu, 27 Jun 2024 04:45:12 +0000
Subject: [PATCH 1/2] fix missing debug location updates
---
.../Scalar/SeparateConstOffsetFromGEP.cpp | 2 +
.../preserving_debugloc_sext.ll | 61 +++++++++++++++++++
2 files changed, 63 insertions(+)
create mode 100644 llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index 4e515e05c842a..5488a12011fe0 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -1238,6 +1238,7 @@ bool SeparateConstOffsetFromGEP::reuniteExts(Instruction *I) {
new SExtInst(Dom, I->getType(), "", I->getIterator());
NewSExt->takeName(I);
I->replaceAllUsesWith(NewSExt);
+ NewSExt->setDebugLoc(I->getDebugLoc());
RecursivelyDeleteTriviallyDeadInstructions(I);
return true;
}
@@ -1250,6 +1251,7 @@ bool SeparateConstOffsetFromGEP::reuniteExts(Instruction *I) {
new SExtInst(Dom, I->getType(), "", I->getIterator());
NewSExt->takeName(I);
I->replaceAllUsesWith(NewSExt);
+ NewSExt->setDebugLoc(I->getDebugLoc());
RecursivelyDeleteTriviallyDeadInstructions(I);
return true;
}
diff --git a/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll b/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll
new file mode 100644
index 0000000000000..d6d3fbed6624b
--- /dev/null
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll
@@ -0,0 +1,61 @@
+; RUN: opt -S -passes=separate-const-offset-from-gep < %s | FileCheck %s
+
+define i64 @add_sext__dominating_add_nsw(i32 %arg0, i32 %arg1) !dbg !5 {
+; CHECK-LABEL: define i64 @add_sext__dominating_add_nsw(
+; CHECK: entry:
+; CHECK: [[ADD_SEXT:%.*]] = sext i32 [[ADD_NSW:%.*]] to i64, !dbg [[DBG9:![0-9]+]]
+;
+entry:
+ %add.nsw = add nsw i32 %arg0, %arg1, !dbg !8
+ %arg0.sext = sext i32 %arg0 to i64, !dbg !9
+ %arg1.sext = sext i32 %arg1 to i64, !dbg !10
+ %add.sext = add i64 %arg0.sext, %arg1.sext, !dbg !11
+ call void @use.i32(i32 %add.nsw), !dbg !12
+ ret i64 %add.sext, !dbg !13
+}
+
+define i64 @sub_sext__dominating_sub_nsw(i32 %arg0, i32 %arg1) !dbg !14 {
+; CHECK-LABEL: define i64 @sub_sext__dominating_sub_nsw(
+; CHECK: entry:
+; CHECK: [[SUB_SEXT:%.*]] = sext i32 [[SUB_NSW:%.*]] to i64, !dbg [[DBG14:![0-9]+]]
+
+;
+entry:
+ %sub.nsw = sub nsw i32 %arg0, %arg1, !dbg !15
+ %arg0.sext = sext i32 %arg0 to i64, !dbg !16
+ %arg1.sext = sext i32 %arg1 to i64, !dbg !17
+ %sub.sext = sub i64 %arg0.sext, %arg1.sext, !dbg !18
+ call void @use.i32(i32 %sub.nsw), !dbg !19
+ ret i64 %sub.sext, !dbg !20
+}
+
+declare void @use.i32(i32 noundef)
+
+!llvm.dbg.cu = !{!0}
+!llvm.debugify = !{!2, !3}
+!llvm.module.flags = !{!4}
+
+; CHECK: [[DBG9]] = !DILocation(line: 4,
+; CHECK: [[DBG14]] = !DILocation(line: 10,
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "test.ll", directory: "/")
+!2 = !{i32 12}
+!3 = !{i32 0}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!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)
+!6 = !DISubroutineType(types: !7)
+!7 = !{}
+!8 = !DILocation(line: 1, column: 1, scope: !5)
+!9 = !DILocation(line: 2, column: 1, scope: !5)
+!10 = !DILocation(line: 3, column: 1, scope: !5)
+!11 = !DILocation(line: 4, column: 1, scope: !5)
+!12 = !DILocation(line: 5, column: 1, scope: !5)
+!13 = !DILocation(line: 6, column: 1, scope: !5)
+!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)
+!15 = !DILocation(line: 7, column: 1, scope: !14)
+!16 = !DILocation(line: 8, column: 1, scope: !14)
+!17 = !DILocation(line: 9, column: 1, scope: !14)
+!18 = !DILocation(line: 10, column: 1, scope: !14)
+!19 = !DILocation(line: 11, column: 1, scope: !14)
+!20 = !DILocation(line: 12, column: 1, scope: !14)
>From 6bb0877085c0da79a4cc86de3082a156748a9f9e Mon Sep 17 00:00:00 2001
From: Apochens <52285902006 at stu.ecnu.edu.cn>
Date: Thu, 27 Jun 2024 04:55:46 +0000
Subject: [PATCH 2/2] add the test comment
---
.../SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll b/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll
index d6d3fbed6624b..040d6ae2b4628 100644
--- a/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll
@@ -1,5 +1,8 @@
; RUN: opt -S -passes=separate-const-offset-from-gep < %s | FileCheck %s
+; Check that SeparateConstOffsetFromGEP's reuniteExts() propagates the debug location
+; to the new sext instruction, which replaces the old add/sub instruction (`%add.sext`/`%sub.sext`).
+
define i64 @add_sext__dominating_add_nsw(i32 %arg0, i32 %arg1) !dbg !5 {
; CHECK-LABEL: define i64 @add_sext__dominating_add_nsw(
; CHECK: entry:
More information about the llvm-commits
mailing list