xref: /llvm-project/llvm/test/DebugInfo/X86/live-debug-values-remove-range.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1; RUN: llc -mtriple=x86_64-unknown-unknown %s -o - -stop-after=livedebugvalues -experimental-debug-variable-locations=true | FileCheck %s
2;
3; In the simple loop below, the location of the variable "toast" is %bar in
4; the entry block, then set to constant zero at the end of the loop. We cannot
5; know the location of "toast" at the start of the %loop block. Test that no
6; location is given until after the call to @booler.
7;
8; Second function @baz added with an even tighter loop -- this tests different
9; code-paths through LiveDebugValues. Any blocks with an incoming backedge need
10; reconsideration after the parent of the backedge has had its OutLocs
11; initialized, even if OutLocs hasn't changed.
12;
13; Third function @quux tests that we don't delete too many variable locations.
14; A variable that is live across the body of the loop should maintain its
15; location across that loop, and not be invalidated.
16;
17; CHECK: ![[FOOVARNUM:[0-9]+]] = !DILocalVariable(name: "toast"
18; CHECK: ![[BAZVARNUM:[0-9]+]] = !DILocalVariable(name: "crumpets"
19; CHECK: ![[QUUXVARNUM:[0-9]+]] = !DILocalVariable(name: "teacake"
20;
21; foo tests
22; CHECK-LABEL: bb.1.loop
23; CHECK-NOT:   DBG_VALUE
24; CHECK-LABEL: CALL64pcrel32 @booler
25; CHECK:       DBG_VALUE 0, $noreg, ![[FOOVARNUM]]
26;
27; baz tests
28; CHECK-LABEL: name: baz
29; CHECK-LABEL: bb.1.loop
30; CHECK-NOT:   DBG_VALUE
31; CHECK-LABEL: CALL64pcrel32 @booler
32; CHECK:       DBG_VALUE 0, $noreg, ![[BAZVARNUM]]
33;
34; quux tests -- the variable arrives in $edi, should get a non-undef location
35; before the loop, and its position re-stated in each block.
36; CHECK-LABEL: name: quux
37; CHECK:       DBG_VALUE $edi, $noreg, ![[QUUXVARNUM]]
38; CHECK-LABEL: bb.1.loop
39; CHECK:       DBG_VALUE $ebx, $noreg, ![[QUUXVARNUM]]
40; CHECK-NOT:   DBG_VALUE $noreg
41; CHECK-LABEL: bb.2.exit
42; CHECK:       DBG_VALUE $ebx, $noreg, ![[QUUXVARNUM]]
43; CHECK-NOT:   DBG_VALUE $noreg
44
45declare dso_local i1 @booler()
46declare dso_local void @escape(i32)
47declare void @llvm.dbg.value(metadata, metadata, metadata)
48@glob = global i32 0
49
50define i32 @foo(i32 %bar) !dbg !4 {
51entry:
52  call void @llvm.dbg.value(metadata i32 %bar, metadata !3, metadata !DIExpression()), !dbg !6
53  br label %loop
54loop:
55  call void @escape(i32 %bar)
56  %retval = call i1 @booler(), !dbg !6
57  call void @llvm.dbg.value(metadata i32 0, metadata !3, metadata !DIExpression()), !dbg !6
58  br i1 %retval, label %loop2, label %exit
59loop2:
60  store i32 %bar, ptr @glob
61  br label %loop
62exit:
63  ret i32 %bar
64}
65
66define i32 @baz(i32 %bar) !dbg !104 {
67entry:
68  call void @llvm.dbg.value(metadata i32 %bar, metadata !103, metadata !DIExpression()), !dbg !106
69  br label %loop
70loop:
71  call void @escape(i32 %bar)
72  %retval = call i1 @booler(), !dbg !106
73  call void @llvm.dbg.value(metadata i32 0, metadata !103, metadata !DIExpression()), !dbg !106
74  br i1 %retval, label %loop, label %exit
75exit:
76  ret i32 %bar
77}
78
79define i32 @quux(i32 %bar) !dbg !204 {
80entry:
81  ; %bar will be placed in a nonvolatile or spill location for the loop,
82  ; before being returned later.
83  call void @llvm.dbg.value(metadata i32 %bar, metadata !203, metadata !DIExpression()), !dbg !206
84  br label %loop
85loop:
86  %retval = call i1 @booler(), !dbg !206
87  br i1 %retval, label %loop, label %exit
88exit:
89  ret i32 %bar
90}
91
92!llvm.module.flags = !{!0, !100}
93!llvm.dbg.cu = !{!1}
94
95!100 = !{i32 2, !"Dwarf Version", i32 4}
96!0 = !{i32 2, !"Debug Info Version", i32 3}
97!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "beards", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
98!2 = !DIFile(filename: "bees.cpp", directory: ".")
99!3 = !DILocalVariable(name: "toast", scope: !4, file: !2, line: 1, type: !16)
100!4 = distinct !DISubprogram(name: "nope", scope: !2, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !13, type: !14, isDefinition: true)
101!6 = !DILocation(line: 1, scope: !4)
102!13 = !{!3}
103!14 = !DISubroutineType(types: !15)
104!15 = !{!16}
105!16 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
106!103 = !DILocalVariable(name: "crumpets", scope: !104, file: !2, line: 1, type: !16)
107!104 = distinct !DISubprogram(name: "ribbit", scope: !2, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !113, type: !14, isDefinition: true)
108!106 = !DILocation(line: 1, scope: !104)
109!113 = !{!103}
110!203 = !DILocalVariable(name: "teacake", scope: !204, file: !2, line: 1, type: !16)
111!204 = distinct !DISubprogram(name: "toad", scope: !2, file: !2, line: 1, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !113, type: !14, isDefinition: true)
112!206 = !DILocation(line: 1, scope: !204)
113!213 = !{!203}
114