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