[llvm] [DebugInfo][SeparateConstOffsetFromGEP] Fix missing debug location updates (PR #96849)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 21:48:12 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Shan Huang (Apochens)

<details>
<summary>Changes</summary>

Fix #<!-- -->96841 .

---
Full diff: https://github.com/llvm/llvm-project/pull/96849.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (+2) 
- (added) llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll (+61) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/96849


More information about the llvm-commits mailing list