xref: /llvm-project/llvm/test/DebugInfo/assignment-tracking/X86/DSE.ll (revision 30845e8ab46c416a2e333eb84239e9ec71e92617)
1; RUN: llc %s -stop-before=finalize-isel -o - \
2; RUN: | FileCheck %s
3
4
5; RUN: llc --try-experimental-debuginfo-iterators %s -stop-before=finalize-isel -o - \
6; RUN: | FileCheck %s
7
8; Check basic lowering behaviour of dbg.assign intrinsics. The first
9; assignment to `local`, which has been DSE'd, should be represented with a
10; constant value DBG_VALUE. The second assignment should have a DBG_VALUE
11; describing the stack home of the variable.
12
13; $ cat test.c
14; void esc(int*);
15; void fun() {
16;   int local = 5;
17;   // ^ killed by v
18;   local = 6;
19;   esc(&local);
20; }
21; $ clang -O2 -g -emit -llvm -S test.c -o -
22
23; CHECK: ![[LOCAL:[0-9]+]] = !DILocalVariable(name: "local",
24; CHECK: DBG_VALUE 5, $noreg, ![[LOCAL]], !DIExpression(), debug-location ![[DBG:[0-9]+]]
25; CHECK-NEXT: MOV32mi [[DEST:.*]], 1, $noreg, 0, $noreg, 6
26; CHECK-NEXT: DBG_VALUE [[DEST]], $noreg, ![[LOCAL]], !DIExpression(DW_OP_deref), debug-location ![[DBG]]
27
28target triple = "x86_64-unknown-linux-gnu"
29
30define dso_local void @fun() local_unnamed_addr !dbg !7 {
31entry:
32  %local = alloca i32, align 4
33  call void @llvm.dbg.assign(metadata i32 5, metadata !11, metadata !DIExpression(), metadata !30, metadata ptr %local, metadata !DIExpression()), !dbg !16
34  store i32 6, ptr %local, align 4, !dbg !23, !DIAssignID !31
35  call void @llvm.dbg.assign(metadata i32 6, metadata !11, metadata !DIExpression(), metadata !31, metadata ptr %local, metadata !DIExpression()), !dbg !16
36  call void @esc(ptr nonnull %local), !dbg !24
37  ret void, !dbg !25
38}
39
40declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
41
42declare !dbg !26 dso_local void @esc(ptr) local_unnamed_addr
43
44!llvm.dbg.cu = !{!0}
45!llvm.module.flags = !{!3, !4, !5, !1000}
46!llvm.ident = !{!6}
47
48!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
49!1 = !DIFile(filename: "test.c", directory: "/")
50!2 = !{}
51!3 = !{i32 7, !"Dwarf Version", i32 4}
52!4 = !{i32 2, !"Debug Info Version", i32 3}
53!5 = !{i32 1, !"wchar_size", i32 4}
54!6 = !{!"clang version 12.0.0"}
55!7 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
56!8 = !DISubroutineType(types: !9)
57!9 = !{null}
58!10 = !{!11}
59!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 3, type: !12)
60!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
61!14 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !12)
62!15 = !DILocation(line: 3, column: 3, scope: !7)
63!16 = !DILocation(line: 0, scope: !7)
64!17 = !DILocation(line: 4, column: 3, scope: !7)
65!18 = !DILocation(line: 4, column: 16, scope: !7)
66!23 = !DILocation(line: 5, column: 9, scope: !7)
67!24 = !DILocation(line: 6, column: 3, scope: !7)
68!25 = !DILocation(line: 7, column: 1, scope: !7)
69!26 = !DISubprogram(name: "esc", scope: !1, file: !1, line: 1, type: !27, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
70!27 = !DISubroutineType(types: !28)
71!28 = !{null, !29}
72!29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
73!30 = distinct !DIAssignID()
74!31 = distinct !DIAssignID()
75
76!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
77