<div dir="ltr">I agree this would improve debugging, but will make sample pgo worse as it does not use column number but discriminator. But for cases like this, the then/else branches are usually small, so they are likely to be if-converted. So I guess the impact to sample pgo would be small.<div><br></div><div>Dehao</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 9, 2016 at 10:33 AM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A further improvement to this would be to check for two locations with identical line numbers and scopes. If the two locations only differ in the column field then it would be sufficient to just set the column to 0 while keeping the line number and scope.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- adrian<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Sep 8, 2016, at 2:53 PM, Dehao Chen via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: dehao<br>
> Date: Thu Sep  8 16:53:33 2016<br>
> New Revision: 280995<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=280995&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=280995&view=rev</a><br>
> Log:<br>
> Remove debug info when hoisting instruction from then/else branch.<br>
><br>
> Summary: The hoisted instruction is executed speculatively. It could affect the debugging experience as user would see gdb go into code that may not be expected to execute. It will also affect sample profile accuracy by assigning incorrect frequency to source within then/else branch.<br>
><br>
> Reviewers: davidxl, dblaikie, chandlerc, kcc, echristo<br>
><br>
> Subscribers: mehdi_amini, probinson, eric_niebler, andreadb, llvm-commits<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D24164" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D24164</a><br>
><br>
> Added:<br>
>    llvm/trunk/test/Transforms/<wbr>SimplifyCFG/remove-debug.ll<br>
> Modified:<br>
>    llvm/trunk/lib/Transforms/<wbr>Utils/SimplifyCFG.cpp<br>
><br>
> Modified: llvm/trunk/lib/Transforms/<wbr>Utils/SimplifyCFG.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=280995&r1=280994&r2=280995&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/Utils/SimplifyCFG.<wbr>cpp?rev=280995&r1=280994&r2=<wbr>280995&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/lib/Transforms/<wbr>Utils/SimplifyCFG.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/<wbr>Utils/SimplifyCFG.cpp Thu Sep  8 16:53:33 2016<br>
> @@ -1242,6 +1242,14 @@ static bool HoistThenElseCodeToIf(Branch<br>
>                            LLVMContext::MD_<wbr>dereferenceable_or_null,<br>
>                            LLVMContext::MD_mem_parallel_<wbr>loop_access};<br>
>     combineMetadata(I1, I2, KnownIDs);<br>
> +<br>
> +    // If the debug loc for I1 and I2 are different, as we are combining them<br>
> +    // into one instruction, we do not want to select debug loc randomly from<br>
> +    // I1 or I2. Instead, we set the 0-line DebugLoc to note that we do not<br>
> +    // know the debug loc of the hoisted instruction.<br>
> +    if (!isa<CallInst>(I1) &&  I1->getDebugLoc() != I2->getDebugLoc())<br>
> +      I1->setDebugLoc(DebugLoc());<br>
> +<br>
>     I2->eraseFromParent();<br>
>     Changed = true;<br>
><br>
><br>
> Added: llvm/trunk/test/Transforms/<wbr>SimplifyCFG/remove-debug.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/remove-debug.ll?rev=280995&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Transforms/SimplifyCFG/remove-<wbr>debug.ll?rev=280995&view=auto</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/test/Transforms/<wbr>SimplifyCFG/remove-debug.ll (added)<br>
> +++ llvm/trunk/test/Transforms/<wbr>SimplifyCFG/remove-debug.ll Thu Sep  8 16:53:33 2016<br>
> @@ -0,0 +1,83 @@<br>
> +; RUN: opt < %s -simplifycfg -S | FileCheck %s<br>
> +<br>
> +; TODO: Track the acutal DebugLoc of the hoisted instruction when no-line<br>
> +; DebugLoc is supported (<a href="https://reviews.llvm.org/D24180" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D24180</a>)<br>
> +; CHECK: line: 6<br>
> +; CHECK-NOT: line: 7<br>
> +; CHECK: line: 8<br>
> +; CHECK: line: 9<br>
> +; CHECK-NOT: line: 10<br>
> +; CHECK: line: 11<br>
> +<br>
> +; Checks if the debug info for hoisted "x = i" is removed<br>
> +; int x;<br>
> +; void bar();<br>
> +; void baz();<br>
> +;<br>
> +; void foo(int i) {<br>
> +;   if (i == 0) {<br>
> +;     x = i;<br>
> +;     bar();<br>
> +;   } else {<br>
> +;     x = i;<br>
> +;     baz();<br>
> +;   }<br>
> +; }<br>
> +<br>
> +target triple = "x86_64-unknown-linux-gnu"<br>
> +<br>
> +@x = global i32 0, align 4<br>
> +<br>
> +; Function Attrs: uwtable<br>
> +define void @_Z3fooi(i32) #0 !dbg !6 {<br>
> +  %2 = alloca i32, align 4<br>
> +  store i32 %0, i32* %2, align 4, !tbaa !8<br>
> +  %3 = load i32, i32* %2, align 4, !dbg !12, !tbaa !8<br>
> +  %4 = icmp eq i32 %3, 0, !dbg !13<br>
> +  br i1 %4, label %5, label %7, !dbg !12<br>
> +<br>
> +; <label>:5:<br>
> +  %6 = load i32, i32* %2, align 4, !dbg !14, !tbaa !8<br>
> +  store i32 %6, i32* @x, align 4, !dbg !15, !tbaa !8<br>
> +  call void @_Z3barv(), !dbg !16<br>
> +  br label %9, !dbg !17<br>
> +<br>
> +; <label>:7:<br>
> +  %8 = load i32, i32* %2, align 4, !dbg !18, !tbaa !8<br>
> +  store i32 %8, i32* @x, align 4, !dbg !19, !tbaa !8<br>
> +  call void @_Z3bazv(), !dbg !20<br>
> +  br label %9<br>
> +<br>
> +; <label>:9:<br>
> +  ret void, !dbg !21<br>
> +}<br>
> +<br>
> +declare void @_Z3barv() #1<br>
> +<br>
> +declare void @_Z3bazv() #1<br>
> +<br>
> +!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
> +!llvm.module.flags = !{!3, !4}<br>
> +<br>
> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)<br>
> +!1 = !DIFile(filename: "a", directory: "b/")<br>
> +!2 = !{}<br>
> +!3 = !{i32 2, !"Dwarf Version", i32 4}<br>
> +!4 = !{i32 2, !"Debug Info Version", i32 3}<br>
> +!5 = !{}<br>
> +!6 = distinct !DISubprogram(unit: !0)<br>
> +!7 = !DISubroutineType(types: !2)<br>
> +!8 = !{!9, !9, i64 0}<br>
> +!9 = !{!"int", !10, i64 0}<br>
> +!10 = !{!"omnipotent char", !11, i64 0}<br>
> +!11 = !{!"Simple C++ TBAA"}<br>
> +!12 = !DILocation(line: 6, column: 7, scope: !6)<br>
> +!13 = !DILocation(line: 6, column: 9, scope: !6)<br>
> +!14 = !DILocation(line: 7, column: 9, scope: !6)<br>
> +!15 = !DILocation(line: 7, column: 7, scope: !6)<br>
> +!16 = !DILocation(line: 8, column: 5, scope: !6)<br>
> +!17 = !DILocation(line: 9, column: 3, scope: !6)<br>
> +!18 = !DILocation(line: 10, column: 9, scope: !6)<br>
> +!19 = !DILocation(line: 10, column: 7, scope: !6)<br>
> +!20 = !DILocation(line: 11, column: 5, scope: !6)<br>
> +!21 = !DILocation(line: 13, column: 1, scope: !6)<br>
><br>
><br>
> ______________________________<wbr>_________________<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/<wbr>mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></blockquote></div><br></div>