<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 25, 2017, at 5:09 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Aug 25, 2017 at 4:44 PM Adrian Prantl <<a href="mailto:aprantl@apple.com" class="">aprantl@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 25, 2017, at 3:15 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>> wrote:</div><br class="m_-1524246888158857396Apple-interchange-newline"><div class=""><div dir="ltr" class="">Adrian - what were we doing about cases where merged locations were on call instructions? I think this case is one of those, where if the instruction is a call, this may drop the location from the call, then inline through the call creating corrupted debug info.<br class=""></div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class="">I guess that in this case the only sane thing we can do is create a new artificial line 0 location in one of the two calls' scope. It's not pretty, but that;s the best I can come up with.</div></div></div></blockquote><div class=""><br class="">A few options:<br class=""><br class="">Further up in the same file, the code avoids merging if the instruction is a call (originally r380995) SimplifyCFG.cpp:1282.<br class=""><br class="">So that's one option - do nothing on calls. But it's probably not ideal/wrong (since it's not either location)<br class=""><br class="">Beyond that we get to the zero location - but in what scope?<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>I don't have a good answer for that. It looks like whatever we do will screw up the backtraces in at least some cases.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class="">The root scope of the function? (what if these two calls are both within a single inlined call? That'll punch a hole in the range which isn't entirely accurate) The nearest common parent scope to the two instructions (assuming they both have debug locations? If one doesn't have a location, could we reliably use the other location? Probably not - so if one doesn't have a location we should use the zero location at the root of the current function for sure)<br class="">Worth finding the common parent scope?<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>That sounds like a workable compromise.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class="">Should this functionality be built into getMergedLocation?<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>I think so — we could add an isCall bool argument or — probably even better — pass in the instruction the location will be attached to.</div><div><br class=""></div><div>-- adrian</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div><div class="">-- adrian</div></div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><br class="">Here's a test case that seems to exercise/assert on that (but it asserts relatively late - would be handy to have a way to run the verifier between each optimization - maybe there is such an option?):<br class=""><font face="monospace" class=""><br class=""></font><div class=""><font face="monospace" class="">struct string {</font></div><div class=""><font face="monospace" class="">  ~string();</font></div><div class=""><font face="monospace" class="">};</font></div><div class=""><font face="monospace" class="">void f2();</font></div><div class=""><font face="monospace" class="">void f1(int) { f2(); }</font></div><div class=""><font face="monospace" class="">void run(int c) {</font></div><div class=""><font face="monospace" class="">  string body;</font></div><div class=""><font face="monospace" class="">  while (true) {</font></div><div class=""><font face="monospace" class="">    if (c)</font></div><div class=""><font face="monospace" class="">      f1(c);</font></div><div class=""><font face="monospace" class="">    else</font></div><div class=""><font face="monospace" class="">      f1(c);</font></div><div class=""><font face="monospace" class="">  }</font></div><div class=""><font face="monospace" class="">}</font></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Aug 15, 2017 at 6:56 PM Dehao Chen via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dehao<br class="">
Date: Tue Aug 15 18:55:26 2017<br class="">
New Revision: 310985<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=310985&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=310985&view=rev</a><br class="">
Log:<br class="">
Merge debug info when hoist then-else code to if.<br class="">
<br class="">
Summary: When we move then-else code to if, we need to merge its debug info, otherwise the hoisted instruction may have inaccurate debug info attached.<br class="">
<br class="">
Reviewers: aprantl, probinson, dblaikie, echristo, loladiro<br class="">
<br class="">
Reviewed By: aprantl<br class="">
<br class="">
Subscribers: sanjoy, llvm-commits<br class="">
<br class="">
Differential Revision: <a href="https://reviews.llvm.org/D36778" rel="noreferrer" target="_blank" class="">https://reviews.llvm.org/D36778</a><br class="">
<br class="">
Added:<br class="">
    llvm/trunk/test/Transforms/SimplifyCFG/min_dbginfo.ll<br class="">
Modified:<br class="">
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp<br class="">
<br class="">
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=310985&r1=310984&r2=310985&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=310985&r1=310984&r2=310985&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)<br class="">
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 15 18:55:26 2017<br class="">
@@ -1336,6 +1336,8 @@ HoistTerminator:<br class="">
     I2->replaceAllUsesWith(NT);<br class="">
     NT->takeName(I1);<br class="">
   }<br class="">
+  NT->setDebugLoc(DILocation::getMergedLocation(<br class="">
+      I1->getDebugLoc(), I2->getDebugLoc()));<br class="">
<br class="">
   IRBuilder<NoFolder> Builder(NT);<br class="">
   // Hoisting one of the terminators from our successor is a great thing.<br class="">
<br class="">
Added: llvm/trunk/test/Transforms/SimplifyCFG/min_dbginfo.ll<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/min_dbginfo.ll?rev=310985&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/min_dbginfo.ll?rev=310985&view=auto</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/test/Transforms/SimplifyCFG/min_dbginfo.ll (added)<br class="">
+++ llvm/trunk/test/Transforms/SimplifyCFG/min_dbginfo.ll Tue Aug 15 18:55:26 2017<br class="">
@@ -0,0 +1,39 @@<br class="">
+; RUN: opt < %s -simplifycfg -S | FileCheck %s<br class="">
+<br class="">
+; Checks if the debug info is removed for the "select" instruction.<br class="">
+; CHECK: cmp {{.*}} !dbg<br class="">
+; CHECK-NOT: select {{.*}} !dbg<br class="">
+define i32 @min(i32 %a, i32 %b) {<br class="">
+entry:<br class="">
+  %cmp = icmp slt i32 %a, %b, !dbg !9<br class="">
+  br i1 %cmp, label %if.then, label %if.else, !dbg !10<br class="">
+<br class="">
+if.then:<br class="">
+  br label %return, !dbg !11<br class="">
+<br class="">
+if.else:<br class="">
+  br label %return, !dbg !12<br class="">
+<br class="">
+return:<br class="">
+  %retval.0 = phi i32 [ %a, %if.then ], [ %b, %if.else ]<br class="">
+  ret i32 %retval.0, !dbg !13<br class="">
+}<br class="">
+<br class="">
+!<a href="http://llvm.dbg.cu/" rel="noreferrer" target="_blank" class="">llvm.dbg.cu</a> = !{!0}<br class="">
+!llvm.module.flags = !{!3, !4, !5}<br class="">
+!llvm.ident = !{!6}<br class="">
+<br class="">
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 310792)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)<br class="">
+!1 = !DIFile(filename: "<a href="http://min.cc/" target="_blank" class="">min.cc</a>", directory: "/")<br class="">
+!2 = !{}<br class="">
+!3 = !{i32 2, !"Dwarf Version", i32 4}<br class="">
+!4 = !{i32 2, !"Debug Info Version", i32 3}<br class="">
+!5 = !{i32 1, !"wchar_size", i32 4}<br class="">
+!6 = !{!"clang version 6.0.0 (trunk 310792)"}<br class="">
+!7 = distinct !DISubprogram(name: "min", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)<br class="">
+!8 = !DISubroutineType(types: !2)<br class="">
+!9 = !DILocation(line: 4, column: 8, scope: !7)<br class="">
+!10 = !DILocation(line: 4, column: 6, scope: !7)<br class="">
+!11 = !DILocation(line: 5, column: 3, scope: !7)<br class="">
+!12 = !DILocation(line: 7, column: 3, scope: !7)<br class="">
+!13 = !DILocation(line: 9, column: 1, scope: !7)<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div></div>
</div></blockquote></div></div></blockquote></div></div>
</div></blockquote></div><br class=""></body></html>