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 debug-use $r4, debug-use $noreg, ![[ARG1]], !DIExpression(), debug-location
9# CHECK: $r5 = MOVr killed $r4, 14, $noreg, $noreg, debug-location
10# CHECK-NEXT: DBG_VALUE debug-use $r5, debug-use $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-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
15  target triple = "armv4t--"
16
17  define dso_local arm_aapcscc i32 @foo(i32 %arg1) local_unnamed_addr !dbg !8 {
18  entry:
19    call void @llvm.dbg.value(metadata i32 %arg1, metadata !13, metadata !DIExpression()), !dbg !16
20    %cmp = icmp sgt i32 %arg1, 10, !dbg !16
21    br i1 %cmp, label %if.end, label %if.else, !dbg !16
22
23  if.else:                                          ; preds = %entry
24    %add5 = add nsw i32 %arg1, 10, !dbg !16
25    call void @llvm.dbg.value(metadata i32 %add5, metadata !13, metadata !DIExpression()), !dbg !16
26    %call6 = tail call arm_aapcscc i32 @externFunc2(i32 %add5), !dbg !16
27    %call8 = tail call arm_aapcscc i32 @externFunc(i32 %add5), !dbg !16
28    ret i32 %call6, !dbg !16
29
30  if.end:                                           ; preds = %entry
31    %call = tail call arm_aapcscc i32 @externFunc(i32 %arg1), !dbg !16
32    ret i32 1, !dbg !16
33  }
34
35  declare dso_local arm_aapcscc i32 @externFunc(i32) local_unnamed_addr
36
37  declare dso_local arm_aapcscc i32 @externFunc2(i32) local_unnamed_addr
38
39  ; Function Attrs: nounwind readnone speculatable
40  declare void @llvm.dbg.value(metadata, metadata, metadata) #0
41
42  ; Function Attrs: nounwind
43  declare void @llvm.stackprotector(i8*, i8**) #1
44
45  attributes #0 = { nounwind readnone speculatable }
46  attributes #1 = { nounwind }
47
48  !llvm.dbg.cu = !{!0}
49  !llvm.module.flags = !{!3, !4, !5, !6}
50  !llvm.ident = !{!7}
51
52  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
53  !1 = !DIFile(filename: "live-debug-values-reg-copy.c", directory: "/")
54  !2 = !{}
55  !3 = !{i32 2, !"Dwarf Version", i32 4}
56  !4 = !{i32 2, !"Debug Info Version", i32 3}
57  !5 = !{i32 1, !"wchar_size", i32 4}
58  !6 = !{i32 1, !"min_enum_size", i32 4}
59  !7 = !{!"clang version 7.0.0"}
60  !8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, type: !9, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
61  !9 = !DISubroutineType(types: !10)
62  !10 = !{!11, !11}
63  !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
64  !12 = !{!13}
65  !13 = !DILocalVariable(name: "arg1", arg: 1, scope: !8, file: !1, line: 4, type: !11)
66  !16 = !DILocation(line: 4, column: 13, scope: !8)
67
68...
69---
70name:            foo
71alignment:       2
72exposesReturnsTwice: false
73legalized:       false
74regBankSelected: false
75selected:        false
76tracksRegLiveness: false
77registers:
78liveins:
79  - { reg: '$r0', virtual-reg: '' }
80frameInfo:
81  isFrameAddressTaken: false
82  isReturnAddressTaken: false
83  hasStackMap:     false
84  hasPatchPoint:   false
85  stackSize:       16
86  offsetAdjustment: 0
87  maxAlignment:    4
88  adjustsStack:    true
89  hasCalls:        true
90  stackProtector:  ''
91  maxCallFrameSize: 0
92  hasOpaqueSPAdjustment: false
93  hasVAStart:      false
94  hasMustTailInVarArgFunc: false
95  savePoint:       ''
96  restorePoint:    ''
97fixedStack:
98stack:
99  - { id: 0, name: '', type: spill-slot, offset: -4, size: 4, alignment: 4,
100      stack-id: 0, callee-saved-register: '$lr', callee-saved-restored: true,
101      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
102  - { id: 1, name: '', type: spill-slot, offset: -8, size: 4, alignment: 4,
103      stack-id: 0, callee-saved-register: '$r11', callee-saved-restored: true,
104      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
105  - { id: 2, name: '', type: spill-slot, offset: -12, size: 4, alignment: 4,
106      stack-id: 0, callee-saved-register: '$r5', callee-saved-restored: true,
107      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
108  - { id: 3, name: '', type: spill-slot, offset: -16, size: 4, alignment: 4,
109      stack-id: 0, callee-saved-register: '$r4', callee-saved-restored: true,
110      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
111constants:
112body:             |
113  bb.0.entry:
114    successors: %bb.1(0x40000000), %bb.2(0x40000000)
115
116    $sp = frame-setup STMDB_UPD $sp, 14, $noreg, killed $r4, killed $r5, killed $r11, killed $lr
117    frame-setup CFI_INSTRUCTION def_cfa_offset 16
118    frame-setup CFI_INSTRUCTION offset $lr, -4
119    frame-setup CFI_INSTRUCTION offset $r11, -8
120    frame-setup CFI_INSTRUCTION offset $r5, -12
121    frame-setup CFI_INSTRUCTION offset $r4, -16
122    DBG_VALUE debug-use $r0, debug-use $noreg, !13, !DIExpression(), debug-location !16
123    DBG_VALUE debug-use $r0, debug-use $noreg, !13, !DIExpression(), debug-location !16
124    CMPri renamable $r0, 10, 14, $noreg, implicit-def $cpsr, debug-location !16
125    Bcc %bb.2, 13, killed $cpsr, debug-location !16
126
127  bb.1.if.end:
128    BL @externFunc, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $r0, implicit-def $sp, implicit-def dead $r0, debug-location !16
129    $r0 = MOVi 1, 14, $noreg, $noreg, debug-location !16
130    $sp = LDMIA_UPD $sp, 14, $noreg, def $r4, def $r5, def $r11, def $lr, debug-location !16
131    BX_RET 14, $noreg, implicit killed $r0, debug-location !16
132
133  bb.2.if.else:
134    renamable $r4 = ADDri killed renamable $r0, 10, 14, $noreg, $noreg, debug-location !16
135    DBG_VALUE debug-use $r4, debug-use $noreg, !13, !DIExpression(), debug-location !16
136    $r0 = MOVr $r4, 14, $noreg, $noreg, debug-location !16
137    BL @externFunc2, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $r0, implicit-def $sp, implicit-def $r0, debug-location !16
138    $r5 = MOVr killed $r0, 14, $noreg, $noreg, debug-location !16
139    $r0 = MOVr $r4, 14, $noreg, $noreg, debug-location !16
140    BL @externFunc, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $r0, implicit-def $sp, implicit-def dead $r0, debug-location !16
141    $r0 = MOVr killed $r5, 14, $noreg, $noreg, debug-location !16
142    ; Instruction below is added in order to test moving variable's value from one register to another.
143    $r5 = MOVr killed $r4, 14, $noreg, $noreg, debug-location !16
144    $sp = LDMIA_UPD $sp, 14, $noreg, def $r4, def $r5, def $r11, def $lr, debug-location !16
145    BX_RET 14, $noreg, implicit killed $r0, debug-location !16
146
147...
148