xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/survives-livedebugvars.mir (revision 7564566779eb07e9daf41a351b09cf7607871845)
1# RUN: llc -start-after=phi-node-elimination -stop-after=virtregrewriter %s -mtriple=x86_64-unknown-unknown -o - -experimental-debug-variable-locations | FileCheck %s
2# RUN: llc -O0 -start-after=phi-node-elimination -stop-after=regallocfast %s -mtriple=x86_64-unknown-unknown -o - -experimental-debug-variable-locations | FileCheck %s --check-prefix=FASTREG
3#
4# Test that DBG_INSTR_REFs can pass through livedebugvariables to the end of
5# regalloc without problem. Program body copied from
6# livedebugvars-crossbb-interval.mir.
7#
8# CHECK-LABEL: bb.0:
9# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
10# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0), dbg-instr-ref(2, 0)
11# CHECK-NEXT:  JMP_1
12# CHECK-LABEL: bb.1:
13# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
14# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0), dbg-instr-ref(3, 0)
15# CHECK-NEXT:  JMP_1
16# CHECK-LABEL: bb.2:
17# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0)
18# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0), dbg-instr-ref(4, 0)
19# CHECK-NEXT:  CALL64pcrel32
20# CHECK-LABEL: bb.3:
21# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0)
22# CHECK:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0), dbg-instr-ref(5, 0)
23# CHECK-NEXT:  JMP_1
24#
25#
26# The fast register allocator puts some spills in -- these are no-ops as far
27# as the slot indexes are concerned. It doesn't matter which side of spills
28# the DBG_INSTR_REF lands on.
29#
30# FASTREG-LABEL: bb.0:
31# FASTREG-DAG:   DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
32# FASTREG-DAG:   DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0), dbg-instr-ref(2, 0)
33# FASTREG-DAG:   MOV64mr
34# FASTREG-DAG:   MOV32mr
35# FASTREG-NEXT:  JMP_1
36# FASTREG-LABEL: bb.1:
37# FASTREG:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
38# FASTREG-DAG:   DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0), dbg-instr-ref(3, 0)
39# FASTREG-NEXT:  JMP_1
40# FASTREG-LABEL: bb.2:
41# FASTREG:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0)
42# FASTREG-DAG:   DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0), dbg-instr-ref(4, 0)
43# FASTREG-NEXT:  CALL64pcrel32
44# FASTREG-LABEL: bb.3:
45# FASTREG-DAG:   MOV32rm
46# FASTREG-DAG:   DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0)
47# FASTREG-DAG:   DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0), dbg-instr-ref(5, 0)
48# FASTREG-DAG:   MOV32mr
49# FASTREG-NEXT:  JMP_1
50# FASTREG-LABEL: bb.4:
51# FASTREG:       DBG_INSTR_REF {{.+}}, dbg-instr-ref(5, 0)
52# FASTREG-DAG:   DBG_INSTR_REF {{.+}}, dbg-instr-ref(5, 0), dbg-instr-ref(1, 0)
53# FASTREG-NEXT:  RET64
54
55--- |
56  ; ModuleID = 'tmp.ll'
57  source_filename = "tmp.ll"
58  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
59
60  %struct.a = type { i32 }
61
62  ; Function Attrs: nounwind ssp
63  define i32 @bar() !dbg !4 {
64    ret i32 0, !dbg !18
65  }
66
67  declare i32 @foo();
68
69  ; Function Attrs: nounwind readnone speculatable willreturn
70  declare void @llvm.dbg.value(metadata, metadata, metadata)
71
72  !llvm.dbg.cu = !{!0}
73  !llvm.module.flags = !{!3}
74
75  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "asdf", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2)
76  !1 = !DIFile(filename: "bar.c", directory: "asdf")
77  !2 = !{}
78  !3 = !{i32 1, !"Debug Info Version", i32 3}
79  !4 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !5, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
80  !5 = !DISubroutineType(types: !6)
81  !6 = !{!7}
82  !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
83  !8 = !{!9, !14}
84  !9 = !DILocalVariable(name: "b", arg: 1, scope: !4, file: !1, line: 5, type: !10)
85  !10 = !DIDerivedType(tag: DW_TAG_pointer_type, scope: !0, baseType: !11, size: 64, align: 64)
86  !11 = !DICompositeType(tag: DW_TAG_structure_type, name: "a", scope: !0, file: !1, line: 1, size: 32, align: 32, elements: !12)
87  !12 = !{!13}
88  !13 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !1, file: !1, line: 2, baseType: !7, size: 32, align: 32)
89  !14 = !DILocalVariable(name: "x", scope: !15, file: !1, line: 6, type: !7)
90  !15 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 22)
91  !16 = !DILocation(line: 5, column: 19, scope: !4)
92  !17 = !DILocation(line: 6, column: 14, scope: !15)
93  !18 = !DILocation(line: 8, column: 2, scope: !15)
94  !19 = !DILocation(line: 7, column: 2, scope: !15)
95  !29 = !DILocalVariable(name: "c", scope: !4, file: !1, line: 5, type: !10)
96
97...
98---
99name:            bar
100alignment:       16
101tracksRegLiveness: true
102debugInstrRef: true
103registers:
104  - { id: 0, class: gr64 }
105  - { id: 1, class: gr32 }
106  - { id: 2, class: gr64 }
107  - { id: 3, class: gr64 }
108  - { id: 4, class: gr32 }
109  - { id: 5, class: gr32 }
110  - { id: 6, class: gr32 }
111  - { id: 7, class: gr32 }
112liveins:
113  - { reg: '$rdi', virtual-reg: '%2' }
114  - { reg: '$esi', virtual-reg: '%4' }
115frameInfo:
116  adjustsStack:    true
117  hasCalls:        true
118machineFunctionInfo: {}
119body:             |
120  bb.0:
121    liveins: $rdi, $esi
122
123    %4:gr32 = COPY $esi
124    %2:gr64 = COPY $rdi
125    %3:gr64 = COPY killed %2
126    %5:gr32 = COPY killed %4
127    DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !16
128    DBG_INSTR_REF !29, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), dbg-instr-ref(1, 0), dbg-instr-ref(2, 0), debug-location !16
129    JMP_1 %bb.3
130
131  bb.1:
132    DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(2, 0), debug-location !16
133    DBG_INSTR_REF !29, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), dbg-instr-ref(2, 0), dbg-instr-ref(3, 0), debug-location !16
134    JMP_1 %bb.4
135
136  bb.2:
137    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !19
138    $edi = COPY %6, debug-location !19
139    $al = MOV8ri 0, debug-location !19
140    DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(3, 0), debug-location !16
141    DBG_INSTR_REF !29, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), dbg-instr-ref(3, 0), dbg-instr-ref(4, 0), debug-location !16
142    CALL64pcrel32 @foo, csr_64, implicit $rsp, implicit $ssp, implicit $al, implicit $edi, implicit-def $eax, debug-location !19
143    ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !19
144    %7:gr32 = COPY $eax, debug-location !19
145    JMP_1 %bb.1
146
147  bb.3:
148    %6:gr32 = MOV32rm %3, 1, $noreg, 0, $noreg, debug-location !17
149    DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(4, 0), debug-location !16
150    DBG_INSTR_REF !29, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), dbg-instr-ref(4, 0), dbg-instr-ref(5, 0), debug-location !16
151    JMP_1 %bb.2
152
153  bb.4:
154    $eax = COPY %5, debug-location !18
155    DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(5, 0), debug-location !16
156    DBG_INSTR_REF !29, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), dbg-instr-ref(5, 0), dbg-instr-ref(1, 0), debug-location !16
157    RET64 implicit $eax, debug-location !18
158
159...
160