xref: /llvm-project/llvm/test/DebugInfo/MIR/X86/live-debug-values-reg-copy.mir (revision 92b33822e989884d29465d34769b07d78aeb1a84)
1# RUN: llc -run-pass=livedebugvalues %s -o - | FileCheck %s
2#
3# This test tests tracking variables value transferring from one register to another.
4# This example is altered additionally in order to test transferring from one float register
5# to another. The altered instructions are labeled below.
6#
7# CHECK: ![[ARG1:.*]] = !DILocalVariable(name: "arg1"
8# CHECK: ![[VAR1:.*]] = !DILocalVariable(name: "var1"
9# CHECK: DBG_VALUE $ebx, $noreg, ![[ARG1]], !DIExpression(), debug-location
10# CHECK: DBG_VALUE_LIST ![[VAR1]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), $ebx, $r13d
11# CHECK: $r12d = MOV32rr killed $ebx, implicit-def $r12
12# CHECK-NEXT: DBG_VALUE_LIST !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), $r12d, $r13d
13# CHECK-NEXT: DBG_VALUE $r12d, $noreg, ![[ARG1]], !DIExpression(), debug-location
14# CHECK: $r10d = MOV32rr killed $r13d, implicit-def $r10
15# CHECK-NEXT: DBG_VALUE_LIST !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), $r12d, $r10d
16--- |
17  ; ModuleID = 'live-debug-values-reg-copy.ll'
18  source_filename = "live-debug-values-reg-copy.c"
19  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
20  target triple = "x86_64-unknown-linux-gnu"
21
22  define dso_local i32 @foo(i32 %arg1) local_unnamed_addr !dbg !7 {
23  entry:
24    %local1 = alloca i32, align 4
25    call void @llvm.dbg.value(metadata i32 %arg1, metadata !12, metadata !DIExpression()), !dbg !15
26    %0 = bitcast ptr %local1 to ptr, !dbg !15
27    call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0), !dbg !15
28    call void @init(ptr nonnull %local1), !dbg !15
29    %1 = load i32, ptr %local1, align 4, !dbg !15, !tbaa !20
30    %add = add nsw i32 %1, %arg1, !dbg !15
31    %call = call i32 @coeficient(i32 %add), !dbg !15
32    %cmp = icmp sgt i32 %call, 32, !dbg !15
33    br i1 %cmp, label %if.then, label %if.else, !dbg !15
34
35  if.then:                                          ; preds = %entry
36    %call1 = call i32 @externFunc(i32 %arg1), !dbg !15
37    %2 = load i32, ptr %local1, align 4, !dbg !15, !tbaa !20
38    %add2 = add nsw i32 %2, %call1, !dbg !15
39    br label %if.end, !dbg !15
40
41  if.else:                                          ; preds = %entry
42    %call3 = call i32 @externFunc2(i32 %arg1), !dbg !15
43    %3 = load i32, ptr %local1, align 4, !dbg !15, !tbaa !20
44    %add4 = add nsw i32 %3, %call3, !dbg !15
45    br label %if.end
46
47  if.end:                                           ; preds = %if.else, %if.then
48    %storemerge = phi i32 [ %add4, %if.else ], [ %add2, %if.then ]
49    %4 = bitcast ptr %local1 to ptr
50    %mul = shl nsw i32 %arg1, 2, !dbg !15
51    %add5 = add nsw i32 %storemerge, %mul, !dbg !15
52    %mul6 = mul nsw i32 %add5, %call, !dbg !15
53    call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4), !dbg !15
54    ret i32 %mul6, !dbg !15
55  }
56
57  ; Function Attrs: argmemonly nounwind
58  declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #0
59
60  declare dso_local void @init(ptr) local_unnamed_addr
61
62  declare dso_local i32 @coeficient(i32) local_unnamed_addr
63
64  declare dso_local i32 @externFunc(i32) local_unnamed_addr
65
66  declare dso_local i32 @externFunc2(i32) local_unnamed_addr
67
68  ; Function Attrs: argmemonly nounwind
69  declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #0
70
71  ; Function Attrs: nounwind readnone speculatable
72  declare void @llvm.dbg.value(metadata, metadata, metadata) #1
73
74  ; Function Attrs: nounwind
75  declare void @llvm.stackprotector(ptr, ptr) #2
76
77  attributes #0 = { argmemonly nounwind }
78  attributes #1 = { nounwind readnone speculatable }
79  attributes #2 = { nounwind }
80
81  !llvm.dbg.cu = !{!0}
82  !llvm.module.flags = !{!3, !4, !5}
83  !llvm.ident = !{!6}
84
85  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
86  !1 = !DIFile(filename: "live-debug-values-reg-copy.c", directory: "/")
87  !2 = !{}
88  !3 = !{i32 2, !"Dwarf Version", i32 4}
89  !4 = !{i32 2, !"Debug Info Version", i32 3}
90  !5 = !{i32 1, !"wchar_size", i32 4}
91  !6 = !{!"clang version 7.0.0 "}
92  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 6, type: !8, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !11)
93  !8 = !DISubroutineType(types: !9)
94  !9 = !{!10, !10}
95  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
96  !11 = !{!12, !13}
97  !12 = !DILocalVariable(name: "arg1", arg: 1, scope: !7, file: !1, line: 6, type: !10)
98  !13 = !DILocalVariable(name: "var1", arg: 1, scope: !7, file: !1, line: 6, type: !10)
99  !15 = !DILocation(line: 6, column: 13, scope: !7)
100  !20 = !{!21, !21, i64 0}
101  !21 = !{!"int", !22, i64 0}
102  !22 = !{!"omnipotent char", !23, i64 0}
103  !23 = !{!"Simple C/C++ TBAA"}
104
105...
106---
107name:            foo
108alignment:       16
109exposesReturnsTwice: false
110legalized:       false
111regBankSelected: false
112selected:        false
113tracksRegLiveness: true
114debugInstrRef: true
115registers:
116liveins:
117  - { reg: '$edi', virtual-reg: '' }
118  - { reg: '$r8d', virtual-reg: '' }
119frameInfo:
120  isFrameAddressTaken: false
121  isReturnAddressTaken: false
122  hasStackMap:     false
123  hasPatchPoint:   false
124  stackSize:       48
125  offsetAdjustment: -48
126  maxAlignment:    4
127  adjustsStack:    true
128  hasCalls:        true
129  stackProtector:  ''
130  maxCallFrameSize: 0
131  hasOpaqueSPAdjustment: false
132  hasVAStart:      false
133  hasMustTailInVarArgFunc: false
134  savePoint:       ''
135  restorePoint:    ''
136fixedStack:
137  - { id: 0, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default,
138      callee-saved-register: '$rbx', callee-saved-restored: true }
139  - { id: 1, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default,
140      callee-saved-register: '$r12', callee-saved-restored: true }
141  - { id: 2, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default,
142      callee-saved-register: '$rbp', callee-saved-restored: true }
143  - { id: 3, type: spill-slot, offset: -24, size: 8, alignment: 16, stack-id: default,
144      callee-saved-register: '$r13', callee-saved-restored: true }
145  - { id: 4, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,
146      callee-saved-register: '$r10', callee-saved-restored: true }
147stack:
148  - { id: 0, name: local1, type: default, offset: -36, size: 4, alignment: 4,
149      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
150      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
151constants:
152body:             |
153  bb.0.entry:
154    successors: %bb.1(0x40000000), %bb.2(0x40000000)
155    liveins: $edi, $rbp, $r8, $r10, $r13, $r12, $rbx
156
157    DBG_VALUE $edi, $noreg, !12, !DIExpression(), debug-location !15
158    DBG_VALUE_LIST !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), $edi, $r8d, debug-location !15
159    frame-setup PUSH64r killed $r10, implicit-def $rsp, implicit $rsp
160    CFI_INSTRUCTION def_cfa_offset 16
161    frame-setup PUSH64r killed $r13, implicit-def $rsp, implicit $rsp
162    CFI_INSTRUCTION def_cfa_offset 24
163    frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
164    CFI_INSTRUCTION def_cfa_offset 32
165    frame-setup PUSH64r killed $r12, implicit-def $rsp, implicit $rsp
166    CFI_INSTRUCTION def_cfa_offset 40
167    frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
168    CFI_INSTRUCTION def_cfa_offset 48
169    $rsp = frame-setup SUB64ri8 $rsp, 16, implicit-def dead $eflags
170    CFI_INSTRUCTION def_cfa_offset 56
171    CFI_INSTRUCTION offset $rbx, -48
172    CFI_INSTRUCTION offset $rbx, -40
173    CFI_INSTRUCTION offset $r12, -32
174    CFI_INSTRUCTION offset $rbp, -24
175    CFI_INSTRUCTION offset $r13,  -16
176    renamable $ebx = COPY $edi, implicit-def $rbx
177    renamable $r13d = COPY $r8d, implicit-def $r13
178    DBG_VALUE $ebx, $noreg, !12, !DIExpression(), debug-location !15
179    DBG_VALUE_LIST !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), $ebx, $r13d, debug-location !15
180    renamable $rdi = LEA64r $rsp, 1, $noreg, 12, $noreg
181    renamable $r8 = LEA64r $rsp, 1, $noreg, 12, $noreg
182    CALL64pcrel32 @init, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, debug-location !15
183    renamable $edi = MOV32rm $rsp, 1, $noreg, 12, $noreg :: (dereferenceable load (s32) from %ir.local1, !tbaa !20)
184    renamable $edi = ADD32rr killed renamable $edi, renamable $ebx, implicit-def dead $eflags, debug-location !15
185    renamable $r8d = MOV32rm $rsp, 1, $noreg, 12, $noreg :: (dereferenceable load (s32) from %ir.local1, !tbaa !20)
186    renamable $r8d = ADD32rr killed renamable $r8d, renamable $r13d, implicit-def dead $eflags, debug-location !15
187    CALL64pcrel32 @coeficient, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $r8d, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15
188    renamable $ebp = COPY $eax, debug-location !15
189    CMP32ri8 $eax, 33, implicit-def $eflags, debug-location !15
190    JCC_1 %bb.2, 12, implicit killed $eflags, debug-location !15
191    JMP_1 %bb.1, debug-location !15
192
193  bb.1.if.then:
194    successors: %bb.3(0x80000000)
195    liveins: $ebp, $rbx, $r13
196
197    $edi = COPY renamable $ebx, debug-location !15
198    $r8d = COPY renamable $r13d, debug-location !15
199    CALL64pcrel32 @externFunc, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15
200    renamable $eax = KILL $eax, implicit-def $rax, debug-location !15
201    renamable $eax = nsw ADD32rm renamable $eax, $rsp, 1, $noreg, 12, $noreg, implicit-def dead $eflags, implicit killed $rax, implicit-def $rax, debug-location !15 :: (dereferenceable load (s32) from %ir.local1, !tbaa !20)
202    JMP_1 %bb.3, debug-location !15
203
204  bb.2.if.else:
205    successors: %bb.3(0x80000000)
206    liveins: $ebp, $r13, $rbx
207
208    $edi = COPY renamable $ebx, debug-location !15
209    $r8d = COPY renamable $r13d, debug-location !15
210    CALL64pcrel32 @externFunc2, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15
211    renamable $eax = KILL $eax, implicit-def $rax, debug-location !15
212    renamable $eax = nsw ADD32rm renamable $eax, $rsp, 1, $noreg, 12, $noreg, implicit-def dead $eflags, implicit killed $rax, implicit-def $rax, debug-location !15 :: (dereferenceable load (s32) from %ir.local1, !tbaa !20)
213
214  bb.3.if.end:
215    liveins: $ebp, $rax, $rbx, $r13, $r12, $r10
216    ; Instruction below is added in order to test moving variable's value from one register to another.
217    $r12d = MOV32rr killed $ebx, implicit-def $r12
218    $r10d = MOV32rr killed $r13d, implicit-def $r10
219    renamable $eax = nsw LEA64_32r killed renamable $rax, 4, killed renamable $rbx, 0, $noreg, debug-location !15
220    renamable $eax = nsw IMUL32rr killed renamable $eax, killed renamable $ebp, implicit-def dead $eflags, debug-location !15
221    $rsp = frame-destroy ADD64ri8 $rsp, 16, implicit-def dead $eflags, debug-location !15
222    CFI_INSTRUCTION def_cfa_offset 48, debug-location !15
223    $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !15
224    CFI_INSTRUCTION def_cfa_offset 40, debug-location !15
225    $r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !15
226    CFI_INSTRUCTION def_cfa_offset 32, debug-location !15
227    $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !15
228    CFI_INSTRUCTION def_cfa_offset 24, debug-location !15
229    $r13 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !15
230    CFI_INSTRUCTION def_cfa_offset 16, debug-location !15
231    $r13 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !15
232    CFI_INSTRUCTION def_cfa_offset 8, debug-location !15
233    RET 0, $eax, debug-location !15
234
235...
236