<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:36 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Thu, Aug 20, 2015 at 11:28 AM, Adrian Prantl via llvm-commits<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><span class=""><br class="">> On Aug 20, 2015, at 11:23 AM, Adrian Prantl via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:<br class="">><br class="">> Author: adrian<br class="">> Date: Thu Aug 20 13:23:56 2015<br class="">> New Revision: 245588<br class="">><br class=""></span>> URL:<span class="Apple-converted-space"> </span><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" class="">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 class=""><span 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="">><br class="">> 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. 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=""></span>> URL:<span class="Apple-converted-space"> </span><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" class="">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 class=""><span 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=""></span>> URL:<span class="Apple-converted-space"> </span><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" class="">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 class=""><div class=""><div class="h5">> ==============================================================================<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="">> +; 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=""><br class=""></div></div>... which has been fixed in r245589.<br class=""></blockquote><div class=""><br class="">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,</div></div></div></blockquote><div><br class=""></div><div>Not really, Duncan (I think?) added a verifier check to the same effect as the assertion recently, so it is no longer legal to have wrong debug locations. “No debug locations” is more of a gray area of course.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""> but at least it expresses a relatively limited constraint which this IR file satisfies, even with this missing location)<br class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class=""><div class="h5"><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=tCvabjHLRgtE8pYEwk_4rnKJHHe7ViXrRrU8PtnORI0&s=lRfYUH6akjutgNevAQG4U-M5kYf6yT8W4Lb1_BbJlyw&e=" rel="noreferrer" target="_blank" class="">llvm.dbg.cu</a><span class="Apple-converted-space"> </span>= !{!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="">><span class="Apple-converted-space"> </span><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class=""></div></div>><span class="Apple-converted-space"> </span><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" class="">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 class=""><div class="HOEnZb"><div class="h5"><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=tCvabjHLRgtE8pYEwk_4rnKJHHe7ViXrRrU8PtnORI0&s=6dVdixERc2LdcI7aGCcm3eNOlaVsaVEAOuP3ntHU4i8&e=" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a></div></div></blockquote></div></div></blockquote></div><br class=""></body></html>