1 ; RUN: llc -mtriple=x86_64-unknown-unknown -start-after=codegenprepare -stop-before=finalize-isel %s -o - -experimental-debug-variable-locations=false | FileCheck %s --check-prefixes=COMMON,CHECK
2 ; RUN: llc -mtriple=x86_64-unknown-unknown -start-after=codegenprepare -stop-before=finalize-isel %s -o - -experimental-debug-variable-locations=true | FileCheck %s --check-prefixes=COMMON,INSTRREF
4 ; Test the movement of dbg.values of arguments. SelectionDAG tries to be
5 ; helpful and places DBG_VALUEs of Arguments at the start of functions.
6 ; Unfortunately, this doesn't necessarily make sense, as one can specify an
7 ; Argument IR Value as a variable location anywhere in the program.
9 ; Distinguish cases where we want to hoist DBG_VALUEs, and those where we
10 ; don't, by whether the referred to variable is a parameter to the current
11 ; function. In the test below, 'xyzzy' is a parameter to an inlined function,
12 ; but should not be hoisted to the start of the function.
14 ; With instruction referencing, accuracy becomes more important than coverage,
15 ; so debug instructions are placed wherever they were in the IR.
17 ; Original test case, in which 'xyzzy' became unavailable because its DBG_VALUE
18 ; landed far from any uses, compiled "clang -O2 -g" with inlining,
25 ; xyzzy = ext() * xyzzy;
32 ; bar(int baz, int qux)
36 ; case 12: fish = 8; break;
37 ; case 848: fish = 0; break;
38 ; case 99999: fish = -1; break;
46 ; COMMON: [[BAZVAR:![0-9]+]] = !DILocalVariable(name: "baz",
47 ; COMMON: [[XYZVAR:![0-9]+]] = !DILocalVariable(name: "xyzzy",
49 ; Start of MIR function block,
51 ; Expect DBG_VALUE of physreg,
52 ; CHECK: DBG_VALUE $edi, $noreg, [[BAZVAR]]
53 ; Expect DBG_VALUE of virtreg,
54 ; CHECK: DBG_VALUE [[ARGREG:%[0-9]+]], $noreg, [[BAZVAR]]
55 ; Label for next block,
56 ; CHECK-LABEL: bb.1.next
57 ; Correctly place dbg.value in the 'next' block.
58 ; CHECK: DBG_VALUE [[ARGREG]], $noreg, [[XYZVAR]]
60 ; INSTRREF-LABEL: body
61 ; INSTRREF: DBG_PHI $edi, 1
62 ; INSTRREF: DBG_VALUE $edi, $noreg, [[BAZVAR]]
63 ; INSTRREF-LABEL: bb.1.next
64 ; INSTRREF: DBG_INSTR_REF [[XYZVAR]], {{.+}}, dbg-instr-ref(1, 0)
\r
66 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
67 target triple = "x86_64-unknown-linux-gnu"
71 define dso_local i32 @bar(i32, i32) local_unnamed_addr !dbg !7 {
72 %3 = srem i32 %1, %0, !dbg !15
73 call void @llvm.dbg.value(metadata i32 %0, metadata !12, metadata !DIExpression()), !dbg !16
77 call void @llvm.dbg.value(metadata i32 %0, metadata !17, metadata !DIExpression()), !dbg !22
78 %4 = tail call i32 @ext(), !dbg !24
79 %5 = mul nsw i32 %3, %4, !dbg !25
80 %6 = add i32 %5, %0, !dbg !25
84 ; Function Attrs: nounwind readnone speculatable
85 declare void @llvm.dbg.value(metadata, metadata, metadata)
88 !llvm.module.flags = !{!3, !4, !5}
91 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2, nameTableKind: None)
92 !1 = !DIFile(filename: "test.c", directory: ".")
94 !3 = !{i32 2, !"Dwarf Version", i32 4}
95 !4 = !{i32 2, !"Debug Info Version", i32 3}
96 !5 = !{i32 1, !"wchar_size", i32 4}
97 !6 = !{!"clang version 8.0.0"}
98 !7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 19, type: !8, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
99 !8 = !DISubroutineType(types: !9)
100 !9 = !{!10, !10, !10}
101 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
103 !12 = !DILocalVariable(name: "baz", arg: 1, scope: !7, file: !1, line: 19, type: !10)
104 !15 = !DILocation(line: 35, column: 7, scope: !7)
105 !16 = !DILocation(line: 19, column: 9, scope: !7)
106 !17 = !DILocalVariable(name: "xyzzy", arg: 1, scope: !18, file: !1, line: 10, type: !10)
107 !18 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 10, type: !19, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !21)
108 !19 = !DISubroutineType(types: !20)
111 !22 = !DILocation(line: 10, column: 9, scope: !18, inlinedAt: !23)
112 !23 = distinct !DILocation(line: 36, column: 10, scope: !7)
113 !24 = !DILocation(line: 12, column: 11, scope: !18, inlinedAt: !23)
114 !25 = !DILocation(line: 37, column: 3, scope: !7)