• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -mtriple=x86_64-unknown-unknown -start-after=codegenprepare -stop-before=finalize-isel %s -o - | FileCheck %s
2
3; Test the movement of dbg.values of arguments. SelectionDAG tries to be
4; helpful and places DBG_VALUEs of Arguments at the start of functions.
5; Unfortunately, this doesn't necessarily make sense, as one can specify an
6; Argument IR Value as a variable location anywhere in the program.
7;
8; Distinguish cases where we want to hoist DBG_VALUEs, and those where we
9; don't, by whether the referred to variable is a parameter to the current
10; function. In the test below, 'xyzzy' is a parameter to an inlined function,
11; but should not be hoisted to the start of the function.
12;
13; Original test case, in which 'xyzzy' became unavailable because its DBG_VALUE
14; landed far from any uses, compiled "clang -O2 -g" with inlining,
15;
16;    int ext(void);
17;
18;    int
19;    foo(int xyzzy)
20;    {
21;      xyzzy = ext() * xyzzy;
22;      xyzzy += 1;
23;      ext();
24;      return xyzzy;
25;    }
26;
27;    int
28;    bar(int baz, int qux)
29;    {
30;      int fish;
31;      switch (qux) {
32;      case 12:        fish = 8;        break;
33;      case 848:       fish = 0;        break;
34;      case 99999:     fish = -1;       break;
35;      default:        fish = 12;
36;      }
37;      qux %= fish;
38;      qux += foo(baz);
39;      return qux;
40;    }
41
42; CHECK: [[BAZVAR:![0-9]+]] = !DILocalVariable(name: "baz",
43; CHECK: [[XYZVAR:![0-9]+]] = !DILocalVariable(name: "xyzzy",
44
45; Start of MIR function block,
46; CHECK-LABEL: body
47; Expect DBG_VALUE of physreg,
48; CHECK:       DBG_VALUE $edi, $noreg, [[BAZVAR]]
49; Expect DBG_VALUE of virtreg,
50; CHECK:       DBG_VALUE [[ARGREG:%[0-9]+]], $noreg, [[BAZVAR]]
51; Label for next block,
52; CHECK-LABEL: bb.1.next
53; Correctly place dbg.value in the 'next' block.
54; CHECK:       DBG_VALUE [[ARGREG]], $noreg, [[XYZVAR]]
55
56target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
57target triple = "x86_64-unknown-linux-gnu"
58
59declare i32 @ext()
60
61define dso_local i32 @bar(i32, i32) local_unnamed_addr !dbg !7 {
62  %3 = srem i32 %1, %0, !dbg !15
63  call void @llvm.dbg.value(metadata i32 %0, metadata !12, metadata !DIExpression()), !dbg !16
64  br label %next
65
66next:                                             ; preds = %2
67  call void @llvm.dbg.value(metadata i32 %0, metadata !17, metadata !DIExpression()), !dbg !22
68  %4 = tail call i32 @ext(), !dbg !24
69  %5 = mul nsw i32 %3, %4, !dbg !25
70  %6 = add i32 %5, %0, !dbg !25
71  ret i32 %6, !dbg !25
72}
73
74; Function Attrs: nounwind readnone speculatable
75declare void @llvm.dbg.value(metadata, metadata, metadata)
76
77!llvm.dbg.cu = !{!0}
78!llvm.module.flags = !{!3, !4, !5}
79!llvm.ident = !{!6}
80
81!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2, nameTableKind: None)
82!1 = !DIFile(filename: "test.c", directory: ".")
83!2 = !{}
84!3 = !{i32 2, !"Dwarf Version", i32 4}
85!4 = !{i32 2, !"Debug Info Version", i32 3}
86!5 = !{i32 1, !"wchar_size", i32 4}
87!6 = !{!"clang version 8.0.0"}
88!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 19, type: !8, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
89!8 = !DISubroutineType(types: !9)
90!9 = !{!10, !10, !10}
91!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
92!11 = !{!12}
93!12 = !DILocalVariable(name: "baz", arg: 1, scope: !7, file: !1, line: 19, type: !10)
94!15 = !DILocation(line: 35, column: 7, scope: !7)
95!16 = !DILocation(line: 19, column: 9, scope: !7)
96!17 = !DILocalVariable(name: "xyzzy", arg: 1, scope: !18, file: !1, line: 10, type: !10)
97!18 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 10, type: !19, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !21)
98!19 = !DISubroutineType(types: !20)
99!20 = !{!10, !10}
100!21 = !{!17}
101!22 = !DILocation(line: 10, column: 9, scope: !18, inlinedAt: !23)
102!23 = distinct !DILocation(line: 36, column: 10, scope: !7)
103!24 = !DILocation(line: 12, column: 11, scope: !18, inlinedAt: !23)
104!25 = !DILocation(line: 37, column: 3, scope: !7)
105