xref: /llvm-project/llvm/test/DebugInfo/X86/instr-ref-unreachable.mir (revision 0670470a8ded8ece91444722a81a9b02b93dcf4a)
1# RUN: llc --run-pass=livedebugvalues %s -o - -experimental-debug-variable-locations | FileCheck %s
2
3## Tests that when a block that is not directly reachable from the entry block
4## contains a DBG_PHI, we treat those DBG_PHIs as referring to live-in values,
5## and resolve them for users as normal.
6## FIXME: "def" currently does not have a value due to blocks that are not
7## directly reachable from the entry block not being fully covered by the
8## LiveDebugValues analysis.
9
10# CHECK-DAG: ![[UNDEFVAR:[0-9]+]] = !DILocalVariable(name: "undef"
11# CHECK-DAG: ![[DEFVAR:[0-9]+]] = !DILocalVariable(name: "def"
12
13# CHECK-LABEL: bb.1.bb1
14# CHECK: DBG_VALUE_LIST ![[UNDEFVAR]], {{.+}}, $noreg
15# CHECK-LABEL: bb.4.bb3
16# CHECK: DBG_VALUE_LIST ![[DEFVAR]], {{.+}}, $noreg
17
18--- |
19  ; ModuleID = 'llvm/test/DebugInfo/X86/instr-ref-unreachable.mir'
20  source_filename = "/tmp/b.ll"
21  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
22  target triple = "x86_64-unknown-linux-gnu"
23
24  @global = private constant [2 x ptr] [ptr blockaddress(@foo, %bb3), ptr blockaddress(@foo, %bb1)]
25
26  define ptr @foo() !dbg !4 {
27  bb:
28    br label %bb3
29
30  bb1:                                              ; preds = %bb3
31    call void @llvm.dbg.value(metadata i64 %phi, metadata !6, metadata !DIExpression()), !dbg !8
32    call void @llvm.dbg.value(metadata i64 %phi, metadata !9, metadata !DIExpression()), !dbg !8
33    store i32 0, ptr null, align 4, !dbg !10
34    %getelementptr = getelementptr i32, ptr null, i64 %phi
35    store i32 0, ptr %getelementptr, align 4
36    br label %bb2
37
38  bb2:                                              ; preds = %bb2, %bb1
39    %select = select i1 false, i1 false, i1 false
40    br i1 %select, label %bb3, label %bb2
41
42  bb3:                                              ; preds = %bb2, %bb
43    %phi = phi i64 [ 1, %bb ], [ 0, %bb2 ]
44    br label %bb1
45  }
46
47  declare void @llvm.dbg.value(metadata, metadata, metadata)
48
49  !llvm.dbg.cu = !{!0}
50  !llvm.module.flags = !{!3}
51
52  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: GNU)
53  !1 = !DIFile(filename: "test.cpp", directory: ".")
54  !2 = !{}
55  !3 = !{i32 2, !"Debug Info Version", i32 3}
56  !4 = distinct !DISubprogram(name: "GetNumericFormat", linkageName: "f", scope: null, file: !1, line: 980, type: !5, scopeLine: 984, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
57  !5 = distinct !DISubroutineType(types: !2)
58  !6 = !DILocalVariable(name: "undef", scope: !4, file: !1, line: 263, type: !7)
59  !7 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
60  !8 = !DILocation(line: 0, scope: !4)
61  !9 = !DILocalVariable(name: "def", scope: !4, file: !1, line: 263, type: !7)
62  !10 = !DILocation(line: 151, column: 41, scope: !4)
63
64...
65---
66name:            foo
67alignment:       16
68tracksRegLiveness: true
69debugInstrRef:   true
70tracksDebugUserValues: true
71frameInfo:
72  maxAlignment:    1
73body:             |
74  bb.0.bb:
75    successors: %bb.1(0x80000000)
76
77    $ecx = MOV32ri 1, implicit-def $rcx
78    renamable $al = MOV8ri 1
79
80  bb.1.bb1 (ir-block-address-taken %ir-block.bb1, align 16):
81    successors: %bb.2(0x80000000)
82    liveins: $al, $rcx
83
84    DBG_INSTR_REF !6, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !8
85    MOV32mi $noreg, 1, $noreg, 0, $noreg, 0, debug-location !10 :: (store (s32) into `ptr null`)
86    MOV32mi $noreg, 4, killed renamable $rcx, 0, $noreg, 0 :: (store (s32) into %ir.getelementptr)
87
88  bb.2.bb2 (align 16):
89    successors: %bb.3(0x04000000), %bb.2(0x7c000000)
90    liveins: $al
91
92    TEST8rr renamable $al, renamable $al, implicit-def $eflags
93    JCC_1 %bb.2, 5, implicit killed $eflags
94
95  bb.3:
96    successors: %bb.1(0x80000000)
97    liveins: $al
98
99    renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags, implicit-def $rcx
100    JMP_1 %bb.1
101
102  bb.4.bb3 (ir-block-address-taken %ir-block.bb3):
103    successors: %bb.1(0x80000000)
104    liveins: $al, $rcx
105
106    DBG_PHI $rcx, 1
107    DBG_INSTR_REF !9, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !8
108    JMP_1 %bb.1
109
110...
111