xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/memory-operand-tracking.mir (revision 40a4cbb0f200e5e0bafbd58d55c2da6daab9515d)
1# RUN: llc %s -mtriple=x86_64 -run-pass=livedebugvalues \
2# RUN:      -mtriple x86_64-unknown-unknown \
3# RUN:      -experimental-debug-variable-locations -o - 2>&1 \
4# RUN: | FileCheck %s
5#
6# Test that memory operands of instructions are interpreted by LiveDebugValues:
7# if an instruction reference is substituted to a memory operand, we should be
8# able to emit a DBG_VALUE referring to its slot.
9#
10# In addition, further instructions that write to the same stack slot should
11# be recognised as clobbering the value in that slot.
12--- |
13  define i8 @test(i32 %bar) local_unnamed_addr !dbg !7 {
14  entry:
15    ret i8 0, !dbg !12
16  }
17
18  declare dso_local void @ext(i64)
19
20  !llvm.dbg.cu = !{!0}
21  !llvm.module.flags = !{!3, !4, !5, !6}
22  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
23  !1 = !DIFile(filename: "foo.cpp", directory: ".")
24  !2 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_signed)
25  !3 = !{i32 2, !"Dwarf Version", i32 4}
26  !4 = !{i32 2, !"Debug Info Version", i32 3}
27  !5 = !{i32 1, !"wchar_size", i32 2}
28  !6 = !{i32 7, !"PIC Level", i32 2}
29  !7 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 6, type: !8, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
30  !8 = !DISubroutineType(types: !9)
31  !9 = !{!2, !2}
32  !10 = !{!11}
33  !11 = !DILocalVariable(name: "baz", scope: !7, file: !1, line: 7, type: !2)
34  !12 = !DILocation(line: 10, scope: !7)
35...
36---
37name: test
38tracksRegLiveness: true
39debugInstrRef: true
40liveins:
41  - { reg: '$rdi', virtual-reg: '' }
42debugValueSubstitutions:
43- { srcinst: 2, srcop: 0, dstinst: 3, dstop: 1000000, subreg: 0 }
44- { srcinst: 4, srcop: 0, dstinst: 5, dstop: 1000000, subreg: 0 }
45stack:
46  - { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 8,
47      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
48      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
49body:  |
50  bb.0:
51  liveins: $rdi, $rax
52    DBG_PHI $rax, 1
53    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rdi :: (store 8 into %stack.0)
54    $rax = MOV64ri 0, debug-location !12
55    INC32m $rsp, 1, $noreg, 4, $noreg, implicit-def dead $eflags, debug-instr-number 3, debug-location !DILocation(line: 0, scope: !7) :: (store (s32) into %stack.0)
56    DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(2, 0), debug-location !12
57    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
58    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $rsp
59    ;; Test that the old value (from the DBG_PHI) is not tracked anywhere. It
60    ;; should not be considered as being on the stack any more.
61    DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !12
62    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
63    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $noreg
64    INC32m $rsp, 1, $noreg, 4, $noreg, implicit-def dead $eflags, debug-location !12 :: (store (s32) into %stack.0)
65    ;; The above INC32m should be detected as clobbering the stack location,
66    ;; even though it isn't debug labelled.
67    DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(2, 0), debug-location !12
68    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
69    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $noreg
70
71    ;; Store another debug-labelled value to the stack,
72    INC32m $rsp, 1, $noreg, 4, $noreg, implicit-def dead $eflags, debug-instr-number 5, debug-location !DILocation(line: 0, scope: !7) :: (store (s32) into %stack.0)
73    ;; Point the variable at that value.
74    DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(4, 0), debug-location !12
75    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0),
76    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $rsp
77    ;; Overwrite the stack: LiveDebugValues should explicitly undef the stack
78    ;; location with DBG_VALUE_LIST $noreg, as DbgEntityHistoryCalculator doesn't
79    ;; look at the stack.
80    INC32m $rsp, 1, $noreg, 4, $noreg, implicit-def dead $eflags, debug-location !DILocation(line: 0, scope: !7) :: (store (s32) into %stack.0)
81    ; CHECK:      INC32m $rsp
82    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $noreg
83
84    $rax = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)
85    RET64 $rax, debug-location !12
86...
87