[llvm] r320216 - Fix out-of-order stepping behavior in programs with sunk instructions.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 09:55:48 PST 2017


FWIW, generally I'm a bit uncertain about changing/dropping locations to
improve stepping behavior. If the optimizer did reorder instructions I
think it's potentialyl valuable to show that.

The main (compelling to me, at least) motivation for stripping/shifting
locations seems to be accurate profiles, which only applies when an
instruction is moved between basic blocks - it sounds like that is the case
here, so it's fine, but just thought I'd check. Is that the case that this
fix/change applies to instructions moving between basic blocks?

On Fri, Dec 8, 2017 at 4:17 PM Paul Robinson via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: probinson
> Date: Fri Dec  8 16:17:01 2017
> New Revision: 320216
>
> URL: http://llvm.org/viewvc/llvm-project?rev=320216&view=rev
> Log:
> Fix out-of-order stepping behavior in programs with sunk instructions.
>
> MachineSink attempts to place instructions near the basic blocks where
> they are needed.  Once an instruction has been sunk, its location
> relative to other instructions no longer is consistent with the
> original source code. In order to ensure correct stepping in the
> debugger, the debug location for sunk instructions is either merged
> with the insertion point or erased if the target successor block is
> empty.
>
> Originally submitted as r318679, revised to fix sanitizer failure and
> improve testing.
>
> Patch by Matthew Voss!
>
> Differential Revision: https://reviews.llvm.org/D39933
>
> Added:
>     llvm/trunk/test/CodeGen/X86/machinesink-merge-debuginfo.ll
>     llvm/trunk/test/CodeGen/X86/machinesink-null-debuginfo.ll
> Modified:
>     llvm/trunk/lib/CodeGen/MachineSink.cpp
>
> Modified: llvm/trunk/lib/CodeGen/MachineSink.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineSink.cpp?rev=320216&r1=320215&r2=320216&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineSink.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineSink.cpp Fri Dec  8 16:17:01 2017
> @@ -38,6 +38,7 @@
>  #include "llvm/CodeGen/TargetSubtargetInfo.h"
>  #include "llvm/IR/BasicBlock.h"
>  #include "llvm/IR/LLVMContext.h"
> +#include "llvm/IR/DebugInfoMetadata.h"
>  #include "llvm/Pass.h"
>  #include "llvm/Support/BranchProbability.h"
>  #include "llvm/Support/CommandLine.h"
> @@ -868,11 +869,20 @@ bool MachineSinking::SinkInstruction(Mac
>    SmallVector<MachineInstr *, 2> DbgValuesToSink;
>    collectDebugValues(MI, DbgValuesToSink);
>
> +  // Merge or erase debug location to ensure consistent stepping in
> profilers
> +  // and debuggers.
> +  if (!SuccToSinkTo->empty() && InsertPos != SuccToSinkTo->end())
> +    MI.setDebugLoc(DILocation::getMergedLocation(MI.getDebugLoc(),
> +
>  InsertPos->getDebugLoc()));
> +  else
> +    MI.setDebugLoc(DebugLoc());
> +
> +
>    // Move the instruction.
>    SuccToSinkTo->splice(InsertPos, ParentBlock, MI,
>                         ++MachineBasicBlock::iterator(MI));
>
> -  // Move debug values.
> +  // Move previously adjacent debug value instructions to the insert
> position.
>    for (SmallVectorImpl<MachineInstr *>::iterator DBI =
> DbgValuesToSink.begin(),
>           DBE = DbgValuesToSink.end(); DBI != DBE; ++DBI) {
>      MachineInstr *DbgMI = *DBI;
>
> Added: llvm/trunk/test/CodeGen/X86/machinesink-merge-debuginfo.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/machinesink-merge-debuginfo.ll?rev=320216&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/machinesink-merge-debuginfo.ll (added)
> +++ llvm/trunk/test/CodeGen/X86/machinesink-merge-debuginfo.ll Fri Dec  8
> 16:17:01 2017
> @@ -0,0 +1,56 @@
> +; RUN: llc -simplify-mir -stop-after=machine-sink < %s -o - | FileCheck %s
> +
> +; ModuleID = 'test-sink-debug.cpp'
> +source_filename = "test-sink-debug.cpp"
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-unknown-linux-gnu"
> +
> +; Function Attrs: nounwind readnone uwtable
> +define double @_Z3fooddb(double %x, double %y, i1 zeroext %c)
> local_unnamed_addr !dbg !7 {
> +  tail call void @llvm.dbg.value(metadata double %x, metadata !13,
> metadata !DIExpression()), !dbg !16
> +  tail call void @llvm.dbg.value(metadata double %y, metadata !14,
> metadata !DIExpression()), !dbg !16
> +  tail call void @llvm.dbg.value(metadata i1 %c, metadata !15, metadata
> !DIExpression()), !dbg !16
> +  %a = fdiv double %x, 3.000000e+00
> +  %b = fdiv double %y, 5.000000e+00, !dbg !17
> +  br i1 %c, label %first, label %second
> +first:
> +  %e = fadd double %a, 1.000000e+00
> +  br label %final
> +second:
> +  %f = fadd double %b, 1.000000e+00, !dbg !17
> +; CHECK:  debug-location !17
> +; CHECK:  debug-location !17
> +  br label %final
> +final:
> +  %cond = phi double [%e, %first], [%f, %second]
> +  %d = fadd double %cond, 1.000000e+00
> +  ret double %d
> +}
> +
> +; Function Attrs: nounwind readnone speculatable
> +declare void @llvm.dbg.value(metadata, metadata, metadata) #1
> +
> +attributes #1 = { nounwind readnone speculatable }
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!3, !4, !5}
> +!llvm.ident = !{!6}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
> producer: "clang version 6.0.0 (trunk 313291)", isOptimized: true,
> runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
> +!1 = !DIFile(filename: "test-sink-debug.cpp", directory: "/tmp")
> +!2 = !{}
> +!3 = !{i32 2, !"Dwarf Version", i32 4}
> +!4 = !{i32 2, !"Debug Info Version", i32 3}
> +!5 = !{i32 1, !"wchar_size", i32 4}
> +!6 = !{!"clang version 6.0.0 (trunk 313291)"}
> +!7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooddb", scope:
> !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true,
> scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0,
> variables: !12)
> +!8 = !DISubroutineType(types: !9)
> +!9 = !{!10, !10, !10, !11}
> +!10 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
> +!11 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
> +!12 = !{!13, !14, !15}
> +!13 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !1, line: 1,
> type: !10)
> +!14 = !DILocalVariable(name: "y", arg: 2, scope: !7, file: !1, line: 1,
> type: !10)
> +!15 = !DILocalVariable(name: "c", arg: 3, scope: !7, file: !1, line: 1,
> type: !11)
> +!16 = !DILocation(line: 1, column: 19, scope: !7)
> +!17 = !DILocation(line: 2, column: 26, scope: !7)
>
> Added: llvm/trunk/test/CodeGen/X86/machinesink-null-debuginfo.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/machinesink-null-debuginfo.ll?rev=320216&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/machinesink-null-debuginfo.ll (added)
> +++ llvm/trunk/test/CodeGen/X86/machinesink-null-debuginfo.ll Fri Dec  8
> 16:17:01 2017
> @@ -0,0 +1,49 @@
> +; RUN: llc -simplify-mir -stop-after=machine-sink < %s -o - | FileCheck %s
> +
> +; ModuleID = 'test-sink-debug.cpp'
> +source_filename = "test-sink-debug.cpp"
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-unknown-linux-gnu"
> +
> +; Function Attrs: nounwind readnone uwtable
> +define double @_Z3fooddb(double %x, double %y, i1 zeroext %c)
> local_unnamed_addr !dbg !7 {
> +  tail call void @llvm.dbg.value(metadata double %x, metadata !13,
> metadata !DIExpression()), !dbg !16
> +  tail call void @llvm.dbg.value(metadata double %y, metadata !14,
> metadata !DIExpression()), !dbg !17
> +  tail call void @llvm.dbg.value(metadata i1 %c, metadata !15, metadata
> !DIExpression()), !dbg !18
> +  %a = fdiv double %x, 3.000000e+00
> +  %b = fdiv double %y, 5.000000e+00, !dbg !21
> +  %cond = select i1 %c,  double %a, double %b
> +; CHECK-NOT: debug-location !21
> +  ret double %cond, !dbg !22
> +}
> +
> +; Function Attrs: nounwind readnone speculatable
> +declare void @llvm.dbg.value(metadata, metadata, metadata) #1
> +
> +attributes #1 = { nounwind readnone speculatable }
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!3, !4, !5}
> +!llvm.ident = !{!6}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
> producer: "clang version 6.0.0 (trunk 313291)", isOptimized: true,
> runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
> +!1 = !DIFile(filename: "test-sink-debug.cpp", directory: "/tmp")
> +!2 = !{}
> +!3 = !{i32 2, !"Dwarf Version", i32 4}
> +!4 = !{i32 2, !"Debug Info Version", i32 3}
> +!5 = !{i32 1, !"wchar_size", i32 4}
> +!6 = !{!"clang version 6.0.0 (trunk 313291)"}
> +!7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooddb", scope:
> !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true,
> scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0,
> variables: !12)
> +!8 = !DISubroutineType(types: !9)
> +!9 = !{!10, !10, !10, !11}
> +!10 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
> +!11 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
> +!12 = !{!13, !14, !15}
> +!13 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !1, line: 1,
> type: !10)
> +!14 = !DILocalVariable(name: "y", arg: 2, scope: !7, file: !1, line: 1,
> type: !10)
> +!15 = !DILocalVariable(name: "c", arg: 3, scope: !7, file: !1, line: 1,
> type: !11)
> +!16 = !DILocation(line: 1, column: 19, scope: !7)
> +!17 = !DILocation(line: 1, column: 29, scope: !7)
> +!18 = !DILocation(line: 1, column: 37, scope: !7)
> +!21 = !DILocation(line: 2, column: 26, scope: !7)
> +!22 = !DILocation(line: 2, column: 3, scope: !7)
>
>
> _______________________________________________
> 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/20171211/8405b3c6/attachment.html>


More information about the llvm-commits mailing list