xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/empty-block.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -S %s -passes=simplifycfg -o - \
2; RUN: | FileCheck %s
3; RUN: opt --try-experimental-debuginfo-iterators -S %s -passes=simplifycfg -o - \
4; RUN: | FileCheck %s
5
6;; $ cat test.cpp
7;; class a {};
8;; void operator*(a, float &);
9;; class b {
10;; public:
11;;   a c;
12;; };
13;; int d;
14;; class e {
15;;   b g[3];
16;;   float f;
17;;   void i();
18;; };
19;; void e::i() {
20;;   float h;
21;;   g[d].c *h;
22;;   if (h)
23;;     h = f;
24;;   else
25;;     h = f;
26;; }
27;; Generated by grabbing IR before simplifycfg in:
28;; $ clang++ -O2 -g -c test.cpp -Xclang -fexperimental-assignment-tracking
29
30;; if.then and if.else each only have a dbg.assign and br instruction.
31;; SimplifyCFG will remove these blocks. Check that the dbg.assign intrinsics
32;; are sunk into the succ beforehand.
33
34; CHECK: entry:
35;; -- alloca dbg.assign
36; CHECK: #dbg_assign(i1 undef
37;; -- sunk dbg.assigns
38; CHECK: #dbg_assign(float undef, ![[var:[0-9]+]], !DIExpression(), ![[id:[0-9]+]], ptr %h, !DIExpression(),
39; CHECK-NEXT: #dbg_assign(float undef, ![[var]], !DIExpression(), ![[id]], ptr %h, !DIExpression(),
40; CHECK-NEXT: %storemerge.in = getelementptr
41; CHECK-NEXT: %storemerge = load float
42; CHECK-NEXT: store float %storemerge, ptr %h, align 4{{.+}}!DIAssignID ![[id]]
43; CHECK: ret void
44
45%class.e = type { [3 x %class.b], float }
46%class.b = type { %class.a }
47%class.a = type { i8 }
48
49@d = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
50
51; Function Attrs: uwtable
52define dso_local void @_ZN1e1iEv(ptr %this) local_unnamed_addr #0 align 2 !dbg !11 {
53entry:
54  %h = alloca float, align 4, !DIAssignID !32
55  call void @llvm.dbg.assign(metadata i1 undef, metadata !31, metadata !DIExpression(), metadata !32, metadata ptr %h, metadata !DIExpression()), !dbg !33
56  %0 = bitcast ptr %h to ptr, !dbg !34
57  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #4, !dbg !34
58  call void @_Zml1aRf(ptr nonnull align 4 dereferenceable(4) %h), !dbg !35
59  %1 = load float, ptr %h, align 4, !dbg !36
60  %tobool = fcmp une float %1, 0.000000e+00, !dbg !36
61  br i1 %tobool, label %if.then, label %if.else, !dbg !42
62
63if.then:                                          ; preds = %entry
64  call void @llvm.dbg.assign(metadata float undef, metadata !31, metadata !DIExpression(), metadata !43, metadata ptr %h, metadata !DIExpression()), !dbg !33
65  br label %if.end, !dbg !44
66
67if.else:                                          ; preds = %entry
68  call void @llvm.dbg.assign(metadata float undef, metadata !31, metadata !DIExpression(), metadata !43, metadata ptr %h, metadata !DIExpression()), !dbg !33
69  br label %if.end
70
71if.end:                                           ; preds = %if.else, %if.then
72  %storemerge.in = getelementptr inbounds %class.e, ptr %this, i64 0, i32 1, !dbg !45
73  %storemerge = load float, ptr %storemerge.in, align 4, !dbg !45
74  store float %storemerge, ptr %h, align 4, !dbg !45, !DIAssignID !43
75  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #4, !dbg !48
76  ret void, !dbg !48
77}
78
79declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
80declare !dbg !49 dso_local void @_Zml1aRf(ptr nonnull align 4 dereferenceable(4)) local_unnamed_addr #2
81declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
82declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #3
83
84!llvm.dbg.cu = !{!2}
85!llvm.module.flags = !{!7, !8, !9, !1000}
86!llvm.ident = !{!10}
87
88!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
89!1 = distinct !DIGlobalVariable(name: "d", scope: !2, file: !3, line: 7, type: !6, isLocal: false, isDefinition: true)
90!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
91!3 = !DIFile(filename: "test.cpp", directory: "/")
92!4 = !{}
93!5 = !{!0}
94!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
95!7 = !{i32 7, !"Dwarf Version", i32 4}
96!8 = !{i32 2, !"Debug Info Version", i32 3}
97!9 = !{i32 1, !"wchar_size", i32 4}
98!10 = !{!"clang version 12.0.0"}
99!11 = distinct !DISubprogram(name: "i", linkageName: "_ZN1e1iEv", scope: !12, file: !3, line: 13, type: !25, scopeLine: 13, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, declaration: !24, retainedNodes: !28)
100!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "e", file: !3, line: 8, size: 64, flags: DIFlagTypePassByValue, elements: !13, identifier: "_ZTS1e")
101!13 = !{!14, !22, !24}
102!14 = !DIDerivedType(tag: DW_TAG_member, name: "g", scope: !12, file: !3, line: 9, baseType: !15, size: 24)
103!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !16, size: 24, elements: !20)
104!16 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "b", file: !3, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !17, identifier: "_ZTS1b")
105!17 = !{!18}
106!18 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !16, file: !3, line: 5, baseType: !19, size: 8, flags: DIFlagPublic)
107!19 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !3, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !4, identifier: "_ZTS1a")
108!20 = !{!21}
109!21 = !DISubrange(count: 3)
110!22 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !12, file: !3, line: 10, baseType: !23, size: 32, offset: 32)
111!23 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
112!24 = !DISubprogram(name: "i", linkageName: "_ZN1e1iEv", scope: !12, file: !3, line: 11, type: !25, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
113!25 = !DISubroutineType(types: !26)
114!26 = !{null, !27}
115!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
116!28 = !{!29, !31}
117!29 = !DILocalVariable(name: "this", arg: 1, scope: !11, type: !30, flags: DIFlagArtificial | DIFlagObjectPointer)
118!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
119!31 = !DILocalVariable(name: "h", scope: !11, file: !3, line: 14, type: !23)
120!32 = distinct !DIAssignID()
121!33 = !DILocation(line: 0, scope: !11)
122!34 = !DILocation(line: 14, column: 3, scope: !11)
123!35 = !DILocation(line: 15, column: 10, scope: !11)
124!36 = !DILocation(line: 16, column: 7, scope: !37)
125!37 = distinct !DILexicalBlock(scope: !11, file: !3, line: 16, column: 7)
126!42 = !DILocation(line: 16, column: 7, scope: !11)
127!43 = distinct !DIAssignID()
128!44 = !DILocation(line: 17, column: 5, scope: !37)
129!45 = !DILocation(line: 0, scope: !37)
130!48 = !DILocation(line: 20, column: 1, scope: !11)
131!49 = !DISubprogram(name: "operator*", linkageName: "_Zml1aRf", scope: !3, file: !3, line: 2, type: !50, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)
132!50 = !DISubroutineType(types: !51)
133!51 = !{null, !19, !52}
134!52 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !23, size: 64)
135!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
136