[llvm] r280995 - Remove debug info when hoisting instruction from then/else branch.

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 11:01:53 PDT 2016


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.

Dehao

On Fri, Sep 9, 2016 at 10:33 AM, Adrian Prantl <aprantl at apple.com> wrote:

> 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.
>
> -- adrian
>
> > On Sep 8, 2016, at 2:53 PM, Dehao Chen via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
> >
> > Author: dehao
> > Date: Thu Sep  8 16:53:33 2016
> > New Revision: 280995
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=280995&view=rev
> > Log:
> > Remove debug info when hoisting instruction from then/else branch.
> >
> > 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.
> >
> > Reviewers: davidxl, dblaikie, chandlerc, kcc, echristo
> >
> > Subscribers: mehdi_amini, probinson, eric_niebler, andreadb, llvm-commits
> >
> > Differential Revision: https://reviews.llvm.org/D24164
> >
> > Added:
> >    llvm/trunk/test/Transforms/SimplifyCFG/remove-debug.ll
> > Modified:
> >    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
> >
> > Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
> Transforms/Utils/SimplifyCFG.cpp?rev=280995&r1=280994&r2=280995&view=diff
> > ============================================================
> ==================
> > --- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
> > +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Thu Sep  8 16:53:33
> 2016
> > @@ -1242,6 +1242,14 @@ static bool HoistThenElseCodeToIf(Branch
> >                            LLVMContext::MD_dereferenceable_or_null,
> >                            LLVMContext::MD_mem_parallel_loop_access};
> >     combineMetadata(I1, I2, KnownIDs);
> > +
> > +    // If the debug loc for I1 and I2 are different, as we are
> combining them
> > +    // into one instruction, we do not want to select debug loc
> randomly from
> > +    // I1 or I2. Instead, we set the 0-line DebugLoc to note that we do
> not
> > +    // know the debug loc of the hoisted instruction.
> > +    if (!isa<CallInst>(I1) &&  I1->getDebugLoc() != I2->getDebugLoc())
> > +      I1->setDebugLoc(DebugLoc());
> > +
> >     I2->eraseFromParent();
> >     Changed = true;
> >
> >
> > Added: llvm/trunk/test/Transforms/SimplifyCFG/remove-debug.ll
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/
> Transforms/SimplifyCFG/remove-debug.ll?rev=280995&view=auto
> > ============================================================
> ==================
> > --- llvm/trunk/test/Transforms/SimplifyCFG/remove-debug.ll (added)
> > +++ llvm/trunk/test/Transforms/SimplifyCFG/remove-debug.ll Thu Sep  8
> 16:53:33 2016
> > @@ -0,0 +1,83 @@
> > +; RUN: opt < %s -simplifycfg -S | FileCheck %s
> > +
> > +; TODO: Track the acutal DebugLoc of the hoisted instruction when
> no-line
> > +; DebugLoc is supported (https://reviews.llvm.org/D24180)
> > +; CHECK: line: 6
> > +; CHECK-NOT: line: 7
> > +; CHECK: line: 8
> > +; CHECK: line: 9
> > +; CHECK-NOT: line: 10
> > +; CHECK: line: 11
> > +
> > +; Checks if the debug info for hoisted "x = i" is removed
> > +; int x;
> > +; void bar();
> > +; void baz();
> > +;
> > +; void foo(int i) {
> > +;   if (i == 0) {
> > +;     x = i;
> > +;     bar();
> > +;   } else {
> > +;     x = i;
> > +;     baz();
> > +;   }
> > +; }
> > +
> > +target triple = "x86_64-unknown-linux-gnu"
> > +
> > + at x = global i32 0, align 4
> > +
> > +; Function Attrs: uwtable
> > +define void @_Z3fooi(i32) #0 !dbg !6 {
> > +  %2 = alloca i32, align 4
> > +  store i32 %0, i32* %2, align 4, !tbaa !8
> > +  %3 = load i32, i32* %2, align 4, !dbg !12, !tbaa !8
> > +  %4 = icmp eq i32 %3, 0, !dbg !13
> > +  br i1 %4, label %5, label %7, !dbg !12
> > +
> > +; <label>:5:
> > +  %6 = load i32, i32* %2, align 4, !dbg !14, !tbaa !8
> > +  store i32 %6, i32* @x, align 4, !dbg !15, !tbaa !8
> > +  call void @_Z3barv(), !dbg !16
> > +  br label %9, !dbg !17
> > +
> > +; <label>:7:
> > +  %8 = load i32, i32* %2, align 4, !dbg !18, !tbaa !8
> > +  store i32 %8, i32* @x, align 4, !dbg !19, !tbaa !8
> > +  call void @_Z3bazv(), !dbg !20
> > +  br label %9
> > +
> > +; <label>:9:
> > +  ret void, !dbg !21
> > +}
> > +
> > +declare void @_Z3barv() #1
> > +
> > +declare void @_Z3bazv() #1
> > +
> > +!llvm.dbg.cu = !{!0}
> > +!llvm.module.flags = !{!3, !4}
> > +
> > +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
> > +!1 = !DIFile(filename: "a", directory: "b/")
> > +!2 = !{}
> > +!3 = !{i32 2, !"Dwarf Version", i32 4}
> > +!4 = !{i32 2, !"Debug Info Version", i32 3}
> > +!5 = !{}
> > +!6 = distinct !DISubprogram(unit: !0)
> > +!7 = !DISubroutineType(types: !2)
> > +!8 = !{!9, !9, i64 0}
> > +!9 = !{!"int", !10, i64 0}
> > +!10 = !{!"omnipotent char", !11, i64 0}
> > +!11 = !{!"Simple C++ TBAA"}
> > +!12 = !DILocation(line: 6, column: 7, scope: !6)
> > +!13 = !DILocation(line: 6, column: 9, scope: !6)
> > +!14 = !DILocation(line: 7, column: 9, scope: !6)
> > +!15 = !DILocation(line: 7, column: 7, scope: !6)
> > +!16 = !DILocation(line: 8, column: 5, scope: !6)
> > +!17 = !DILocation(line: 9, column: 3, scope: !6)
> > +!18 = !DILocation(line: 10, column: 9, scope: !6)
> > +!19 = !DILocation(line: 10, column: 7, scope: !6)
> > +!20 = !DILocation(line: 11, column: 5, scope: !6)
> > +!21 = !DILocation(line: 13, column: 1, scope: !6)
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160909/ebbf2e75/attachment.html>


More information about the llvm-commits mailing list