2017-08-19 02:07:00 +08:00
; RUN: llc %s -stop-after=livedebugvars -o %t
; RUN: cat %t | FileCheck %s
;
; Test that we can emit debug info for large values that are split
; up across multiple registers by the SelectionDAG type legalizer.
;
; // Compile with -O1 -m32.
; long long foo (long long a, long long b)
; {
; long long res = b+1;
; if ( a == b )
; return res;
; return 0;
; }
;
2018-10-31 07:28:27 +08:00
; CHECK-DAG: DBG_VALUE ${{[a-z]+}}, $noreg, !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !{{[0-9]+}}
; CHECK-DAG: DBG_VALUE ${{[a-z]+}}, $noreg, !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_fragment, 32, 32), debug-location !{{[0-9]+}}
2017-08-19 02:07:00 +08:00
; ModuleID = 'sdagsplit-1.c'
target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
target triple = "i386"
; Function Attrs: nounwind readnone
define i64 @foo ( i64 %a , i64 %b ) local_unnamed_addr #0 !dbg !8 {
entry:
tail call void @llvm.dbg.value ( metadata i64 %a , metadata !13 , metadata !16 ) , !dbg !17
tail call void @llvm.dbg.value ( metadata i64 %b , metadata !14 , metadata !16 ) , !dbg !18
%cmp = icmp eq i64 %a , %b , !dbg !20
%add = add nsw i64 %b , 1 , !dbg !22
[DebugInfo] Sink related dbg users when sinking in InstCombine
Summary:
When sinking an instruction in InstCombine we now also sink
the DbgInfoIntrinsics that are using the sunken value.
Example)
When sinking the load in this input
bb.X:
%0 = load i64, i64* %start, align 4, !dbg !31
tail call void @llvm.dbg.value(metadata i64 %0, ...)
br i1 %cond, label %for.end, label %for.body.lr.ph
for.body.lr.ph:
br label %for.body
we now also move the dbg.value, like this
bb.X:
br i1 %cond, label %for.end, label %for.body.lr.ph
for.body.lr.ph:
%0 = load i64, i64* %start, align 4, !dbg !31
tail call void @llvm.dbg.value(metadata i64 %0, ...)
br label %for.body
In the past we haven't moved the dbg.value so we got
bb.X:
tail call void @llvm.dbg.value(metadata i64 %0, ...)
br i1 %cond, label %for.end, label %for.body.lr.ph
for.body.lr.ph:
%0 = load i64, i64* %start, align 4, !dbg !31
br label %for.body
So in the past we got a debug-use before the def of %0.
And that dbg.value was also on the path jumping to %for.end, for
which %0 never was defined.
CodeGenPrepare normally comes to rescue later (when not moving
the dbg.value), since it moves dbg.value instrinsics quite
brutally, without really analysing if it is correct to move
the intrinsic (see PR31878).
So at the moment this patch isn't expected to have much impact,
besides that it is moving the dbg.value already in opt, making
the IR look more sane directly.
This can be seen as a preparation to (hopefully) make it possible
to turn off CodeGenPrepare::placeDbgValues later as a solution
to PR31878.
I also adjusted test/DebugInfo/X86/sdagsplit-1.ll to make the
IR in the test case up-to-date with this behavior in InstCombine.
Reviewers: rnk, vsk, aprantl
Reviewed By: vsk, aprantl
Subscribers: mattd, JDevlieghere, llvm-commits
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D45425
llvm-svn: 330243
2018-04-18 16:08:04 +08:00
tail call void @llvm.dbg.value ( metadata i64 %add , metadata !15 , metadata !16 ) , !dbg !19
2017-08-19 02:07:00 +08:00
%retval.0 = select i1 %cmp , i64 %add , i64 0 , !dbg !23
ret i64 %retval.0 , !dbg !24
}
; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value ( metadata , metadata , metadata ) #1
attributes #0 = { nounwind readnone }
attributes #1 = { nounwind readnone s p e c u l a t a b l e }
!llvm.dbg.cu = ! { !0 }
!llvm.module.flags = ! { !3 , !4 , !5 , !6 }
!llvm.ident = ! { !7 }
!0 = distinct !DICompileUnit ( language: D W _ L A N G _ C 99 , file: !1 , producer: "clang version 6.0.0 " , isOptimized: true , runtimeVersion: 0 , emissionKind: F u l l D e b u g , enums: !2 )
!1 = !DIFile ( filename: "sdagsplit-1.c" , directory: "/X86" )
!2 = ! { }
!3 = ! { i32 1 , !"NumRegisterParameters" , i32 0 }
!4 = ! { i32 2 , !"Dwarf Version" , i32 2 }
!5 = ! { i32 2 , !"Debug Info Version" , i32 3 }
!6 = ! { i32 1 , !"wchar_size" , i32 4 }
!7 = ! { !"clang version 6.0.0 " }
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
!8 = distinct !DISubprogram ( name: "foo" , scope: !1 , file: !1 , line: 2 , type: !9 , isLocal: false , isDefinition: true , scopeLine: 3 , flags: D I F l a g P r o t o t y p e d , isOptimized: true , unit: !0 , retainedNodes: !12 )
2017-08-19 02:07:00 +08:00
!9 = !DISubroutineType ( types: !10 )
!10 = ! { !11 , !11 , !11 }
!11 = !DIBasicType ( name: "long long int" , size: 64 , encoding: D W _ A T E _ s i g n e d )
!12 = ! { !13 , !14 , !15 }
!13 = !DILocalVariable ( name: "a" , arg: 1 , scope: !8 , file: !1 , line: 2 , type: !11 )
!14 = !DILocalVariable ( name: "b" , arg: 2 , scope: !8 , file: !1 , line: 2 , type: !11 )
!15 = !DILocalVariable ( name: "res" , scope: !8 , file: !1 , line: 4 , type: !11 )
!16 = !DIExpression ( )
!17 = !DILocation ( line: 2 , column: 26 , scope: !8 )
!18 = !DILocation ( line: 2 , column: 39 , scope: !8 )
!19 = !DILocation ( line: 4 , column: 12 , scope: !8 )
!20 = !DILocation ( line: 5 , column: 9 , scope: !21 )
!21 = distinct !DILexicalBlock ( scope: !8 , file: !1 , line: 5 , column: 7 )
!22 = !DILocation ( line: 4 , column: 19 , scope: !8 )
!23 = !DILocation ( line: 5 , column: 7 , scope: !8 )
!24 = !DILocation ( line: 8 , column: 1 , scope: !8 )