Skip to content

Commit

Permalink
[LiveDebugValues][NFC] Add additional tests
Browse files Browse the repository at this point in the history
These were supposed to be in 0caeaff and D83054, but a fat-fingered
error when git-adding missed them. Ooops.
  • Loading branch information
jmorse committed Sep 11, 2020
1 parent 48b510c commit 0825fa9
Show file tree
Hide file tree
Showing 2 changed files with 309 additions and 0 deletions.
113 changes: 113 additions & 0 deletions llvm/test/DebugInfo/MIR/X86/livedebugvalues_load_in_loop.mir
@@ -0,0 +1,113 @@
--- |
; RUN: llc %s -march=x86-64 -run-pass=livedebugvalues -o - -experimental-debug-variable-locations -emulate-old-livedebugvalues=0 | FileCheck %s -implicit-check-not=DBG_VALUE

; Sometimes, variables can have multiple locations, and when control flow
; merges LiveDebugValues has a hard time picking which one the variable lives
; in. Test two of these scenarios that old LiveDebugValues can't handle: when
; a value is in two registers, and when a value is both in a register and
; on the stack.

; In a register:

; CHECK-LABEL: bb.0.entry:
; CHECK: DBG_VALUE $rdi, $noreg, !16, !DIExpression()
; CHECK-LABEL: bb.1.bb1:
; CHECK: DBG_VALUE $rbp, $noreg, !16, !DIExpression()
; CHECK: DBG_VALUE $rbp, $noreg, !16, !DIExpression()
; CHECK-LABEL: bb.2.bb2:
; CHECK: DBG_VALUE $rbp, $noreg, !16, !DIExpression()
; CHECK-LABEL: bb.3.bb3:
; CHECK: DBG_VALUE $rbp, $noreg, !16, !DIExpression()

; On the stack: we move from $rbp to a stack slot in bb4, but join back on
; $rbp in bb6.

; CHECK-LABEL: bb.4:
; CHECK: DBG_VALUE $rbp, $noreg, !16, !DIExpression()
; CHECK: DBG_VALUE $rsp, 0, !16, !DIExpression()
; CHECK-LABEL: bb.5:
; CHECK: DBG_VALUE $rbp, $noreg, !16, !DIExpression()
; CHECK-LABEL: bb.6:
; CHECK: DBG_VALUE $rbp, $noreg, !16, !DIExpression()

declare i64 @bees(i64 %arg);

define i32 @_Z8bb_to_bb(i64 %arg) local_unnamed_addr !dbg !12 {
entry:
br label %bb1, !dbg !17
bb1:
br label %bb2, !dbg !17
bb2:
br label %bb3, !dbg !17
bb3:
ret i32 0, !dbg !17
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!7, !8, !9, !10}
!llvm.ident = !{!11}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, debugInfoForProfiling: true, nameTableKind: None)
!1 = !DIFile(filename: "main.cpp", directory: "F:\")
!2 = !{}
!3 = !{!4}
!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
!5 = distinct !DIGlobalVariable(name: "start", scope: !0, file: !1, line: 4, type: !6, isLocal: false, isDefinition: true)
!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!7 = !{i32 2, !"Dwarf Version", i32 4}
!8 = !{i32 2, !"Debug Info Version", i32 3}
!9 = !{i32 1, !"wchar_size", i32 2}
!10 = !{i32 7, !"PIC Level", i32 2}
!11 = !{!"clang version 10.0.0"}
!12 = distinct !DISubprogram(name: "bb_to_bb", linkageName: "bb_to_bb", scope: !1, file: !1, line: 6, type: !13, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
!13 = !DISubroutineType(types: !14)
!14 = !{!6, !6}
!15 = !{!16}
!16 = !DILocalVariable(name: "myVar", scope: !12, file: !1, line: 7, type: !6)
!17 = !DILocation(line: 10, scope: !12)

...
---
name: _Z8bb_to_bb
tracksRegLiveness: true
liveins:
- { reg: '$rdi', virtual-reg: '' }
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
body: |
bb.0.entry:
liveins: $rdi
successors: %bb.1, %bb.2
DBG_VALUE $rdi, $noreg, !16, !DIExpression(), debug-location !17
$rbp = MOV64rr $rdi, debug-location !17
dead $rcx = MOV64ri 0, debug-location !17
CALL64pcrel32 @bees, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax, debug-location !17
CMP64ri8 renamable $rax, 1, implicit-def $eflags, debug-location !17
JCC_1 %bb.2, 4, implicit killed $eflags, debug-location !17
bb.1.bb1:
liveins: $rax, $rbp
successors: %bb.3
$rbp = MOV64ri 0, debug-location !17
DBG_VALUE $rbp, $noreg, !16, !DIExpression(), debug-location !17
JMP_1 %bb.3
bb.2.bb2:
liveins: $rax, $rbp
successors: %bb.3
$rax = MOV64ri 0, debug-location !17
bb.3.bb3:
liveins: $rax, $rbp
$rdi = MOV64rr $rbp, debug-location !17
CALL64pcrel32 @bees, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax, debug-location !17
CMP64ri8 renamable $rax, 1, implicit-def $eflags, debug-location !17
JCC_1 %bb.5, 4, implicit killed $eflags, debug-location !17
bb.4:
liveins: $rax, $rbp
MOV64mr $rsp, 1, $noreg, 8, $noreg, killed renamable $rbp :: (store 8 into %stack.0)
JMP_1 %bb.6
bb.5:
liveins: $rax, $rbp
bb.6:
liveins: $rax, $rbp
RETQ $rax, debug-location !17
...
196 changes: 196 additions & 0 deletions llvm/test/DebugInfo/MIR/X86/livedebugvalues_many_loop_heads.mir
@@ -0,0 +1,196 @@
--- |
; RUN: llc %s -march=x86-64 -run-pass=livedebugvalues -o - -experimental-debug-variable-locations | FileCheck %s -implicit-check-not=DBG_VALUE

; The MIR below represents a pathalogical case for value-tracking
; LiveDebugValues. The code structure is eight nested loops, with loop heads
; from bb.1 to bb.8, a central block bb.9 that does nothing, and loop ends
; from bb.10 to bb.17. The CMP's and jumps might be broken; the only
; important part is that it looks like nested loops to LiveDebugValues.
;
; The variable location is always $rsi, which enters the function live.
; There's also a def of $rsi in bb.14, in a loop tail, half way into the
; loop nest.s.
;
; This presents a serious problem: the outer four loops each implicitly have
; a PHI value for $rsi, because the block could be entered on a path straight
; from entry, or from bb.14 where $rsi is def'd. While the innermost four
; loops have a value of $rsi that is live-through each loop from bb.5
; onwards.
;
; Value-tracking LiveDebugValues _must_ correctly identify each PHI value.
; Observe the DBG_VALUE in bb.2: this variable location musn't be propagated
; any further, because there's a path to either successor that goes through
; bb.14 where the value is overwritten.Value tracking needs to identify the
; PHI value on entry to the block; and that each successor has a different
; PHI value in that register.
;
; Likewise, we mustn't identify values as PHIs which aren't. Entering bb.5
; has a PHI value (from bb.4) in $rsi. There are no paths to bb.5 that pass
; through the clobbering bb.14, which don't also pass through bb.4: thus
; that value is live-through the innermost four loops. If we
; over-approximated where PHIs happened, we would lose variable location
; coverage here, by not propagating the variable location through the inner
; loops.
;
; Getting this right requires the lattice descent (described in the
; implementation) to search loop head PHI values, until one is found that is
; live-through a loop.

; This location in bb.2 should not be propagated further,
; CHECK-LABEL: bb.2:
; CHECK: DBG_VALUE $rsi, $noreg

; This location should be live through the inner loops, til bb.14
; CHECK-LABEL: bb.5:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.6:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.7:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.8:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.9:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.10:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.11:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.12:
; CHECK: DBG_VALUE $rsi, $noreg
; CHECK-LABEL: bb.13:
; CHECK: DBG_VALUE $rsi, $noreg

declare i64 @bees(i64 %arg);

define i32 @chiasm(i64 %arg) local_unnamed_addr !dbg !12 {
entry:
br label %bb1, !dbg !17
bb1:
br label %bb2, !dbg !17
bb2:
br label %bb3, !dbg !17
bb3:
ret i32 0, !dbg !17
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!7, !8, !9, !10}
!llvm.ident = !{!11}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, debugInfoForProfiling: true, nameTableKind: None)
!1 = !DIFile(filename: "main.cpp", directory: "F:\")
!2 = !{}
!3 = !{!4}
!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
!5 = distinct !DIGlobalVariable(name: "start", scope: !0, file: !1, line: 4, type: !6, isLocal: false, isDefinition: true)
!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!7 = !{i32 2, !"Dwarf Version", i32 4}
!8 = !{i32 2, !"Debug Info Version", i32 3}
!9 = !{i32 1, !"wchar_size", i32 2}
!10 = !{i32 7, !"PIC Level", i32 2}
!11 = !{!"clang version 10.0.0"}
!12 = distinct !DISubprogram(name: "bb_to_bb", linkageName: "bb_to_bb", scope: !1, file: !1, line: 6, type: !13, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
!13 = !DISubroutineType(types: !14)
!14 = !{!6, !6}
!15 = !{!16}
!16 = !DILocalVariable(name: "myVar", scope: !12, file: !1, line: 7, type: !6)
!17 = !DILocation(line: 10, scope: !12)

...
---
name: chiasm
tracksRegLiveness: true
liveins:
- { reg: '$rdi', virtual-reg: '' }
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
body: |
bb.0.entry:
liveins: $rdi, $rsi
bb.1:
liveins: $rsi, $rdi
CMP64ri8 renamable $rdi, 1, implicit-def $eflags, debug-location !17
JCC_1 %bb.17, 4, implicit $eflags, debug-location !17
bb.2:
liveins: $rsi, $rdi
DBG_VALUE $rsi, $noreg, !16, !DIExpression(), debug-location !17
CMP64ri8 renamable $rdi, 2, implicit-def $eflags, debug-location !17
JCC_1 %bb.16, 4, implicit $eflags, debug-location !17
bb.3:
liveins: $rsi, $rdi
CMP64ri8 renamable $rdi, 3, implicit-def $eflags, debug-location !17
JCC_1 %bb.15, 4, implicit $eflags, debug-location !17
bb.4:
liveins: $rsi, $rdi
CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
JCC_1 %bb.14, 4, implicit $eflags, debug-location !17
bb.5:
liveins: $rsi, $rdi
DBG_VALUE $rsi, $noreg, !16, !DIExpression(), debug-location !17
CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
JCC_1 %bb.13, 4, implicit $eflags, debug-location !17
bb.6:
liveins: $rsi, $rdi
CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
JCC_1 %bb.12, 4, implicit $eflags, debug-location !17
bb.7:
liveins: $rsi, $rdi
CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
JCC_1 %bb.11, 4, implicit $eflags, debug-location !17
bb.8:
liveins: $rsi, $rdi
CMP64ri8 renamable $rdi, 4, implicit-def $eflags, debug-location !17
JCC_1 %bb.10, 4, implicit $eflags, debug-location !17
bb.9:
liveins: $rsi, $rdi, $eflags
;$rsi = MOV64ri 0, debug-location !17
;JMP_1 %bb.1, debug-location !17
bb.10:
liveins: $rsi, $rdi, $eflags
JCC_1 %bb.8, 4, implicit $eflags, debug-location !17
bb.11:
liveins: $rsi, $rdi, $eflags
JCC_1 %bb.7, 4, implicit $eflags, debug-location !17
bb.12:
liveins: $rsi, $rdi, $eflags
JCC_1 %bb.6, 4, implicit $eflags, debug-location !17
bb.13:
liveins: $rsi, $rdi, $eflags
JCC_1 %bb.5, 4, implicit $eflags, debug-location !17
bb.14:
liveins: $rsi, $rdi, $eflags
$rsi = MOV64ri 0, debug-location !17
JCC_1 %bb.4, 4, implicit $eflags, debug-location !17
bb.15:
liveins: $rsi, $rdi, $eflags
JCC_1 %bb.3, 4, implicit $eflags, debug-location !17
bb.16:
liveins: $rsi, $rdi, $eflags
JCC_1 %bb.2, 4, implicit $eflags, debug-location !17
bb.17:
liveins: $rsi, $rdi, $eflags
JCC_1 %bb.1, 4, implicit $eflags, debug-location !17
bb.18:
liveins: $rsi, $rdi, $eflags
RETQ
...

0 comments on commit 0825fa9

Please sign in to comment.