[PATCH] D20432: [DAGCombiner] Keep debug information when folding (sext (truncate x)) -> (sextinreg x)

Marianne Mailhot-Sarrasin via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 06:57:31 PDT 2016


mamai created this revision.
mamai added a reviewer: probinson.
mamai added a subscriber: llvm-commits.
mamai set the repository for this revision to rL LLVM.

In the case that there is a debug value on the truncate instruction and none on the sign extend, transfer it from truncate to sign extend so it does not get lost. Also adding a test case showing the debug information in IR will result in a debug value at code generation.

Repository:
  rL LLVM

http://reviews.llvm.org/D20432

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  test/DebugInfo/ARM/dagcombine-truncate.ll

Index: test/DebugInfo/ARM/dagcombine-truncate.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/ARM/dagcombine-truncate.ll
@@ -0,0 +1,44 @@
+; RUN: llc < %s | FileCheck %s
+
+;CHECK: #DEBUG_VALUE: main:bigger
+
+; Function Attrs: noinline nounwind
+define i32 @main() !dbg !4 {
+entry:
+  %call = call i32 bitcast (i32 (...)* @max to i32 (i32, i32)*)(i32 1, i32 2), !dbg !14
+  %conv = trunc i32 %call to i8, !dbg !16
+  call void @llvm.dbg.value(metadata i8 %conv, i64 0, metadata !9, metadata !17), !dbg !18
+  %conv1 = sext i8 %conv to i32, !dbg !19
+  ret i32 %conv1, !dbg !20
+}
+
+declare i32 @max(...)
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!11, !12}
+!llvm.ident = !{!13}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk) (http://llvm.org/git/llvm.git a0a8cb640e6caead7ea28b9f04a410bc86209e4f)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "main.c", directory: "/private/tmp")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 10, type: !5, isLocal: false, isDefinition: true, scopeLine: 10, isOptimized: true, variables: !8, unit: !0)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!8 = !{!9}
+!9 = !DILocalVariable(name: "bigger", scope: !4, file: !1, line: 11, type: !10)
+!10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+!11 = !{i32 2, !"Dwarf Version", i32 4}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{!"clang version 3.9.0 (trunk) (http://llvm.org/git/llvm.git a0a8cb640e6caead7ea28b9f04a410bc86209e4f)"}
+!14 = !DILocation(line: 11, column: 16, scope: !15)
+!15 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 1)
+!16 = !DILocation(line: 11, column: 16, scope: !4)
+!17 = !DIExpression()
+!18 = !DILocation(line: 11, column: 7, scope: !4)
+!19 = !DILocation(line: 12, column: 9, scope: !4)
+!20 = !DILocation(line: 12, column: 2, scope: !4)
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -6077,6 +6077,12 @@
         Op = DAG.getNode(ISD::ANY_EXTEND, SDLoc(N0), VT, Op);
       else if (OpBits > DestBits)
         Op = DAG.getNode(ISD::TRUNCATE, SDLoc(N0), VT, Op);
+      else if (N0->getHasDebugValue() && !N->getHasDebugValue()) {
+        // Instead of loosing the truncate debug information, pass it to N.
+        N->setDebugLoc(N0->getDebugLoc());
+        N->setIROrder(N0->getIROrder());
+        DAG.TransferDbgValues(N0, SDValue(N, 0));
+      }
       return DAG.getNode(ISD::SIGN_EXTEND_INREG, SDLoc(N), VT, Op,
                          DAG.getValueType(N0.getValueType()));
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20432.57675.patch
Type: text/x-patch
Size: 3027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160519/8af07288/attachment.bin>


More information about the llvm-commits mailing list