[PATCH] D41924: dagcombine: Transfer debug information when folding (zext (truncate x)) -> (zext (truncate x))

Adrian Prantl via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 16:02:17 PST 2018


aprantl created this revision.
aprantl added a reviewer: vsk.
Herald added a subscriber: JDevlieghere.

This patch adds debug info support to the dagcombine rule  (zext (truncate x)) -> (zext (truncate x)).


Repository:
  rL LLVM

https://reviews.llvm.org/D41924

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  test/DebugInfo/X86/sdag-combine.ll


Index: test/DebugInfo/X86/sdag-combine.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/X86/sdag-combine.ll
@@ -0,0 +1,47 @@
+; RUN: llc %s -stop-after=livedebugvars -o - | FileCheck %s
+source_filename = "/tmp/t.ll"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.13"
+
+%TSb = type <{ i1 }>
+
+declare swiftcc i1 @f()
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+; Function Attrs: nounwind readnone speculatable
+define swiftcc void @g() #0 !dbg !5 {
+entry:
+  %0 = alloca %TSb, align 1
+  %1 = call swiftcc i1 @f(), !dbg !8
+  call void @llvm.dbg.value(metadata i1 %1, metadata !9, metadata !DIExpression()), !dbg !8
+  ; CHECK: DBG_VALUE debug-use %rax, debug-use %noreg, !9, !DIExpression(), debug-location !8
+  %2 = getelementptr inbounds %TSb, %TSb* %0, i32 0, i32 0, !dbg !8
+  store i1 %1, i1* %2, align 1, !dbg !8
+  %3 = zext i1 %1 to i64, !dbg !8
+  call void asm sideeffect "", "r"(i64 %3), !dbg !8
+  ret void, !dbg !8
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.value(metadata, metadata, metadata) #0
+
+attributes #0 = { nounwind readnone speculatable }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !1, isOptimized: false, runtimeVersion: 4, emissionKind: FullDebug, enums: !2, imports: !2)
+!1 = !DIFile(filename: "/tmp/t.swift", directory: "/Data/llvm/tools/clang")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "g", scope: !0, file: !6, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, variables: !2)
+!6 = !DIFile(filename: "t.swift", directory: "/tmp")
+!7 = !DISubroutineType(types: !2)
+!8 = !DILocation(line: 4, scope: !5)
+!9 = !DILocalVariable(name: "hasInput", scope: !5, file: !6, line: 3, type: !10)
+!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "Bool", scope: !12, file: !11, size: 8, elements: !2, runtimeLang: DW_LANG_Swift, identifier: "_T0SbD")
+!11 = !DIFile(filename: "Swift.swiftmodule", directory: "/usr/lib/swift/macosx/x86_64")
+!12 = !DIModule(scope: null, name: "Swift", includePath: "/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk")
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7798,7 +7798,10 @@
         SDValue Op = N0.getOperand(0);
         Op = DAG.getZeroExtendInReg(Op, SDLoc(N), MinVT.getScalarType());
         AddToWorklist(Op.getNode());
-        return DAG.getZExtOrTrunc(Op, SDLoc(N), VT);
+        SDValue ZExtOrTrunc = DAG.getZExtOrTrunc(Op, SDLoc(N), VT);
+        // Transfer the debug info; the new node is equivalent to N0.
+        DAG.transferDbgValues(N0, ZExtOrTrunc);
+        return ZExtOrTrunc;
       }
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41924.129361.patch
Type: text/x-patch
Size: 3128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180111/509aa12d/attachment.bin>


More information about the llvm-commits mailing list