<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 20, 2015, at 11:34 AM, 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=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Aug 20, 2015 at 11:23 AM, Adrian Prantl via llvm-commits <span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br class="">
Date: Thu Aug 20 13:23:56 2015<br class="">
New Revision: 245588<br class="">
<br class="">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D245588-26view-3Drev&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=86dqHw1S-sgpsH4Bsgqx_Mj5aCBM3RvAtP4OlFh1AG0&s=e4jjdKwbnVmqzlwu17oTd4tnkT7mzpB7ff782guZhFo&e=" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=245588&view=rev</a><br class="">
Log:<br class="">
Fix a debug location handling bug in GVN.<br class="">
Caught by the famous "DebugLoc describes the currect SubProgram" assertion.<br class=""></blockquote><div class=""><br class=""></div><div class="">Huzzah! \o/ ;) (sorry, I know they're a pain to track down, but it's a great way to find debug info quality bugs that would produce really shitty debug info if it weren't for this assertion)</div></div></div></div></div></blockquote><div><br class=""></div>Oh yes.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><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">When GVN is removing a nonlocal load it updates the debug location of the<br class="">
SSA value it replaced the load with with the one of the load.</blockquote><div class=""><br class="">I guess I'm not quite following here (knowing next to nothing about GVN) - could you explain this in more detail? What transformation is GVN performing on a call?<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>GVN is eliminating the load (and store) to @f and replaces all uses of the load with the value that is stored in @f, which is %call. It then used to transfer the DebugLoc of the load to the value it’s replacing it with (in this case %call). This triggers the assertion because %call happens to be, well, a call.</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><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"> In the<br class="">
testcase this actually overwrites a valid debug location with an empty one.<br class="">
<br class="">
In reality GVN has to make an arbitrary choice between two equally valid<br class="">
debug locations. This patch changes to behavior to only update the<br class="">
location if the value doesn't already have a debug location.<br class="">
<br class="">
Added:<br class="">
llvm/trunk/test/DebugInfo/gvn.ll<br class="">
Modified:<br class="">
llvm/trunk/lib/Transforms/Scalar/GVN.cpp<br class="">
<br class="">
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp<br class="">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Transforms_Scalar_GVN.cpp-3Frev-3D245588-26r1-3D245587-26r2-3D245588-26view-3Ddiff&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=86dqHw1S-sgpsH4Bsgqx_Mj5aCBM3RvAtP4OlFh1AG0&s=3z-a-gXHRfLinlwxZW5mohZaeBGnPUqI5NluJhV-TAQ&e=" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=245588&r1=245587&r2=245588&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)<br class="">
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Thu Aug 20 13:23:56 2015<br class="">
@@ -1744,7 +1744,8 @@ bool GVN::processNonLocalLoad(LoadInst *<br class="">
if (isa<PHINode>(V))<br class="">
V->takeName(LI);<br class="">
if (Instruction *I = dyn_cast<Instruction>(V))<br class="">
- I->setDebugLoc(LI->getDebugLoc());<br class="">
+ if (LI->getDebugLoc())<br class="">
+ I->setDebugLoc(LI->getDebugLoc());<br class="">
if (V->getType()->getScalarType()->isPointerTy())<br class="">
MD->invalidateCachedPointerInfo(V);<br class="">
markInstructionForDeletion(LI);<br class="">
<br class="">
Added: llvm/trunk/test/DebugInfo/gvn.ll<br class="">
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_DebugInfo_gvn.ll-3Frev-3D245588-26view-3Dauto&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=86dqHw1S-sgpsH4Bsgqx_Mj5aCBM3RvAtP4OlFh1AG0&s=zFB2qrxGTG9FAm3X7GplKYZ_JKT6reaieKBiMl66Dzs&e=" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/gvn.ll?rev=245588&view=auto</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/test/DebugInfo/gvn.ll (added)<br class="">
+++ llvm/trunk/test/DebugInfo/gvn.ll Thu Aug 20 13:23:56 2015<br class="">
@@ -0,0 +1,135 @@<br class="">
+; RUN: opt < %s -O2 -gvn -S | FileCheck %s<br class="">
+;<br class="">
+; Produced at -O2 from:<br class=""></blockquote><div class=""><br class="">Do you have the original reproduction -cc1 line, by chance? I'd be curious to see if this test case can be simplified a bit further to make the interesting part(s) more obvious.<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>Testcase-golfing! :-)</div><div><br class=""></div><div>It’s very hard to reduce it any more from source, because it needs this specific chain of simplify-cfg and gvn:</div><div> clang -cc1 -triple arm64-apple-ios -emit-llvm -gdwarf-2 -O2 file.c -o -</div><div><br class=""></div><div>-- adrian</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+; struct context {<br class="">
+; int cur_pid<br class="">
+; };<br class="">
+; int a, b, c, f, d;<br class="">
+; int pid_for_task(int);<br class="">
+; sample(struct context *p1)<br class="">
+; {<br class="">
+; if (c)<br class="">
+; b = a;<br class="">
+; if (a && p1->cur_pid)<br class="">
+; sample_internal();<br class="">
+; }<br class="">
+; callback() {<br class="">
+; f = pid_for_task(d);<br class="">
+; sample(&f);<br class="">
+; }<br class="">
+<br class="">
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"<br class="">
+target triple = "arm64-apple-ios"<br class="">
+<br class="">
+%struct.context = type { i32 }<br class="">
+<br class="">
+@c = common global i32 0, align 4<br class="">
+@a = common global i32 0, align 4<br class="">
+@b = common global i32 0, align 4<br class="">
+@d = common global i32 0, align 4<br class="">
+@f = common global i32 0, align 4<br class="">
+<br class="">
+; Function Attrs: nounwind<br class="">
+declare i32 @sample_internal(...)<br class="">
+<br class="">
+; Function Attrs: nounwind<br class="">
+define i32 @callback() #0 {<br class="">
+entry:<br class="">
+ %0 = load i32, i32* @d, align 4, !dbg !37<br class="">
+<br class="">
+ ; Verify that the call still has a debug location after GVN.<br class="">
+ ; CHECK: %call = tail call i32 @pid_for_task(i32 %0) #{{[0-9]}}, !dbg<br class="">
+ %call = tail call i32 @pid_for_task(i32 %0) #3, !dbg !37<br class="">
+<br class="">
+ store i32 %call, i32* @f, align 4, !dbg !37<br class="">
+ tail call void @llvm.dbg.value(metadata %struct.context* bitcast (i32* @f to %struct.context*), i64 0, metadata !25, metadata !26) #3, !dbg !38<br class="">
+ %1 = load i32, i32* @c, align 4, !dbg !40<br class="">
+ %tobool.i = icmp eq i32 %1, 0, !dbg !40<br class="">
+ %.pr.i = load i32, i32* @a, align 4, !dbg !41<br class="">
+ br i1 %tobool.i, label %if.end.i, label %if.then.i, !dbg !42<br class="">
+<br class="">
+if.then.i: ; preds = %entry<br class="">
+ store i32 %.pr.i, i32* @b, align 4, !dbg !43<br class="">
+ br label %if.end.i, !dbg !43<br class="">
+<br class="">
+if.end.i: ; preds = %if.then.i, %entry<br class="">
+ %tobool1.i = icmp eq i32 %.pr.i, 0, !dbg !41<br class="">
+<br class="">
+ ; This instruction has no debug location -- in this<br class="">
+ ; particular case it was removed by a bug in SimplifyCFG.<br class="">
+ %2 = load i32, i32* @f, align 4<br class="">
+<br class="">
+ ; GVN is supposed to replace the load of @f with a direct reference to %call.<br class="">
+ ; CHECK: %tobool2.i = icmp eq i32 %call, 0, !dbg<br class="">
+ %tobool2.i = icmp eq i32 %2, 0, !dbg !41<br class="">
+<br class="">
+ %or.cond = or i1 %tobool1.i, %tobool2.i, !dbg !41<br class="">
+ br i1 %or.cond, label %sample.exit, label %if.then.3.i, !dbg !41<br class="">
+<br class="">
+if.then.3.i: ; preds = %if.end.i<br class="">
+ %call.i = tail call i32 bitcast (i32 (...)* @sample_internal to i32 ()*)() #3, !dbg !44<br class="">
+ br label %sample.exit, !dbg !44<br class="">
+<br class="">
+sample.exit: ; preds = %if.end.i, %if.then.3.i<br class="">
+ ret i32 undef, !dbg !45<br class="">
+}<br class="">
+<br class="">
+declare i32 @pid_for_task(i32) #1<br class="">
+<br class="">
+; Function Attrs: nounwind readnone<br class="">
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2<br class="">
+<br class="">
+attributes #0 = { nounwind }<br class="">
+attributes #2 = { nounwind readnone }<br class="">
+attributes #3 = { nounwind }<br class="">
+<br class="">
+!<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.dbg.cu&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=86dqHw1S-sgpsH4Bsgqx_Mj5aCBM3RvAtP4OlFh1AG0&s=k1mLTSIzssOjZljHe612mvR_uLJjrT9NK96QRAUNl_Q&e=" rel="noreferrer" target="_blank" class="">llvm.dbg.cu</a> = !{!0}<br class="">
+!llvm.module.flags = !{!22, !23}<br class="">
+!llvm.ident = !{!24}<br class="">
+<br class="">
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 244473) (llvm/trunk 244644)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !16)<br class="">
+!1 = !DIFile(filename: "test.c", directory: "/")<br class="">
+!2 = !{}<br class="">
+!3 = !{!4, !13}<br class="">
+!4 = !DISubprogram(name: "sample", scope: !5, file: !5, line: 6, type: !6, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, variables: !2)<br class="">
+!5 = !DIFile(filename: "test.i", directory: "/")<br class="">
+!6 = !DISubroutineType(types: !7)<br class="">
+!7 = !{!8, !9}<br class="">
+!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)<br class="">
+!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)<br class="">
+!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "context", file: !5, line: 1, size: 32, align: 32, elements: !11)<br class="">
+!11 = !{!12}<br class="">
+!12 = !DIDerivedType(tag: DW_TAG_member, name: "cur_pid", scope: !10, file: !5, line: 2, baseType: !8, size: 32, align: 32)<br class="">
+!13 = !DISubprogram(name: "callback", scope: !5, file: !5, line: 13, type: !14, isLocal: false, isDefinition: true, scopeLine: 13, isOptimized: false, function: i32 ()* @callback, variables: !2)<br class="">
+!14 = !DISubroutineType(types: !15)<br class="">
+!15 = !{!8}<br class="">
+!16 = !{!17, !18, !19, !20, !21}<br class="">
+!17 = !DIGlobalVariable(name: "a", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @a)<br class="">
+!18 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @b)<br class="">
+!19 = !DIGlobalVariable(name: "c", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @c)<br class="">
+!20 = !DIGlobalVariable(name: "f", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @f)<br class="">
+!21 = !DIGlobalVariable(name: "d", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @d)<br class="">
+!22 = !{i32 2, !"Dwarf Version", i32 2}<br class="">
+!23 = !{i32 2, !"Debug Info Version", i32 3}<br class="">
+!24 = !{!"clang version 3.8.0 (trunk 244473) (llvm/trunk 244644)"}<br class="">
+!25 = !DILocalVariable(name: "p1", arg: 1, scope: !4, file: !5, line: 6, type: !9)<br class="">
+!26 = !DIExpression()<br class="">
+!27 = !DILocation(line: 6, scope: !4)<br class="">
+!28 = !DILocation(line: 8, scope: !29)<br class="">
+!29 = distinct !DILexicalBlock(scope: !4, file: !5, line: 8)<br class="">
+!30 = !DILocation(line: 10, scope: !31)<br class="">
+!31 = distinct !DILexicalBlock(scope: !4, file: !5, line: 10)<br class="">
+!32 = !DILocation(line: 8, scope: !4)<br class="">
+!33 = !DILocation(line: 9, scope: !29)<br class="">
+!34 = !DILocation(line: 10, scope: !4)<br class="">
+!35 = !DILocation(line: 11, scope: !31)<br class="">
+!36 = !DILocation(line: 12, scope: !4)<br class="">
+!37 = !DILocation(line: 14, scope: !13)<br class="">
+!38 = !DILocation(line: 6, scope: !4, inlinedAt: !39)<br class="">
+!39 = distinct !DILocation(line: 15, scope: !13)<br class="">
+!40 = !DILocation(line: 8, scope: !29, inlinedAt: !39)<br class="">
+!41 = !DILocation(line: 10, scope: !31, inlinedAt: !39)<br class="">
+!42 = !DILocation(line: 8, scope: !4, inlinedAt: !39)<br class="">
+!43 = !DILocation(line: 9, scope: !29, inlinedAt: !39)<br class="">
+!44 = !DILocation(line: 11, scope: !31, inlinedAt: !39)<br class="">
+!45 = !DILocation(line: 16, scope: !13)<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=86dqHw1S-sgpsH4Bsgqx_Mj5aCBM3RvAtP4OlFh1AG0&s=hw8X2tjG7mYWbE1ipbSVUR3OqRgOptp1K6hBQIBuGmU&e=" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>