xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/dbg-phis-in-ldv2.mir (revision d53425e2a33a0ff7336c86d3f668b1855c47a6de)
1# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
2# RUN:    -experimental-debug-variable-locations -run-pass=livedebugvalues\
3# RUN:    | FileCheck %s
4#
5# Test that a DBG_INSTR_REF that refers to a DBG_PHI, will be translated into a
6# DBG_VALUE of the value read at that DBG_PHI -- in this test, when the value
7# is on the stack.
8#
9--- |
10  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
11  target triple = "x86_64-unknown-linux-gnu"
12
13  define dso_local i32 @foo(i64 %bar, i64 %baz) !dbg !7 {
14    ret i32 0
15  }
16
17  declare dso_local void @ext(i64)
18
19  declare dso_local i64 @getlong()
20
21  !llvm.dbg.cu = !{!0}
22  !llvm.module.flags = !{!3, !4, !5}
23  !llvm.ident = !{!6}
24
25  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
26  !1 = !DIFile(filename: "test.c", directory: "/tmp/out.c")
27  !2 = !{}
28  !3 = !{i32 7, !"Dwarf Version", i32 4}
29  !4 = !{i32 2, !"Debug Info Version", i32 3}
30  !5 = !{i32 1, !"wchar_size", i32 4}
31  !6 = !{!""}
32  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
33  !8 = !DISubroutineType(types: !9)
34  !9 = !{!10, !11, !11}
35  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
36  !11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
37  !12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11)
38  !13 = !DILocation(line: 0, scope: !7)
39  !14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)
40  !19 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7)
41  !26 = !DILocation(line: 13, column: 3, scope: !7)
42
43...
44---
45name:            foo
46alignment:       16
47tracksRegLiveness: true
48debugInstrRef: true
49liveins:
50  - { reg: '$rdi' }
51  - { reg: '$rsi' }
52frameInfo:
53  stackSize:       24
54  offsetAdjustment: -24
55  maxAlignment:    1
56  adjustsStack:    true
57  hasCalls:        true
58  maxCallFrameSize: 0
59  cvBytesOfCalleeSavedRegisters: 16
60fixedStack:
61  - { id: 0, type: spill-slot, offset: -24, size: 8, alignment: 8, callee-saved-register: '$rbx' }
62  - { id: 1, type: spill-slot, offset: -16, size: 8, alignment: 16, callee-saved-register: '$r14' }
63machineFunctionInfo: {}
64stack:
65  - { id: 0, name: '', type: spill-slot, offset: 0, size: 8, alignment: 8,
66      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
67      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
68
69body:             |
70  bb.0:
71    liveins: $rdi, $rsi, $r14, $rbx
72    ; CHECK-LABEL: bb.0:
73
74    $r14 = MOV64rr $rsi
75    $rbx = MOV64rr $rdi
76    $rax = MOV64ri 0
77    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)
78    $rax = MOV64ri 0
79
80    ;; A DBG_PHI of the stack should resolve to the stack location.
81    DBG_PHI %stack.0, 1, 64
82
83    ;; Reload value, clobber stack location.
84    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)
85    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)
86
87    ;; This should resolve to the loaded register.
88    DBG_INSTR_REF !12, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !13
89    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
90    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}} $rcx
91
92    ;; And if we say it's a smaller size, we should be able to pick out smaller
93    ;; subregisters within the stack slot.
94    DBG_PHI %stack.0, 2, 32
95    $rax = MOV64ri 0
96    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)
97    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)
98
99    ;; This should pick out the 32 bit value.
100    DBG_INSTR_REF !12, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(2, 0), debug-location !13
101    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)
102    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}} $ecx
103
104    ;; Try all the other subregs.
105    DBG_PHI %stack.0, 3, 16
106    $rax = MOV64ri 0
107    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)
108    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)
109
110    DBG_INSTR_REF !12, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(3, 0), debug-location !13
111    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0)
112    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}} $cx
113
114    DBG_PHI %stack.0, 4, 8
115    $rax = MOV64ri 0
116    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)
117    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)
118
119    DBG_INSTR_REF !12, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(4, 0), debug-location !13
120    ; CHECK:      DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0)
121    ; CHECK-NEXT: DBG_VALUE_LIST {{.+}} $cl
122
123    ;; We can't, at this time, describe subregister fields with nonzero offset.
124    ;; It's easily achieved by attaching more data to stack DBG_PHIs, but it's
125    ;; not clear that LLVM will ever merge registers to generate such locations.
126
127    RET64 implicit $eax, debug-location !26
128
129...
130