xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/split-pre-fragmented-store.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -S -passes=sroa -sroa-skip-mem2reg %s \
2; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
3; RUN: opt --try-experimental-debuginfo-iterators -S -passes=sroa -sroa-skip-mem2reg %s \
4; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
5
6;; IR hand-modified, originally generated from:
7;; struct Pair { int a; int b; };
8;; Pair getVar();
9;; int fun() {
10;;   Pair var;
11;;   var = getVar();
12;;   return var.b;
13;; }
14;; Modification: split the dbg.assign linked the the memcpy(64 bits) into two,
15;; each describing a 32 bit fragment.
16;;
17;; Check that assignment tracking updates in SROA work when the store being
18;; split is described with one dbg.assign (covering different fragments). The
19;; store may have been already split and then merged again at some point.
20
21;; Alloca for var.a and associated dbg.assign:
22; CHECK: %var.sroa.0 = alloca i32, align 4, !DIAssignID ![[id_1:[0-9]+]]
23; CHECK-NEXT: #dbg_assign(i1 undef, ![[var:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 32), ![[id_1]], ptr %var.sroa.0, !DIExpression(),
24
25;; Alloca for var.b and associated dbg.assign:
26; CHECK-NEXT: %var.sroa.1 = alloca i32, align 4, !DIAssignID ![[id_2:[0-9]+]]
27; CHECK-NEXT: #dbg_assign(i1 undef, ![[var]], !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[id_2]], ptr %var.sroa.1, !DIExpression(),
28
29;; Store to var.b (split from store to var) and associated dbg.assigns. The
30;; dbg.assign for the fragment covering the (pre-split) assignment to var.a
31;; should not be linked to the store.
32; CHECK: store i32 %[[v:.*]], ptr %var.sroa.1,{{.*}}!DIAssignID ![[id_3:[0-9]+]]
33; CHECK-NEXT: #dbg_assign(i32 %{{.*var\.sroa\.0.*}}, ![[var]], !DIExpression(DW_OP_LLVM_fragment, 0, 32), ![[id_4:[0-9]+]], ptr %var.sroa.0, !DIExpression(),
34; CHECK-NEXT: #dbg_assign(i32 %[[v]], ![[var]], !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[id_3]], ptr %var.sroa.1, !DIExpression(),
35
36; CHECK-DAG: ![[id_1]] = distinct !DIAssignID()
37; CHECK-DAG: ![[id_2]] = distinct !DIAssignID()
38; CHECK-DAG: ![[id_3]] = distinct !DIAssignID()
39; CHECK-DAG: ![[id_4]] = distinct !DIAssignID()
40
41%struct.Pair = type { i32, i32 }
42
43define dso_local noundef i32 @_Z3funv() !dbg !9 {
44entry:
45  %var = alloca %struct.Pair, align 4, !DIAssignID !19
46  call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(), metadata !19, metadata ptr %var, metadata !DIExpression()), !dbg !20
47  %ref.tmp = alloca %struct.Pair, align 4
48  %call = call i64 @_Z6getVarv(), !dbg !22
49  store i64 %call, ptr %ref.tmp, align 4, !dbg !22
50  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %var, ptr align 4 %ref.tmp, i64 8, i1 false), !dbg !23, !DIAssignID !29
51  call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32), metadata !29, metadata ptr %var, metadata !DIExpression()), !dbg !20
52  call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !29, metadata ptr %var, metadata !DIExpression(DW_OP_plus, DW_OP_constu, 4)), !dbg !20
53  %b = getelementptr inbounds %struct.Pair, ptr %var, i32 0, i32 1, !dbg !31
54  %0 = load i32, ptr %b, align 4, !dbg !31
55  ret i32 %0, !dbg !35
56}
57
58declare !dbg !36 i64 @_Z6getVarv()
59declare void @llvm.dbg.declare(metadata, metadata, metadata)
60declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)
61declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
62
63!llvm.dbg.cu = !{!0}
64!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
65!llvm.ident = !{!8}
66
67!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
68!1 = !DIFile(filename: "test.cpp", directory: "/")
69!2 = !{i32 7, !"Dwarf Version", i32 5}
70!3 = !{i32 2, !"Debug Info Version", i32 3}
71!4 = !{i32 1, !"wchar_size", i32 4}
72!5 = !{i32 8, !"PIC Level", i32 2}
73!6 = !{i32 7, !"PIE Level", i32 2}
74!7 = !{i32 7, !"uwtable", i32 2}
75!8 = !{!"clang version 16.0.0"}
76!9 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 3, type: !10, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
77!10 = !DISubroutineType(types: !11)
78!11 = !{!12}
79!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
80!13 = !{!14}
81!14 = !DILocalVariable(name: "var", scope: !9, file: !1, line: 4, type: !15)
82!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Pair", file: !1, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !16, identifier: "_ZTS4Pair")
83!16 = !{!17, !18}
84!17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 1, baseType: !12, size: 32)
85!18 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !15, file: !1, line: 1, baseType: !12, size: 32, offset: 32)
86!19 = distinct !DIAssignID()
87!20 = !DILocation(line: 0, scope: !9)
88!21 = !DILocation(line: 4, column: 3, scope: !9)
89!22 = !DILocation(line: 5, column: 9, scope: !9)
90!23 = !DILocation(line: 5, column: 7, scope: !9)
91!29 = distinct !DIAssignID()
92!30 = !DILocation(line: 5, column: 3, scope: !9)
93!31 = !DILocation(line: 6, column: 14, scope: !9)
94!34 = !DILocation(line: 7, column: 1, scope: !9)
95!35 = !DILocation(line: 6, column: 3, scope: !9)
96!36 = !DISubprogram(name: "getVar", linkageName: "_Z6getVarv", scope: !1, file: !1, line: 2, type: !37, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !39)
97!37 = !DISubroutineType(types: !38)
98!38 = !{!15}
99!39 = !{}
100