<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 20, 2015 at 11:28 AM, Adrian Prantl 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"><span class=""><br>
> On Aug 20, 2015, at 11:23 AM, Adrian Prantl via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: adrian<br>
> Date: Thu Aug 20 13:23:56 2015<br>
> New Revision: 245588<br>
><br>
</span>> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D245588-26view-3Drev&d=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=UsPyOZjvOF75FKD4kBH1X1gMSZIq-pFRDC8kvWBS2w0&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D245588-26view-3Drev&d=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=UsPyOZjvOF75FKD4kBH1X1gMSZIq-pFRDC8kvWBS2w0&e=</a><br>
<span class="">> Log:<br>
> Fix a debug location handling bug in GVN.<br>
> Caught by the famous "DebugLoc describes the currect SubProgram" assertion.<br>
><br>
> When GVN is removing a nonlocal load it updates the debug location of the<br>
> SSA value it replaced the load with with the one of the load. In the<br>
> testcase this actually overwrites a valid debug location with an empty one.<br>
><br>
> In reality GVN has to make an arbitrary choice between two equally valid<br>
> debug locations. This patch changes to behavior to only update the<br>
> location if the value doesn't already have a debug location.<br>
><br>
> Added:<br>
> llvm/trunk/test/DebugInfo/gvn.ll<br>
> Modified:<br>
> llvm/trunk/lib/Transforms/Scalar/GVN.cpp<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp<br>
</span>> 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=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=qxyWSdB0E7E3fhM6zkYTzydfTcgVPfVFpm85bvbqaw0&e=" rel="noreferrer" target="_blank">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=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=qxyWSdB0E7E3fhM6zkYTzydfTcgVPfVFpm85bvbqaw0&e=</a><br>
<span class="">> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Thu Aug 20 13:23:56 2015<br>
> @@ -1744,7 +1744,8 @@ bool GVN::processNonLocalLoad(LoadInst *<br>
> if (isa<PHINode>(V))<br>
> V->takeName(LI);<br>
> if (Instruction *I = dyn_cast<Instruction>(V))<br>
> - I->setDebugLoc(LI->getDebugLoc());<br>
> + if (LI->getDebugLoc())<br>
> + I->setDebugLoc(LI->getDebugLoc());<br>
> if (V->getType()->getScalarType()->isPointerTy())<br>
> MD->invalidateCachedPointerInfo(V);<br>
> markInstructionForDeletion(LI);<br>
><br>
> Added: llvm/trunk/test/DebugInfo/gvn.ll<br>
</span>> 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=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=Zg7ORbK0TOC9ZrZ1W5nHutgFgc5wAHA6RlagiMt6NAc&e=" rel="noreferrer" target="_blank">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=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=Zg7ORbK0TOC9ZrZ1W5nHutgFgc5wAHA6RlagiMt6NAc&e=</a><br>
<div><div class="h5">> ==============================================================================<br>
> --- llvm/trunk/test/DebugInfo/gvn.ll (added)<br>
> +++ llvm/trunk/test/DebugInfo/gvn.ll Thu Aug 20 13:23:56 2015<br>
> @@ -0,0 +1,135 @@<br>
> +; RUN: opt < %s -O2 -gvn -S | FileCheck %s<br>
> +;<br>
> +; Produced at -O2 from:<br>
> +; struct context {<br>
> +; int cur_pid<br>
> +; };<br>
> +; int a, b, c, f, d;<br>
> +; int pid_for_task(int);<br>
> +; sample(struct context *p1)<br>
> +; {<br>
> +; if (c)<br>
> +; b = a;<br>
> +; if (a && p1->cur_pid)<br>
> +; sample_internal();<br>
> +; }<br>
> +; callback() {<br>
> +; f = pid_for_task(d);<br>
> +; sample(&f);<br>
> +; }<br>
> +<br>
> +target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"<br>
> +target triple = "arm64-apple-ios"<br>
> +<br>
> +%struct.context = type { i32 }<br>
> +<br>
> +@c = common global i32 0, align 4<br>
> +@a = common global i32 0, align 4<br>
> +@b = common global i32 0, align 4<br>
> +@d = common global i32 0, align 4<br>
> +@f = common global i32 0, align 4<br>
> +<br>
> +; Function Attrs: nounwind<br>
> +declare i32 @sample_internal(...)<br>
> +<br>
> +; Function Attrs: nounwind<br>
> +define i32 @callback() #0 {<br>
> +entry:<br>
> + %0 = load i32, i32* @d, align 4, !dbg !37<br>
> +<br>
> + ; Verify that the call still has a debug location after GVN.<br>
> + ; CHECK: %call = tail call i32 @pid_for_task(i32 %0) #{{[0-9]}}, !dbg<br>
> + %call = tail call i32 @pid_for_task(i32 %0) #3, !dbg !37<br>
> +<br>
> + store i32 %call, i32* @f, align 4, !dbg !37<br>
> + 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>
> + %1 = load i32, i32* @c, align 4, !dbg !40<br>
> + %tobool.i = icmp eq i32 %1, 0, !dbg !40<br>
> + %.pr.i = load i32, i32* @a, align 4, !dbg !41<br>
> + br i1 %tobool.i, label %if.end.i, label %if.then.i, !dbg !42<br>
> +<br>
> +if.then.i: ; preds = %entry<br>
> + store i32 %.pr.i, i32* @b, align 4, !dbg !43<br>
> + br label %if.end.i, !dbg !43<br>
> +<br>
> +if.end.i: ; preds = %if.then.i, %entry<br>
> + %tobool1.i = icmp eq i32 %.pr.i, 0, !dbg !41<br>
> +<br>
> + ; This instruction has no debug location -- in this<br>
> + ; particular case it was removed by a bug in SimplifyCFG.<br>
<br>
</div></div>... which has been fixed in r245589.<br></blockquote><div><br>Ideally we'd have a reproduction that was from IR that wasn't produced by a bug in another pass - but if that's not easy to come by, this is still legit, for sure (we shouldn't crash on any IR input, really - which does sort of make that assertion a bit dodgy, but at least it expresses a relatively limited constraint which this IR file satisfies, even with this missing location)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5"><br>
> + %2 = load i32, i32* @f, align 4<br>
> +<br>
> + ; GVN is supposed to replace the load of @f with a direct reference to %call.<br>
> + ; CHECK: %tobool2.i = icmp eq i32 %call, 0, !dbg<br>
> + %tobool2.i = icmp eq i32 %2, 0, !dbg !41<br>
> +<br>
> + %or.cond = or i1 %tobool1.i, %tobool2.i, !dbg !41<br>
> + br i1 %or.cond, label %sample.exit, label %if.then.3.i, !dbg !41<br>
> +<br>
> +if.then.3.i: ; preds = %if.end.i<br>
> + %call.i = tail call i32 bitcast (i32 (...)* @sample_internal to i32 ()*)() #3, !dbg !44<br>
> + br label %sample.exit, !dbg !44<br>
> +<br>
> +sample.exit: ; preds = %if.end.i, %if.then.3.i<br>
> + ret i32 undef, !dbg !45<br>
> +}<br>
> +<br>
> +declare i32 @pid_for_task(i32) #1<br>
> +<br>
> +; Function Attrs: nounwind readnone<br>
> +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2<br>
> +<br>
> +attributes #0 = { nounwind }<br>
> +attributes #2 = { nounwind readnone }<br>
> +attributes #3 = { nounwind }<br>
> +<br>
> +!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
> +!llvm.module.flags = !{!22, !23}<br>
> +!llvm.ident = !{!24}<br>
> +<br>
> +!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>
> +!1 = !DIFile(filename: "test.c", directory: "/")<br>
> +!2 = !{}<br>
> +!3 = !{!4, !13}<br>
> +!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>
> +!5 = !DIFile(filename: "test.i", directory: "/")<br>
> +!6 = !DISubroutineType(types: !7)<br>
> +!7 = !{!8, !9}<br>
> +!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)<br>
> +!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)<br>
> +!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "context", file: !5, line: 1, size: 32, align: 32, elements: !11)<br>
> +!11 = !{!12}<br>
> +!12 = !DIDerivedType(tag: DW_TAG_member, name: "cur_pid", scope: !10, file: !5, line: 2, baseType: !8, size: 32, align: 32)<br>
> +!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>
> +!14 = !DISubroutineType(types: !15)<br>
> +!15 = !{!8}<br>
> +!16 = !{!17, !18, !19, !20, !21}<br>
> +!17 = !DIGlobalVariable(name: "a", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @a)<br>
> +!18 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @b)<br>
> +!19 = !DIGlobalVariable(name: "c", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @c)<br>
> +!20 = !DIGlobalVariable(name: "f", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @f)<br>
> +!21 = !DIGlobalVariable(name: "d", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @d)<br>
> +!22 = !{i32 2, !"Dwarf Version", i32 2}<br>
> +!23 = !{i32 2, !"Debug Info Version", i32 3}<br>
> +!24 = !{!"clang version 3.8.0 (trunk 244473) (llvm/trunk 244644)"}<br>
> +!25 = !DILocalVariable(name: "p1", arg: 1, scope: !4, file: !5, line: 6, type: !9)<br>
> +!26 = !DIExpression()<br>
> +!27 = !DILocation(line: 6, scope: !4)<br>
> +!28 = !DILocation(line: 8, scope: !29)<br>
> +!29 = distinct !DILexicalBlock(scope: !4, file: !5, line: 8)<br>
> +!30 = !DILocation(line: 10, scope: !31)<br>
> +!31 = distinct !DILexicalBlock(scope: !4, file: !5, line: 10)<br>
> +!32 = !DILocation(line: 8, scope: !4)<br>
> +!33 = !DILocation(line: 9, scope: !29)<br>
> +!34 = !DILocation(line: 10, scope: !4)<br>
> +!35 = !DILocation(line: 11, scope: !31)<br>
> +!36 = !DILocation(line: 12, scope: !4)<br>
> +!37 = !DILocation(line: 14, scope: !13)<br>
> +!38 = !DILocation(line: 6, scope: !4, inlinedAt: !39)<br>
> +!39 = distinct !DILocation(line: 15, scope: !13)<br>
> +!40 = !DILocation(line: 8, scope: !29, inlinedAt: !39)<br>
> +!41 = !DILocation(line: 10, scope: !31, inlinedAt: !39)<br>
> +!42 = !DILocation(line: 8, scope: !4, inlinedAt: !39)<br>
> +!43 = !DILocation(line: 9, scope: !29, inlinedAt: !39)<br>
> +!44 = !DILocation(line: 11, scope: !31, inlinedAt: !39)<br>
> +!45 = !DILocation(line: 16, scope: !13)<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
</div></div>> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=spWlc7X04Ustu2UzfsjG4qz7ExRmUUz_mvamy2koidg&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=BQIGaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=1OMFcIVXCQ-3a2cHjkzeoWw-2B9l6GXi6522rq-fXRo&s=spWlc7X04Ustu2UzfsjG4qz7ExRmUUz_mvamy2koidg&e=</a><br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div></div>