1# RUN: llc %s -o - -run-pass=removeredundantdebugvalues | FileCheck --implicit-check-not=DBG_VALUE %s 2 3## This checks that the RemoveRedundantDebugValues removes redundant 4## DBG_VALUEs. The MIR was hand-written, and foo{[2-6]}() are just 5## copies of foo(), with an extra instruction that modifies the $edi register 6## and extra (artificial) DBG_VALUE and DBG_VALUE_LIST instructions. 7 8# CHECK-LABEL: foo 9# CHECK-LABEL: bb.0.entry: 10# CHECK: DBG_VALUE $edi 11# CHECK-NOT: DBG_VALUE $edi 12# CHECK: frame-setup PUSH64r 13# CHECK: MOV32mr $rip, 1, $noreg 14# CHECK-NOT: DBG_VALUE $edi 15 16# CHECK-LABEL: foo6 17# CHECK-LABEL: bb.0.entry: 18# CHECK: DBG_VALUE 0 19# CHECK: DBG_VALUE 1 20# CHECK: frame-setup PUSH64r 21 22# CHECK-LABEL: foo2 23# CHECK-LABEL: bb.0.entry: 24# CHECK: DBG_VALUE $edi 25# CHECK: MOV32mr $rip, 1, $noreg 26# CHECK: DBG_VALUE $edi 27 28# CHECK-LABEL: foo3 29# CHECK-LABEL: bb.0.entry: 30# CHECK: DBG_VALUE $edi, {{.*}}, !DIExpression(DW_OP_LLVM_fragment, 0, 32) 31# CHECK: DBG_VALUE $esi, {{.*}}, !DIExpression() 32# CHECK: DBG_VALUE $edi, {{.*}}, !DIExpression(DW_OP_LLVM_fragment, 0, 32) 33 34# CHECK-LABEL: foo4 35# CHECK-LABEL: bb.0.entry: 36# CHECK: DBG_VALUE $edi, {{.*}}, !DIExpression(DW_OP_LLVM_fragment, 0, 32) 37# CHECK: DBG_VALUE_LIST !{{.*}} 38# CHECK: DBG_VALUE $edi, {{.*}}, !DIExpression(DW_OP_LLVM_fragment, 0, 32) 39 40# CHECK-LABEL: foo5 41# CHECK-LABEL: bb.0.entry: 42# CHECK: DBG_VALUE $edi, {{.*}}, !DIExpression(DW_OP_LLVM_fragment, 0, 32) 43# CHECK: DBG_VALUE 0, {{.*}}, !DIExpression() 44# CHECK: DBG_VALUE $edi, {{.*}}, !DIExpression(DW_OP_LLVM_fragment, 0, 32) 45 46--- | 47 ; ModuleID = 'test.ll' 48 source_filename = "test.c" 49 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 50 target triple = "x86_64-unknown-linux-gnu" 51 52 @side_effect = external dso_local local_unnamed_addr global i32, align 4 53 @value = external dso_local local_unnamed_addr global i32, align 4 54 55 ; Function Attrs: nounwind uwtable 56 define dso_local i32 @foo(i32 %param) local_unnamed_addr !dbg !8 { 57 entry: 58 call void @llvm.dbg.value(metadata i32 %param, metadata !13, metadata !DIExpression()), !dbg !14 59 store i32 %param, ptr @side_effect, align 4, !dbg !15 60 %0 = load i32, ptr @value, align 4, !dbg !20 61 call void @llvm.dbg.value(metadata i32 %0, metadata !13, metadata !DIExpression()), !dbg !14 62 tail call void @bar(i32 %0), !dbg !21 63 ret i32 0, !dbg !22 64 } 65 66 define dso_local i32 @foo6(i32 %param) local_unnamed_addr !dbg !34 { 67 entry: 68 store i32 %param, ptr @side_effect, align 4, !dbg !35 69 %0 = load i32, ptr @value, align 4, !dbg !35 70 tail call void @bar(i32 %0), !dbg !35 71 ret i32 0, !dbg !35 72 } 73 74 ; Function Attrs: nounwind uwtable 75 define dso_local i32 @foo2(i32 %param) local_unnamed_addr !dbg !26 { 76 entry: 77 store i32 %param, ptr @side_effect, align 4, !dbg !27 78 %0 = load i32, ptr @value, align 4, !dbg !27 79 tail call void @bar(i32 %0), !dbg !27 80 ret i32 0, !dbg !27 81 } 82 83 ; Function Attrs: nounwind uwtable 84 define dso_local i32 @foo3(i32 %param) local_unnamed_addr !dbg !28 { 85 entry: 86 store i32 %param, ptr @side_effect, align 4, !dbg !29 87 %0 = load i32, ptr @value, align 4, !dbg !29 88 tail call void @bar(i32 %0), !dbg !29 89 ret i32 0, !dbg !29 90 } 91 92 ; Function Attrs: nounwind uwtable 93 define dso_local i32 @foo4(i32 %param) local_unnamed_addr !dbg !30 { 94 entry: 95 store i32 %param, ptr @side_effect, align 4, !dbg !31 96 %0 = load i32, ptr @value, align 4, !dbg !31 97 tail call void @bar(i32 %0), !dbg !31 98 ret i32 0, !dbg !31 99 } 100 101 ; Function Attrs: nounwind uwtable 102 define dso_local i32 @foo5(i32 %param) local_unnamed_addr !dbg !32 { 103 entry: 104 store i32 %param, ptr @side_effect, align 4, !dbg !33 105 %0 = load i32, ptr @value, align 4, !dbg !33 106 tail call void @bar(i32 %0), !dbg !33 107 ret i32 0, !dbg !33 108 } 109 110 declare !dbg !23 dso_local void @bar(i32) local_unnamed_addr 111 112 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 113 declare void @llvm.dbg.value(metadata, metadata, metadata) 114 115 !llvm.dbg.cu = !{!0} 116 !llvm.module.flags = !{!3, !4, !5, !6} 117 !llvm.ident = !{!7} 118 119 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) 120 !1 = !DIFile(filename: "test.c", directory: "/dir") 121 !2 = !{} 122 !3 = !{i32 7, !"Dwarf Version", i32 4} 123 !4 = !{i32 2, !"Debug Info Version", i32 3} 124 !5 = !{i32 1, !"wchar_size", i32 4} 125 !6 = !{i32 7, !"uwtable", i32 1} 126 !7 = !{!"clang version 13.0.0"} 127 !8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 128 !9 = !DISubroutineType(types: !10) 129 !10 = !{!11, !11} 130 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 131 !12 = !{!13} 132 !13 = !DILocalVariable(name: "param", arg: 1, scope: !8, file: !1, line: 4, type: !11) 133 !14 = !DILocation(line: 0, scope: !8) 134 !15 = !DILocation(line: 5, column: 17, scope: !8) 135 !20 = !DILocation(line: 6, column: 13, scope: !8) 136 !21 = !DILocation(line: 7, column: 5, scope: !8) 137 !22 = !DILocation(line: 8, column: 5, scope: !8) 138 !23 = !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !24, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) 139 !24 = !DISubroutineType(types: !25) 140 !25 = !{null, !11} 141 !26 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 142 !27 = !DILocation(line: 0, scope: !26) 143 !28 = distinct !DISubprogram(name: "foo3", scope: !1, file: !1, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 144 !29 = !DILocation(line: 0, scope: !28) 145 !30 = distinct !DISubprogram(name: "foo4", scope: !1, file: !1, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 146 !31 = !DILocation(line: 0, scope: !30) 147 !32 = distinct !DISubprogram(name: "foo5", scope: !1, file: !1, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 148 !33 = !DILocation(line: 0, scope: !32) 149 !34 = distinct !DISubprogram(name: "foo6", scope: !1, file: !1, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 150 !35 = !DILocation(line: 0, scope: !34) 151 152... 153--- 154name: foo 155alignment: 16 156liveins: 157 - { reg: '$edi', virtual-reg: '' } 158body: | 159 bb.0.entry: 160 liveins: $edi, $esi 161 162 DBG_VALUE $edi, $noreg, !13, !DIExpression(), debug-location !14 163 DBG_VALUE $edi, $noreg, !13, !DIExpression(), debug-location !14 164 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp 165 CFI_INSTRUCTION def_cfa_offset 16 166 MOV32mr $rip, 1, $noreg, @side_effect, $noreg, killed renamable $esi, debug-location !15 :: (store 4 into @side_effect) 167 DBG_VALUE $edi, $noreg, !13, !DIExpression(), debug-location !14 168 CALL64pcrel32 @bar, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, debug-location !21 169 $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !22 170 $rcx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !22 171 CFI_INSTRUCTION def_cfa_offset 8, debug-location !22 172 RET64 killed $eax, debug-location !22 173 174... 175--- 176name: foo2 177alignment: 16 178liveins: 179 - { reg: '$edi', virtual-reg: '' } 180body: | 181 bb.0.entry: 182 liveins: $edi, $esi 183 184 DBG_VALUE $edi, $noreg, !13, !DIExpression(), debug-location !14 185 DBG_VALUE $edi, $noreg, !13, !DIExpression(), debug-location !14 186 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp 187 CFI_INSTRUCTION def_cfa_offset 16 188 MOV32mr $rip, 1, $noreg, @side_effect, $noreg, killed renamable $esi, debug-location !15 :: (store 4 into @side_effect) 189 renamable $edi = MOV32rm $rip, 1, $noreg, @value, $noreg, debug-location !20 :: (dereferenceable load 4 from @value) 190 DBG_VALUE $edi, $noreg, !13, !DIExpression(), debug-location !14 191 CALL64pcrel32 @bar, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, debug-location !21 192 $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !22 193 $rcx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !22 194 CFI_INSTRUCTION def_cfa_offset 8, debug-location !22 195 RET64 killed $eax, debug-location !22 196 197... 198--- 199name: foo3 200alignment: 16 201liveins: 202 - { reg: '$edi', virtual-reg: '' } 203body: | 204 bb.0.entry: 205 liveins: $edi, $esi 206 207 DBG_VALUE $edi, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !14 208 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp 209 CFI_INSTRUCTION def_cfa_offset 16 210 MOV32mr $rip, 1, $noreg, @side_effect, $noreg, killed renamable $esi, debug-location !15 :: (store 4 into @side_effect) 211 renamable $esi = MOV32rm $rip, 1, $noreg, @value, $noreg, debug-location !20 :: (dereferenceable load 4 from @value) 212 DBG_VALUE $esi, $noreg, !13, !DIExpression(), debug-location !14 213 $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !22 214 DBG_VALUE $edi, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !14 215 $rcx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !22 216 CFI_INSTRUCTION def_cfa_offset 8, debug-location !22 217 RET64 killed $eax, debug-location !22 218 219... 220--- 221name: foo4 222alignment: 16 223liveins: 224 - { reg: '$edi', virtual-reg: '' } 225body: | 226 bb.0.entry: 227 liveins: $edi, $esi 228 229 DBG_VALUE $edi, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !14 230 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp 231 CFI_INSTRUCTION def_cfa_offset 16 232 MOV32mr $rip, 1, $noreg, @side_effect, $noreg, killed renamable $esi, debug-location !15 :: (store 4 into @side_effect) 233 renamable $esi = MOV32rm $rip, 1, $noreg, @value, $noreg, debug-location !20 :: (dereferenceable load 4 from @value) 234 DBG_VALUE_LIST !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value), $edi, $esi, debug-location !14 235 $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !22 236 DBG_VALUE $edi, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !14 237 $rcx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !22 238 CFI_INSTRUCTION def_cfa_offset 8, debug-location !22 239 RET64 killed $eax, debug-location !22 240 241... 242--- 243name: foo5 244alignment: 16 245liveins: 246 - { reg: '$edi', virtual-reg: '' } 247body: | 248 bb.0.entry: 249 liveins: $edi, $esi 250 251 DBG_VALUE $edi, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !14 252 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp 253 CFI_INSTRUCTION def_cfa_offset 16 254 MOV32mr $rip, 1, $noreg, @side_effect, $noreg, killed renamable $esi, debug-location !15 :: (store 4 into @side_effect) 255 renamable $esi = MOV32rm $rip, 1, $noreg, @value, $noreg, debug-location !20 :: (dereferenceable load 4 from @value) 256 DBG_VALUE 0, $noreg, !13, !DIExpression(), debug-location !14 257 $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !22 258 DBG_VALUE $edi, $noreg, !13, !DIExpression(DW_OP_LLVM_fragment, 0, 32), debug-location !14 259 $rcx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !22 260 CFI_INSTRUCTION def_cfa_offset 8, debug-location !22 261 RET64 killed $eax, debug-location !22 262 263... 264--- 265name: foo6 266alignment: 16 267liveins: 268 - { reg: '$edi', virtual-reg: '' } 269body: | 270 bb.0.entry: 271 liveins: $edi, $esi 272 273 DBG_VALUE 0, $noreg, !13, !DIExpression(), debug-location !14 274 DBG_VALUE 1, $noreg, !13, !DIExpression(), debug-location !14 275 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp 276 CFI_INSTRUCTION def_cfa_offset 16 277 MOV32mr $rip, 1, $noreg, @side_effect, $noreg, killed renamable $esi, debug-location !15 :: (store 4 into @side_effect) 278 renamable $esi = MOV32rm $rip, 1, $noreg, @value, $noreg, debug-location !20 :: (dereferenceable load 4 from @value) 279 $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !22 280 $rcx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !22 281 CFI_INSTRUCTION def_cfa_offset 8, debug-location !22 282 RET64 killed $eax, debug-location !22 283 284... 285