--- /dev/null
+# RUN: llc -run-pass=greedy -run-pass=virtregrewriter %s -o - | FileCheck %s
+
+## This tests that LiveDebugVariables does not trim non-inlined variable
+## location.
+
+# CHECK: ![[VARB:.*]] = !DILocalVariable(name: "b"
+# CHECK: ![[VARC:.*]] = !DILocalVariable(name: "c"
+# CHECK: $at = COPY $a2
+# CHECK-NEXT: DBG_VALUE $at, $noreg, ![[VARC]], !DIExpression(), debug-location
+# CHECK: $s0 = COPY $a1
+# CHECK-NEXT: DBG_VALUE $s0, $noreg, ![[VARB]], !DIExpression(), debug-location
+
+--- |
+ ; ModuleID = 'test.c'
+ source_filename = "test.c"
+ target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
+ target triple = "mips-unknown-linux-gnu"
+
+ ; Function Attrs: nounwind
+ define dso_local i32 @fn2(i32 signext %a, i32 signext %b, i32 signext %c) local_unnamed_addr !dbg !7 {
+ entry:
+ call void @llvm.dbg.value(metadata i32 %a, metadata !12, metadata !DIExpression()), !dbg !16
+ call void @llvm.dbg.value(metadata i32 %b, metadata !13, metadata !DIExpression()), !dbg !16
+ call void @llvm.dbg.value(metadata i32 %c, metadata !14, metadata !DIExpression()), !dbg !16
+ %add = add nsw i32 %b, %a, !dbg !17
+ %add1 = add nsw i32 %b, 10, !dbg !18
+ %call = tail call i32 @fn1(i32 signext %add, i32 signext %c, i32 signext %add1), !dbg !19
+ call void @llvm.dbg.value(metadata i32 %call, metadata !15, metadata !DIExpression()), !dbg !16
+ %cmp = icmp sgt i32 %call, 10, !dbg !20
+ %add2 = add nsw i32 %call, 10, !dbg !22
+ %retval.0 = select i1 %cmp, i32 %add2, i32 %b, !dbg !22
+ ret i32 %retval.0, !dbg !23
+ }
+
+ declare !dbg !24 dso_local i32 @fn1(i32 signext, i32 signext, i32 signext) local_unnamed_addr
+
+ ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn mustprogress
+ declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+ !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!3, !4, !5}
+ !llvm.ident = !{!6}
+
+ !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)
+ !1 = !DIFile(filename: "test.c", directory: "/dir")
+ !2 = !{}
+ !3 = !{i32 7, !"Dwarf Version", i32 4}
+ !4 = !{i32 2, !"Debug Info Version", i32 3}
+ !5 = !{i32 1, !"wchar_size", i32 4}
+ !6 = !{!"clang version 13.0.0"}
+ !7 = distinct !DISubprogram(name: "fn2", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
+ !8 = !DISubroutineType(types: !9)
+ !9 = !{!10, !10, !10, !10}
+ !10 = !DIBasicType(name: "long int", size: 32, encoding: DW_ATE_signed)
+ !11 = !{!12, !13, !14, !15}
+ !12 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !1, line: 2, type: !10)
+ !13 = !DILocalVariable(name: "b", arg: 2, scope: !7, file: !1, line: 2, type: !10)
+ !14 = !DILocalVariable(name: "c", arg: 3, scope: !7, file: !1, line: 2, type: !10)
+ !15 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 3, type: !10)
+ !16 = !DILocation(line: 0, scope: !7)
+ !17 = !DILocation(line: 3, column: 22, scope: !7)
+ !18 = !DILocation(line: 3, column: 30, scope: !7)
+ !19 = !DILocation(line: 3, column: 17, scope: !7)
+ !20 = !DILocation(line: 4, column: 14, scope: !21)
+ !21 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 8)
+ !22 = !DILocation(line: 4, column: 8, scope: !7)
+ !23 = !DILocation(line: 7, column: 2, scope: !7)
+ !24 = !DISubprogram(name: "fn1", scope: !1, file: !1, line: 1, type: !8, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
+
+...
+---
+name: fn2
+alignment: 4
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: gpr32, preferred-register: '' }
+ - { id: 1, class: gpr32, preferred-register: '' }
+ - { id: 2, class: gpr32, preferred-register: '' }
+ - { id: 3, class: gpr32, preferred-register: '' }
+ - { id: 4, class: gpr32, preferred-register: '' }
+ - { id: 5, class: gpr32, preferred-register: '' }
+ - { id: 6, class: gpr32, preferred-register: '' }
+ - { id: 7, class: gpr32, preferred-register: '' }
+ - { id: 8, class: gpr32, preferred-register: '' }
+liveins:
+ - { reg: '$a0', virtual-reg: '%0' }
+ - { reg: '$a1', virtual-reg: '%1' }
+ - { reg: '$a2', virtual-reg: '%2' }
+body: |
+ bb.0.entry:
+ liveins: $a0, $a1, $a2
+
+ DBG_VALUE $a0, $noreg, !12, !DIExpression(), debug-location !16
+ DBG_VALUE $a1, $noreg, !13, !DIExpression(), debug-location !16
+ DBG_VALUE $a2, $noreg, !14, !DIExpression(), debug-location !16
+ %2:gpr32 = COPY $a2
+ DBG_VALUE %2, $noreg, !14, !DIExpression(), debug-location !16
+ %8:gpr32 = COPY $a1
+ DBG_VALUE %8, $noreg, !13, !DIExpression(), debug-location !16
+ %0:gpr32 = COPY $a0
+ DBG_VALUE %0, $noreg, !12, !DIExpression(), debug-location !16
+ %3:gpr32 = nsw ADDu %8, %0, debug-location !17
+ ADJCALLSTACKDOWN 16, 0, implicit-def dead $sp, implicit $sp, debug-location !19
+ %4:gpr32 = nsw ADDiu %8, 10, debug-location !18
+ $a0 = COPY %3, debug-location !19
+ $a1 = COPY %2, debug-location !19
+ DBG_VALUE $a1, $noreg, !14, !DIExpression(), debug-location !16
+ $a2 = COPY %4, debug-location !19
+ JAL @fn1, csr_o32, implicit-def dead $ra, implicit $a0, implicit $a1, implicit $a2, implicit-def $sp, implicit-def $v0, debug-location !19
+ ADJCALLSTACKUP 16, 0, implicit-def dead $sp, implicit $sp, debug-location !19
+ %5:gpr32 = COPY killed $v0, debug-location !19
+ DBG_VALUE %5, $noreg, !15, !DIExpression(), debug-location !16
+ %6:gpr32 = SLTi %5, 11, debug-location !22
+ %7:gpr32 = nsw ADDiu %5, 10, debug-location !22
+ %8:gpr32 = MOVZ_I_I %7, %6, %8, debug-location !22
+ $v0 = COPY %8, debug-location !23
+ RetRA implicit killed $v0, debug-location !23
+
+...