[PATCH] D100371: [debug-info] SCCP should preserve the debug location for an one-to-one instruction replacement

Yuanbo Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 13 04:12:55 PDT 2021


yuanboli233 updated this revision to Diff 337099.
yuanboli233 added a comment.

Updated with the simplified test case suggested by @Orlando.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100371/new/

https://reviews.llvm.org/D100371

Files:
  llvm/lib/Transforms/Scalar/SCCP.cpp
  llvm/test/Transforms/SCCP/sccp_preserve_debugloc.ll


Index: llvm/test/Transforms/SCCP/sccp_preserve_debugloc.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/SCCP/sccp_preserve_debugloc.ll
@@ -0,0 +1,62 @@
+; RUN: opt -sccp -S < %s | FileCheck %s
+; COM: check whether the debug location is preserved
+; CHECK: %{{[a-zA-Z0-9_]*}} = zext i32 %tmp9 to i64, !dbg !{{[0-9]*}} 
+source_filename = "abc.ll"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @foo(i64* %arg) !dbg !6 {
+bb:
+  %tmp = zext i8 undef to i32, !dbg !8
+  %tmp1 = getelementptr inbounds i64, i64* %arg, i32 0, !dbg !9
+  %tmp2 = load i64, i64* %tmp1, align 8, !dbg !10
+  switch i32 %tmp, label %bb20 [
+    i32 1, label %bb3
+    i32 2, label %bb4
+    i32 4, label %bb19
+  ], !dbg !11
+
+bb3:                                              ; preds = %bb
+  unreachable, !dbg !12
+
+bb4:                                              ; preds = %bb
+  %tmp5 = add i64 %tmp2, 3, !dbg !13
+  %tmp6 = and i64 %tmp5, 3, !dbg !14
+  %tmp7 = sub i64 3, %tmp6, !dbg !15
+  %tmp8 = shl i64 %tmp7, 1, !dbg !16
+  %tmp9 = trunc i64 %tmp8 to i32, !dbg !17
+  %tmp10 = sext i32 %tmp9 to i64, !dbg !18
+  unreachable, !dbg !19
+
+bb19:                                             ; preds = %bb
+  unreachable, !dbg !20
+
+bb20:                                             ; preds = %bb
+  ret void, !dbg !21
+}
+
+!llvm.module.flags = !{!0}
+!llvm.dbg.cu = !{!1}
+!llvm.debugify = !{!4, !5}
+
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
+!2 = !DIFile(filename: "bugpoint-reduced-simplified.bc", directory: "/")
+!3 = !{}
+!4 = !{i32 14}
+!5 = !{i32 0}
+!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !2, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !3)
+!7 = !DISubroutineType(types: !3)
+!8 = !DILocation(line: 1, column: 1, scope: !6)
+!9 = !DILocation(line: 2, column: 1, scope: !6)
+!10 = !DILocation(line: 3, column: 1, scope: !6)
+!11 = !DILocation(line: 4, column: 1, scope: !6)
+!12 = !DILocation(line: 5, column: 1, scope: !6)
+!13 = !DILocation(line: 6, column: 1, scope: !6)
+!14 = !DILocation(line: 7, column: 1, scope: !6)
+!15 = !DILocation(line: 8, column: 1, scope: !6)
+!16 = !DILocation(line: 9, column: 1, scope: !6)
+!17 = !DILocation(line: 10, column: 1, scope: !6)
+!18 = !DILocation(line: 11, column: 1, scope: !6)
+!19 = !DILocation(line: 12, column: 1, scope: !6)
+!20 = !DILocation(line: 13, column: 1, scope: !6)
+!21 = !DILocation(line: 14, column: 1, scope: !6)
Index: llvm/lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SCCP.cpp
+++ llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -1693,6 +1693,7 @@
         continue;
       if (IV.getConstantRange().isAllNonNegative()) {
         auto *ZExt = new ZExtInst(ExtOp, Inst.getType(), "", &Inst);
+        ZExt->setDebugLoc(Inst.getDebugLoc());
         InsertedValues.insert(ZExt);
         Inst.replaceAllUsesWith(ZExt);
         Solver.removeLatticeValueFor(&Inst);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100371.337099.patch
Type: text/x-patch
Size: 3244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210413/6069f29f/attachment.bin>


More information about the llvm-commits mailing list