[PATCH] D71175: [DebugInfo][SelectionDAG] Change order while transferring SDDbgValue to another node

Kristina Bessonova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 8 05:46:28 PST 2019


krisb created this revision.
krisb added reviewers: dblaikie, jmorse.
Herald added subscribers: llvm-commits, hiraditya, aprantl.
Herald added a project: LLVM.
krisb edited the summary of this revision.
krisb added a project: debug-info.
krisb added a subscriber: avl.

transferDbgValues() can 'reattach' SDDbgValue from one to another node, but doesn't change its source order. If the destination node has the order greater than the SDDbgValue, there are two possible issues revealed on MIR:

- If debug info is attached to an instruction that is the first definition of a register, this ends up with a def-after-use case and the debug info gets 'undef' later.
- If MIR has another definition of the register above the debug info, debug info won't be 'undef' but may represent a source variable incorrectly because appears (significantly) before an instruction corresponded to this debug info.

So, in cases when the order of SDDbgValue becomes less than the order of a destination node during transferDbgValues() attached debug value,
the patch equalizes them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71175

Files:
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/test/DebugInfo/X86/sdag-transfer-dbgvalue.ll


Index: llvm/test/DebugInfo/X86/sdag-transfer-dbgvalue.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/sdag-transfer-dbgvalue.ll
@@ -0,0 +1,76 @@
+; RUN: llc -start-after=codegenprepare -stop-before finalize-isel -o - %s | FileCheck %s
+
+; This tests that transferDbgValues() changes order of d SDDbgValue transferred
+; to another node and debug info for 'ADD32ri' appear *after* the instruction.
+;
+; This test case was generated from the following program
+; using: clang -g -O3 -S -emit-llvm test.c
+;
+; int foo(int a, int *b) {
+;   int c = a + 512;
+;   if (c != 0)
+;     *b = a;
+;   return c;
+; }
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: bb.0.entry:
+; CHECK:       %[[REG:[0-9]+]]:gr32 = ADD32ri %1, 512
+; CHECK-NEXT:  DBG_VALUE %[[REG]]
+
+; Function Attrs: nofree norecurse nounwind uwtable writeonly
+define dso_local i32 @foo(i32 %a, i32* nocapture %b) local_unnamed_addr !dbg !7 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %a, metadata !14, metadata !DIExpression()), !dbg !17
+  call void @llvm.dbg.value(metadata i32* %b, metadata !15, metadata !DIExpression()), !dbg !17
+  %add = add nsw i32 %a, 512, !dbg !18
+  call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !17
+  %cmp = icmp eq i32 %add, 0, !dbg !19
+  br i1 %cmp, label %if.end, label %if.then, !dbg !21
+
+if.then:                                          ; preds = %entry
+  store i32 %a, i32* %b, align 4, !dbg !22, !tbaa !23
+  br label %if.end, !dbg !27
+
+if.end:                                           ; preds = %entry, %if.then
+  ret i32 %add, !dbg !28
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 10.0.0"}
+!7 = distinct !DISubprogram(name: "foo", scope: !8, file: !8, line: 1, type: !9, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
+!8 = !DIFile(filename: "test.c", directory: "/")
+!9 = !DISubroutineType(types: !10)
+!10 = !{!11, !11, !12}
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!13 = !{!14, !15, !16}
+!14 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !8, line: 1, type: !11)
+!15 = !DILocalVariable(name: "b", arg: 2, scope: !7, file: !8, line: 1, type: !12)
+!16 = !DILocalVariable(name: "c", scope: !7, file: !8, line: 2, type: !11)
+!17 = !DILocation(line: 0, scope: !7)
+!18 = !DILocation(line: 2, column: 13, scope: !7)
+!19 = !DILocation(line: 3, column: 9, scope: !20)
+!20 = distinct !DILexicalBlock(scope: !7, file: !8, line: 3, column: 7)
+!21 = !DILocation(line: 3, column: 7, scope: !7)
+!22 = !DILocation(line: 4, column: 8, scope: !20)
+!23 = !{!24, !24, i64 0}
+!24 = !{!"int", !25, i64 0}
+!25 = !{!"omnipotent char", !26, i64 0}
+!26 = !{!"Simple C/C++ TBAA"}
+!27 = !DILocation(line: 4, column: 5, scope: !20)
+!28 = !DILocation(line: 5, column: 3, scope: !7)
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -8123,9 +8123,9 @@
       Expr = *Fragment;
     }
     // Clone the SDDbgValue and move it to To.
-    SDDbgValue *Clone =
-        getDbgValue(Var, Expr, ToNode, To.getResNo(), Dbg->isIndirect(),
-                    Dbg->getDebugLoc(), Dbg->getOrder());
+    SDDbgValue *Clone = getDbgValue(
+        Var, Expr, ToNode, To.getResNo(), Dbg->isIndirect(), Dbg->getDebugLoc(),
+        std::max(ToNode->getIROrder(), Dbg->getOrder()));
     ClonedDVs.push_back(Clone);
 
     if (InvalidateDbg) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71175.232734.patch
Type: text/x-patch
Size: 4405 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191208/2a96a3d8/attachment.bin>


More information about the llvm-commits mailing list