xref: /llvm-project/llvm/test/DebugInfo/ARM/machine-cp-updates-dbg-reg.mir (revision 1469d82e1cb3edc939d6b93089046edfef0cf36c)
1# RUN: llc %s -run-pass=machine-cp -o - | FileCheck %s --implicit-check-not=DBG_VALUE
2
3## Ensure that when the destination register of a copy instruction is used by a
4## DBG_VALUE/DBG_VALUE_LIST, and then that instruction is deleted during copy
5## propagation, the debug use is updated to the source register.
6##
7## Do the same for DBG_PHI instructions.
8
9# CHECK: ![[VAR_V:[0-9]+]] = !DILocalVariable(name: "v"
10# CHECK-LABEL: body:
11
12# CHECK: DBG_PHI $r0, 1
13# CHECK: DBG_VALUE $r0, $noreg, ![[VAR_V]], !DIExpression()
14# CHECK: DBG_VALUE_LIST ![[VAR_V]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), $r0, 0
15
16--- |
17  target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
18  target triple = "arm-unknown-linux-gnueabi"
19
20  %struct.atomic_t.0.6.15.24.48.51.54.57 = type { i32 }
21  %struct.mm_struct.2.8.17.26.50.53.56.59 = type { %struct.anon.1.7.16.25.49.52.55.58 }
22  %struct.anon.1.7.16.25.49.52.55.58 = type { i32 }
23
24  @dup_mm_err = external dso_local local_unnamed_addr global i32, align 4, !dbg !0
25
26  declare dso_local i32 @atomic_long_read(ptr) local_unnamed_addr #0
27
28  declare dso_local i32 @get_mm_counter(ptr, i32) local_unnamed_addr #0
29
30  define dso_local i32 @dup_mm(i1 %arg) local_unnamed_addr !dbg !16 {
31  entry:
32    %call = tail call i32 @kmem_cache_alloc(i32 0)
33    br i1 %arg, label %cleanup, label %if.end
34
35  if.end:                                           ; preds = %entry
36    %tobool1.not = icmp eq i32 undef, 0
37    br i1 %tobool1.not, label %if.end3, label %free_pt
38
39  if.end3:                                          ; preds = %if.end
40    call void @llvm.dbg.value(metadata !DIArgList(i32 %call, i32 0), metadata !30, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value)), !dbg !40
41    %0 = load volatile i32, ptr undef, align 4
42    br label %cleanup
43
44  free_pt:                                          ; preds = %if.end
45    store i32 0, ptr undef, align 4
46    br label %cleanup
47
48  cleanup:                                          ; preds = %free_pt, %if.end3, %entry
49    %retval.0 = phi i32 [ %call, %if.end3 ], [ 0, %entry ], [ 0, %free_pt ]
50    ret i32 %retval.0
51  }
52
53  declare dso_local i32 @kmem_cache_alloc(...) local_unnamed_addr
54
55  declare void @llvm.dbg.label(metadata)
56
57  declare void @llvm.dbg.value(metadata, metadata, metadata)
58
59  !llvm.dbg.cu = !{!2}
60  !llvm.module.flags = !{!14, !15}
61
62  !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
63  !1 = distinct !DIGlobalVariable(name: "dup_mm_err", scope: !2, file: !3, line: 5, type: !12, isLocal: false, isDefinition: true)
64  !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !9, globals: !13, splitDebugInlining: false, nameTableKind: None)
65  !3 = !DIFile(filename: "machine-cp-updates-dbg-reg.ll", directory: "/")
66  !4 = !{!5}
67  !5 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !3, line: 4, baseType: !6, size: 32, elements: !7)
68  !6 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
69  !7 = !{!8}
70  !8 = !DIEnumerator(name: "MM_SHMEMPAGES", value: 0, isUnsigned: true)
71  !9 = !{!10}
72  !10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 32)
73  !11 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !12)
74  !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
75  !13 = !{!0}
76  !14 = !{i32 2, !"Debug Info Version", i32 3}
77  !15 = !{i32 1, !"min_enum_size", i32 4}
78  !16 = distinct !DISubprogram(name: "dup_mm", scope: !3, file: !3, line: 14, type: !17, scopeLine: 14, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19)
79  !17 = !DISubroutineType(types: !18)
80  !18 = !{!12}
81  !19 = !{!20, !28, !29}
82  !20 = !DILocalVariable(name: "mm", scope: !16, file: !3, line: 15, type: !21)
83  !21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 32)
84  !22 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "mm_struct", file: !3, line: 7, size: 32, elements: !23)
85  !23 = !{!24}
86  !24 = !DIDerivedType(tag: DW_TAG_member, scope: !22, file: !3, line: 8, baseType: !25, size: 32)
87  !25 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !22, file: !3, line: 8, size: 32, elements: !26)
88  !26 = !{!27}
89  !27 = !DIDerivedType(tag: DW_TAG_member, name: "binfmt", scope: !25, file: !3, line: 9, baseType: !12, size: 32)
90  !28 = !DILabel(scope: !16, name: "free_pt", file: !3, line: 22)
91  !29 = !DILabel(scope: !16, name: "fail_nomem", file: !3, line: 24)
92  !30 = !DILocalVariable(name: "v", arg: 1, scope: !31, file: !3, line: 6, type: !34)
93  !31 = distinct !DISubprogram(name: "atomic_long_read", scope: !3, file: !3, line: 6, type: !32, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !39)
94  !32 = !DISubroutineType(types: !33)
95  !33 = !{!12, !34}
96  !34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !35, size: 32)
97  !35 = !DIDerivedType(tag: DW_TAG_typedef, name: "atomic_t", file: !3, line: 3, baseType: !36)
98  !36 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 1, size: 32, elements: !37)
99  !37 = !{!38}
100  !38 = !DIDerivedType(tag: DW_TAG_member, name: "counter", scope: !36, file: !3, line: 2, baseType: !12, size: 32)
101  !39 = !{!30}
102  !40 = !DILocation(line: 0, scope: !31, inlinedAt: !41)
103  !41 = distinct !DILocation(line: 12, column: 3, scope: !42, inlinedAt: !48)
104  !42 = distinct !DISubprogram(name: "get_mm_counter", scope: !3, file: !3, line: 11, type: !43, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !45)
105  !43 = !DISubroutineType(types: !44)
106  !44 = !{!22, !21, !12}
107  !45 = !{!46, !47}
108  !46 = !DILocalVariable(name: "mm", arg: 1, scope: !42, file: !3, line: 11, type: !21)
109  !47 = !DILocalVariable(name: "member", arg: 2, scope: !42, file: !3, line: 11, type: !12)
110  !48 = distinct !DILocation(line: 20, column: 3, scope: !16)
111
112...
113---
114name:            dup_mm
115alignment:       4
116exposesReturnsTwice: false
117legalized:       false
118regBankSelected: false
119selected:        false
120failedISel:      false
121tracksRegLiveness: true
122hasWinCFI:       false
123registers:       []
124liveins:         []
125frameInfo:
126  isFrameAddressTaken: false
127  isReturnAddressTaken: false
128  hasStackMap:     false
129  hasPatchPoint:   false
130  stackSize:       8
131  offsetAdjustment: 0
132  maxAlignment:    4
133  adjustsStack:    true
134  hasCalls:        true
135  stackProtector:  ''
136  maxCallFrameSize: 0
137  cvBytesOfCalleeSavedRegisters: 0
138  hasOpaqueSPAdjustment: false
139  hasVAStart:      false
140  hasMustTailInVarArgFunc: false
141  hasTailCall:     false
142  localFrameSize:  0
143  savePoint:       ''
144  restorePoint:    ''
145fixedStack:      []
146stack:
147  - { id: 0, name: '', type: spill-slot, offset: -4, size: 4, alignment: 4,
148      stack-id: default, callee-saved-register: '$lr', callee-saved-restored: false,
149      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
150  - { id: 1, name: '', type: spill-slot, offset: -8, size: 4, alignment: 4,
151      stack-id: default, callee-saved-register: '$r4', callee-saved-restored: true,
152      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
153callSites:       []
154debugValueSubstitutions: []
155constants:       []
156machineFunctionInfo: {}
157body:             |
158  bb.0.entry:
159    successors: %bb.4(0x40000000), %bb.1(0x40000000)
160    liveins: $r4, $lr
161
162    $sp = frame-setup STMDB_UPD $sp, 14 /* CC::al */, $noreg, killed $r4, killed $lr
163    frame-setup CFI_INSTRUCTION def_cfa_offset 8
164    frame-setup CFI_INSTRUCTION offset $lr, -4
165    frame-setup CFI_INSTRUCTION offset $r4, -8
166    renamable $r4 = MOVi 0, 14 /* CC::al */, $noreg, $noreg
167    $r0 = MOVi 0, 14 /* CC::al */, $noreg, $noreg
168    BL @kmem_cache_alloc, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit $r0, implicit-def $sp, implicit-def $r0
169    CMPri renamable $r4, 0, 14 /* CC::al */, $noreg, implicit-def $cpsr
170    Bcc %bb.4, 1 /* CC::ne */, killed $cpsr
171
172  bb.1.if.end:
173    successors: %bb.2(0x30000000), %bb.3(0x50000000)
174    liveins: $r0
175
176    renamable $r4 = MOVi 0, 14 /* CC::al */, $noreg, $noreg
177    CMPri renamable $r4, 0, 14 /* CC::al */, $noreg, implicit-def $cpsr
178    Bcc %bb.3, 1 /* CC::ne */, killed $cpsr
179
180  bb.2.if.end3:
181    liveins: $r0
182
183    dead renamable $r1 = LDRi12 undef renamable $r0, 0, 14 /* CC::al */, $noreg :: (volatile load (s32) from `ptr undef`)
184    renamable $r4 = COPY killed renamable $r0
185    DBG_PHI $r4, 1
186    DBG_VALUE $r4, $noreg, !30, !DIExpression(), debug-location !40
187    DBG_VALUE_LIST !30, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), $r4, 0, debug-location !40
188    $r0 = COPY killed renamable $r4
189    $sp = frame-destroy LDMIA_RET $sp, 14 /* CC::al */, $noreg, def $r4, def $pc, implicit $r0
190
191  bb.3.free_pt:
192    successors: %bb.4(0x80000000)
193    liveins: $r4
194
195    STRi12 renamable $r4, undef renamable $r0, 0, 14 /* CC::al */, $noreg :: (store (s32) into `ptr undef`)
196
197  bb.4.cleanup:
198    liveins: $r4
199
200    $r0 = COPY killed renamable $r4
201    $sp = frame-destroy LDMIA_RET $sp, 14 /* CC::al */, $noreg, def $r4, def $pc, implicit $r0
202
203...
204