<div dir="ltr">Generally the test case should just test the optimization - no need to go all the way through codegen, etc.<br><br>what's the current behavior if both instructions have a location?<br><br>& why is this in an else if block? Why should it not happen if the ifs above it are true?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 19, 2016 at 6:57 AM, Marianne Mailhot-Sarrasin via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">mamai created this revision.<br>
mamai added a reviewer: probinson.<br>
mamai added a subscriber: llvm-commits.<br>
mamai set the repository for this revision to rL LLVM.<br>
<br>
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.<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D20432" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20432</a><br>
<br>
Files:<br>
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
  test/DebugInfo/ARM/dagcombine-truncate.ll<br>
<br>
Index: test/DebugInfo/ARM/dagcombine-truncate.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/DebugInfo/ARM/dagcombine-truncate.ll<br>
@@ -0,0 +1,44 @@<br>
+; RUN: llc < %s | FileCheck %s<br>
+<br>
+;CHECK: #DEBUG_VALUE: main:bigger<br>
+<br>
+; Function Attrs: noinline nounwind<br>
+define i32 @main() !dbg !4 {<br>
+entry:<br>
+  %call = call i32 bitcast (i32 (...)* @max to i32 (i32, i32)*)(i32 1, i32 2), !dbg !14<br>
+  %conv = trunc i32 %call to i8, !dbg !16<br>
+  call void @llvm.dbg.value(metadata i8 %conv, i64 0, metadata !9, metadata !17), !dbg !18<br>
+  %conv1 = sext i8 %conv to i32, !dbg !19<br>
+  ret i32 %conv1, !dbg !20<br>
+}<br>
+<br>
+declare i32 @max(...)<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!11, !12}<br>
+!llvm.ident = !{!13}<br>
+<br>
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk) (<a href="http://llvm.org/git/llvm.git" rel="noreferrer" target="_blank">http://llvm.org/git/llvm.git</a> a0a8cb640e6caead7ea28b9f04a410bc86209e4f)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)<br>
+!1 = !DIFile(filename: "main.c", directory: "/private/tmp")<br>
+!2 = !{}<br>
+!3 = !{!4}<br>
+!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)<br>
+!5 = !DISubroutineType(types: !6)<br>
+!6 = !{!7}<br>
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)<br>
+!8 = !{!9}<br>
+!9 = !DILocalVariable(name: "bigger", scope: !4, file: !1, line: 11, type: !10)<br>
+!10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)<br>
+!11 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!12 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!13 = !{!"clang version 3.9.0 (trunk) (<a href="http://llvm.org/git/llvm.git" rel="noreferrer" target="_blank">http://llvm.org/git/llvm.git</a> a0a8cb640e6caead7ea28b9f04a410bc86209e4f)"}<br>
+!14 = !DILocation(line: 11, column: 16, scope: !15)<br>
+!15 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 1)<br>
+!16 = !DILocation(line: 11, column: 16, scope: !4)<br>
+!17 = !DIExpression()<br>
+!18 = !DILocation(line: 11, column: 7, scope: !4)<br>
+!19 = !DILocation(line: 12, column: 9, scope: !4)<br>
+!20 = !DILocation(line: 12, column: 2, scope: !4)<br>
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
===================================================================<br>
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
@@ -6077,6 +6077,12 @@<br>
         Op = DAG.getNode(ISD::ANY_EXTEND, SDLoc(N0), VT, Op);<br>
       else if (OpBits > DestBits)<br>
         Op = DAG.getNode(ISD::TRUNCATE, SDLoc(N0), VT, Op);<br>
+      else if (N0->getHasDebugValue() && !N->getHasDebugValue()) {<br>
+        // Instead of loosing the truncate debug information, pass it to N.<br>
+        N->setDebugLoc(N0->getDebugLoc());<br>
+        N->setIROrder(N0->getIROrder());<br>
+        DAG.TransferDbgValues(N0, SDValue(N, 0));<br>
+      }<br>
       return DAG.getNode(ISD::SIGN_EXTEND_INREG, SDLoc(N), VT, Op,<br>
                          DAG.getValueType(N0.getValueType()));<br>
     }<br>
<br>
<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>