[llvm] 8f9d156 - [DebugInfo][SeparateConstOffsetFromGEP] Fix missing debug location updates (#96849)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 30 23:03:28 PDT 2024


Author: Shan Huang
Date: 2024-07-01T14:03:25+08:00
New Revision: 8f9d156ded93c8e8396ad36b433938bfc7883bc4

URL: https://github.com/llvm/llvm-project/commit/8f9d156ded93c8e8396ad36b433938bfc7883bc4
DIFF: https://github.com/llvm/llvm-project/commit/8f9d156ded93c8e8396ad36b433938bfc7883bc4.diff

LOG: [DebugInfo][SeparateConstOffsetFromGEP] Fix missing debug location updates (#96849)

Fix #96841 .

Added: 
    llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll

Modified: 
    llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index 111157b5b326f..73e3ff296cf11 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..040d6ae2b4628
--- /dev/null
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/preserving_debugloc_sext.ll
@@ -0,0 +1,64 @@
+; 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:
+; 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)


        


More information about the llvm-commits mailing list