xref: /llvm-project/llvm/test/DebugInfo/assignment-tracking/X86/diamond-3.ll (revision 30845e8ab46c416a2e333eb84239e9ec71e92617)
1; RUN: llc %s -stop-after=finalize-isel -o - \
2; RUN: | FileCheck %s --implicit-check-not=DBG_
3
4
5; RUN: llc --try-experimental-debuginfo-iterators %s -stop-after=finalize-isel -o - \
6; RUN: | FileCheck %s --implicit-check-not=DBG_
7
8;; Hand written to test scenario we can definitely run into in the wild. This
9;; file name includes "diamond" because the idea is that we lose (while
10;; optimizing) one of the diamond branches which was empty except for a debug
11;; intrinsic. In this case, the debug intrinsic linked to the common-and-sunk
12;; store now in if.end. So we've got this:
13;;
14;; entry:          ; -> br if.then, if.end
15;;    mem(a) = !19
16;;    dbg(a) = !21 ; dbg and mem disagree, don't use mem loc.
17;; if.then:        ; -> br if.end
18;;    dbg(a) = !20
19;; if.end:
20;;    mem(a) = !20 ; two preds disagree that !20 is the last assignment, don't
21;;                 ; use mem loc.
22;;    ; This feels highly unfortunate, and highlights the need to reinstate the
23;;    ; memory location at call sites leaking the address (in an ideal world,
24;;    ; the memory location would always be in use at that point and so this
25;;    ; wouldn't be necessary).
26;;    esc(a)       ; force the memory location
27
28;; In real world examples this is caused by InstCombine sinking common code
29;; followed by SimplifyCFG deleting empty-except-for-dbg blocks.
30
31; CHECK-DAG: ![[A:[0-9]+]] = !DILocalVariable(name: "a",
32; CHECK-LABEL: bb.0.entry:
33; CHECK:         DBG_VALUE $edi, $noreg, ![[A]], !DIExpression()
34; CHECK-LABEL: bb.1.if.then:
35; CHECK:         DBG_VALUE 0, $noreg, ![[A]], !DIExpression()
36
37;; === TODO / WISHLIST ===
38; LEBAL-KCEHC: bb.2.if.end:
39; KCEHC:         CALL64pcrel32 target-flags(x86-plt) @es
40; KCEHC:         DBG_VALUE %stack.0.a.addr, $noreg, ![[A]], !DIExpression(DW_OP_deref)
41
42target triple = "x86_64-unknown-linux-gnu"
43
44@g = dso_local local_unnamed_addr global ptr null, align 8, !dbg !0
45
46define dso_local noundef i32 @_Z1fiii(i32 noundef %a, i32 noundef %b, i32 noundef %c) local_unnamed_addr #0 !dbg !12 {
47entry:
48  %a.addr = alloca i32, align 4, !DIAssignID !19
49  call void @llvm.dbg.assign(metadata i1 undef, metadata !16, metadata !DIExpression(), metadata !19, metadata ptr %a.addr, metadata !DIExpression()), !dbg !20
50  call void @llvm.dbg.assign(metadata i32 %a, metadata !16, metadata !DIExpression(), metadata !21, metadata ptr %a.addr, metadata !DIExpression()), !dbg !20
51  %tobool.not = icmp eq i32 %c, 0
52  br i1 %tobool.not, label %if.then, label %if.end
53
54if.then:
55  call void @e()
56  call void @llvm.dbg.assign(metadata i32 0, metadata !16, metadata !DIExpression(), metadata !22, metadata ptr %a.addr, metadata !DIExpression()), !dbg !20
57  br label %if.end
58
59if.end:                                           ; preds = %do.body
60  store i32 0, ptr %a.addr, align 4, !DIAssignID !22
61  call void @es(ptr %a.addr)
62  ret i32 0
63}
64
65declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2
66declare void @e()
67declare void @es(ptr)
68
69!llvm.dbg.cu = !{!2}
70!llvm.module.flags = !{!7, !8, !9, !10, !1000}
71!llvm.ident = !{!11}
72
73!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
74!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, isLocal: false, isDefinition: true)
75!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
76!3 = !DIFile(filename: "test.cpp", directory: "/")
77!4 = !{!0}
78!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
79!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
80!7 = !{i32 7, !"Dwarf Version", i32 5}
81!8 = !{i32 2, !"Debug Info Version", i32 3}
82!9 = !{i32 1, !"wchar_size", i32 4}
83!10 = !{i32 7, !"uwtable", i32 1}
84!11 = !{!"clang version 14.0.0"}
85!12 = distinct !DISubprogram(name: "f", linkageName: "_Z1fiii", scope: !3, file: !3, line: 5, type: !13, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15)
86!13 = !DISubroutineType(types: !14)
87!14 = !{!6, !6, !6, !6}
88!15 = !{!16, !17, !18}
89!16 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !3, line: 5, type: !6)
90!17 = !DILocalVariable(name: "b", arg: 2, scope: !12, file: !3, line: 5, type: !6)
91!18 = !DILocalVariable(name: "c", arg: 3, scope: !12, file: !3, line: 5, type: !6)
92!19 = distinct !DIAssignID()
93!20 = !DILocation(line: 0, scope: !12)
94!21 = distinct !DIAssignID()
95!22 = distinct !DIAssignID()
96!23 = distinct !DIAssignID()
97!28 = distinct !DIAssignID()
98!29 = !DILocation(line: 6, column: 3, scope: !12)
99!30 = !DILocation(line: 8, column: 7, scope: !31)
100!31 = distinct !DILexicalBlock(scope: !12, file: !3, line: 6, column: 6)
101!32 = distinct !DIAssignID()
102!33 = !DILocation(line: 10, column: 5, scope: !31)
103!34 = !DILocation(line: 11, column: 12, scope: !12)
104!35 = !DILocation(line: 11, column: 3, scope: !31)
105!36 = distinct !{!36, !29, !37, !38}
106!37 = !DILocation(line: 11, column: 15, scope: !12)
107!38 = !{!"llvm.loop.mustprogress"}
108!39 = !DILocation(line: 12, column: 3, scope: !12)
109!40 = !DILocation(line: 13, column: 10, scope: !12)
110!41 = !DILocation(line: 13, column: 12, scope: !12)
111!42 = !DILocation(line: 13, column: 3, scope: !12)
112!43 = !DISubprogram(name: "e", linkageName: "_Z1ev", scope: !3, file: !3, line: 2, type: !44, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !46)
113!44 = !DISubroutineType(types: !45)
114!45 = !{null}
115!46 = !{}
116!47 = !DISubprogram(name: "d", linkageName: "_Z1dv", scope: !3, file: !3, line: 1, type: !48, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !46)
117!48 = !DISubroutineType(types: !49)
118!49 = !{!6}
119!50 = !DISubprogram(name: "es", linkageName: "_Z2esPi", scope: !3, file: !3, line: 3, type: !51, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !46)
120!51 = !DISubroutineType(types: !52)
121!52 = !{null, !5}
122!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
123