1# RUN: llc -start-after=phi-node-elimination -stop-after=virtregrewriter %s -mtriple=x86_64-unknown-unknown -o - | FileCheck %s
2#
3# Test that when a livedebugvars interval crosses a basic block boundary,
4# DBG_VALUEs are created in each covered basic block. In the IR below, control
5# flow moves from the bottom upwards, and the DBG_VALUEs from the entry block
6# to bb.1 become a single range. Check that they're transformed back into two
7# DBG_VALUEs after regalloc.
8
9# These checks look at the entry and bb.1 blocks, and ensure that there is a
10# DBG_VALUE in each.
11
12# CHECK:       ![[VARNUM:[0-9]+]] = !DILocalVariable(name: "b",
13# CHECK-LABEL: name: bar
14# CHECK-LABEL: bb.0.entry:
15# CHECK:       DBG_VALUE $[[SOMEREG:[a-z]+]], $noreg, ![[VARNUM]], !DIExpression()
16# CHECK-NEXT:  JMP_1 %bb.3
17# CHECK-LABEL: bb.1.bb1:
18# CHECK:       DBG_VALUE $[[SOMEREG]], $noreg, ![[VARNUM]], !DIExpression()
19# CHECK-NEXT:  JMP_1 %bb.4
20
21--- |
22  ; ModuleID = 'tmp.ll'
23  source_filename = "tmp.ll"
24  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
25
26  %struct.a = type { i32 }
27
28  ; Function Attrs: nounwind ssp
29  define i32 @bar(%struct.a* nocapture %b, i32 %shoes) !dbg !4 {
30  entry:
31    tail call void @llvm.dbg.value(metadata i32 %shoes, metadata !9, metadata !DIExpression()), !dbg !16
32    %tmp1 = getelementptr inbounds %struct.a, %struct.a* %b, i64 0, i32 0, !dbg !17
33    br label %bb3
34
35  bb1:                                              ; preds = %bb2
36    tail call void @llvm.dbg.value(metadata i32 %shoes, metadata !9, metadata !DIExpression()), !dbg !16
37    %add = add nsw i32 %tmp2, 1, !dbg !18
38    br label %exit
39
40  bb2:                                              ; preds = %bb3
41    tail call void @llvm.dbg.value(metadata i32 %tmp2, metadata !14, metadata !DIExpression()), !dbg !17
42    %call = tail call i32 (...) @foo(i32 %tmp2), !dbg !19
43    br label %bb1
44
45  bb3:                                              ; preds = %entry
46    %tmp2 = load i32, i32* %tmp1, align 4, !dbg !17
47    br label %bb2
48
49  exit:                                             ; preds = %bb1
50    ret i32 %shoes, !dbg !18
51  }
52
53  declare i32 @foo(...)
54
55  ; Function Attrs: nounwind readnone speculatable willreturn
56  declare void @llvm.dbg.value(metadata, metadata, metadata)
57
58  ; Function Attrs: nounwind
59  declare void @llvm.stackprotector(i8*, i8**)
60
61  !llvm.dbg.cu = !{!0}
62  !llvm.module.flags = !{!3}
63
64  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 2.9 (trunk 122997)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2)
65  !1 = !DIFile(filename: "bar.c", directory: "/private/tmp")
66  !2 = !{}
67  !3 = !{i32 1, !"Debug Info Version", i32 3}
68  !4 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !5, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
69  !5 = !DISubroutineType(types: !6)
70  !6 = !{!7}
71  !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
72  !8 = !{!9, !14}
73  !9 = !DILocalVariable(name: "b", arg: 1, scope: !4, file: !1, line: 5, type: !10)
74  !10 = !DIDerivedType(tag: DW_TAG_pointer_type, scope: !0, baseType: !11, size: 64, align: 64)
75  !11 = !DICompositeType(tag: DW_TAG_structure_type, name: "a", scope: !0, file: !1, line: 1, size: 32, align: 32, elements: !12)
76  !12 = !{!13}
77  !13 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !1, file: !1, line: 2, baseType: !7, size: 32, align: 32)
78  !14 = !DILocalVariable(name: "x", scope: !15, file: !1, line: 6, type: !7)
79  !15 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 22)
80  !16 = !DILocation(line: 5, column: 19, scope: !4)
81  !17 = !DILocation(line: 6, column: 14, scope: !15)
82  !18 = !DILocation(line: 8, column: 2, scope: !15)
83  !19 = !DILocation(line: 7, column: 2, scope: !15)
84
85...
86---
87name:            bar
88alignment:       16
89tracksRegLiveness: true
90registers:
91  - { id: 0, class: gr64 }
92  - { id: 1, class: gr32 }
93  - { id: 2, class: gr64 }
94  - { id: 3, class: gr64 }
95  - { id: 4, class: gr32 }
96  - { id: 5, class: gr32 }
97  - { id: 6, class: gr32 }
98  - { id: 7, class: gr32 }
99liveins:
100  - { reg: '$rdi', virtual-reg: '%2' }
101  - { reg: '$esi', virtual-reg: '%4' }
102frameInfo:
103  hasCalls:        true
104machineFunctionInfo: {}
105body:             |
106  bb.0.entry:
107    liveins: $rdi, $esi
108
109    %4:gr32 = COPY $esi
110    %2:gr64 = COPY $rdi
111    %3:gr64 = COPY killed %2
112    %5:gr32 = COPY killed %4
113    DBG_VALUE %5, $noreg, !9, !DIExpression(), debug-location !16
114    JMP_1 %bb.3
115
116  bb.1.bb1:
117    DBG_VALUE %5, $noreg, !9, !DIExpression(), debug-location !16
118    JMP_1 %bb.4
119
120  bb.2.bb2:
121    DBG_VALUE %6, $noreg, !14, !DIExpression(), debug-location !17
122    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !19
123    $edi = COPY %6, debug-location !19
124    $al = MOV8ri 0, debug-location !19
125    CALL64pcrel32 @foo, csr_64, implicit $rsp, implicit $ssp, implicit $al, implicit $edi, implicit-def $eax, debug-location !19
126    ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !19
127    %7:gr32 = COPY $eax, debug-location !19
128    JMP_1 %bb.1
129
130  bb.3.bb3:
131    %6:gr32 = MOV32rm %3, 1, $noreg, 0, $noreg, debug-location !17 :: (load 4 from %ir.tmp1)
132    JMP_1 %bb.2
133
134  bb.4.exit:
135    $eax = COPY %5, debug-location !18
136    RETQ implicit $eax, debug-location !18
137
138...
139