xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/store.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=sroa,verify -S %s -o - \
2; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
3; RUN: opt --try-experimental-debuginfo-iterators -passes=sroa,verify -S %s -o - \
4; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
5
6; Check that the new slices of an alloca and memset intructions get dbg.assign
7; intrinsics with the correct fragment info. Ensure that only the
8; value-expression gets fragment info; that the address-expression remains
9; untouched.
10
11;; $ cat test.cpp
12;; void do_something();
13;; struct LargeStruct {
14;;   int A, B, C;
15;;   int Var;
16;;   int D, E, F;
17;; };
18;; int Glob;
19;; bool Cond;
20;; int use(LargeStruct);
21;; int example() {
22;;   LargeStruct S = {0};
23;;   S.Var = Glob;
24;;   use(S);
25;;   return S.Var;
26;; }
27;; $ clang test.cpp -Xclang -disable-llvm-passes -O2 -g -c -S -emit-llvm -o - \
28;;   | opt -passes=declare-to-assign -S -o -
29
30; CHECK: entry:
31; CHECK-NEXT:   %S.sroa.0 = alloca { i32, i32, i32 }, align 8, !DIAssignID ![[ID_1:[0-9]+]]
32; CHECK-NEXT:   #dbg_assign(i1 undef, ![[VAR:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 96), ![[ID_1]], ptr %S.sroa.0, !DIExpression(),
33
34; CHECK-NEXT:   %S.sroa.4 = alloca { i32, i32, i32 }, align 8, !DIAssignID ![[ID_3:[0-9]+]]
35; CHECK-NEXT:   #dbg_assign(i1 undef, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 128, 96), ![[ID_3]], ptr %S.sroa.4, !DIExpression(),
36
37;; The memset has been split into [0, 96)[96, 128)[128, 224) bit slices. The
38;; memset for the middle slice has been removed.
39; CHECK: call void @llvm.memset{{.*}}(ptr align 8 %S.sroa.0, i8 0, i64 12, i1 false), !dbg !{{.+}}, !DIAssignID ![[ID_4:[0-9]+]]
40; CHECK-NEXT: call void @llvm.memset{{.*}}(ptr align 8 %S.sroa.4, i8 0, i64 12, i1 false), !dbg !{{.+}}, !DIAssignID ![[ID_5:[0-9]+]]
41
42; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 0, 96), ![[ID_4]], ptr %S.sroa.0, !DIExpression(),
43;; This is the one we care about most in this test: check that a memset->store
44;; gets a correct dbg.assign.
45; CHECK-NEXT: #dbg_value(i32 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 96, 32),
46; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 128, 96), ![[ID_5]], ptr %S.sroa.4, !DIExpression(),
47
48;; The load from global+store becomes a load.
49;; FIXME: In reality it is actually stored again later on.
50; CHECK-NEXT: %0 = load i32, ptr @Glob, align 4, !dbg !{{.+}}
51; CHECK-NEXT: #dbg_value(i32 %0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 96, 32),
52
53
54target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
55
56%struct.LargeStruct = type { i32, i32, i32, i32, i32, i32, i32 }
57
58@Glob = dso_local global i32 0, align 4, !dbg !0
59@Cond = dso_local global i8 0, align 1, !dbg !6
60
61; Function Attrs: uwtable mustprogress
62define dso_local i32 @_Z7examplev() #0 !dbg !14 {
63entry:
64  %S = alloca %struct.LargeStruct, align 4, !DIAssignID !28
65  call void @llvm.dbg.assign(metadata i1 undef, metadata !18, metadata !DIExpression(), metadata !28, metadata ptr %S, metadata !DIExpression()), !dbg !29
66  %agg.tmp = alloca %struct.LargeStruct, align 8
67  %0 = bitcast ptr %S to ptr, !dbg !30
68  %1 = bitcast ptr %S to ptr, !dbg !31
69  call void @llvm.memset.p0.i64(ptr align 4 %1, i8 0, i64 28, i1 false), !dbg !31, !DIAssignID !32
70  call void @llvm.dbg.assign(metadata i8 0, metadata !18, metadata !DIExpression(), metadata !32, metadata ptr %1, metadata !DIExpression()), !dbg !31
71  %2 = load i32, ptr @Glob, align 4, !dbg !33
72  %Var = getelementptr inbounds %struct.LargeStruct, ptr %S, i32 0, i32 3, !dbg !38
73  store i32 %2, ptr %Var, align 4, !dbg !39, !DIAssignID !42
74  call void @llvm.dbg.assign(metadata i32 %2, metadata !18, metadata !DIExpression(DW_OP_LLVM_fragment, 96, 32), metadata !42, metadata ptr %Var, metadata !DIExpression()), !dbg !39
75  %3 = bitcast ptr %agg.tmp to ptr, !dbg !43
76  %4 = bitcast ptr %S to ptr, !dbg !43
77  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %4, i64 28, i1 false), !dbg !43
78  %call = call i32 @_Z3use11LargeStruct(ptr byval(%struct.LargeStruct) align 8 %agg.tmp), !dbg !45
79  %Var1 = getelementptr inbounds %struct.LargeStruct, ptr %S, i32 0, i32 3, !dbg !46
80  %5 = load i32, ptr %Var1, align 4, !dbg !46
81  %6 = bitcast ptr %S to ptr, !dbg !47
82  ret i32 %5, !dbg !48
83}
84
85
86declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2
87declare !dbg !49 dso_local i32 @_Z3use11LargeStruct(ptr byval(%struct.LargeStruct) align 8) #3
88declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1
89declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #4
90
91!llvm.dbg.cu = !{!2}
92!llvm.module.flags = !{!10, !11, !12, !1000}
93!llvm.ident = !{!13}
94
95!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
96!1 = distinct !DIGlobalVariable(name: "Glob", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true)
97!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
98!3 = !DIFile(filename: "test.cpp", directory: "/")
99!4 = !{}
100!5 = !{!0, !6}
101!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
102!7 = distinct !DIGlobalVariable(name: "Cond", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true)
103!8 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
104!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
105!10 = !{i32 7, !"Dwarf Version", i32 4}
106!11 = !{i32 2, !"Debug Info Version", i32 3}
107!12 = !{i32 1, !"wchar_size", i32 4}
108!13 = !{!"clang version 12.0.0"}
109!14 = distinct !DISubprogram(name: "example", linkageName: "_Z7examplev", scope: !3, file: !3, line: 10, type: !15, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !17)
110!15 = !DISubroutineType(types: !16)
111!16 = !{!9}
112!17 = !{!18}
113!18 = !DILocalVariable(name: "S", scope: !14, file: !3, line: 11, type: !19)
114!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "LargeStruct", file: !3, line: 2, size: 224, flags: DIFlagTypePassByValue, elements: !20, identifier: "_ZTS11LargeStruct")
115!20 = !{!21, !22, !23, !24, !25, !26, !27}
116!21 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !19, file: !3, line: 3, baseType: !9, size: 32)
117!22 = !DIDerivedType(tag: DW_TAG_member, name: "B", scope: !19, file: !3, line: 3, baseType: !9, size: 32, offset: 32)
118!23 = !DIDerivedType(tag: DW_TAG_member, name: "C", scope: !19, file: !3, line: 3, baseType: !9, size: 32, offset: 64)
119!24 = !DIDerivedType(tag: DW_TAG_member, name: "Var", scope: !19, file: !3, line: 4, baseType: !9, size: 32, offset: 96)
120!25 = !DIDerivedType(tag: DW_TAG_member, name: "D", scope: !19, file: !3, line: 5, baseType: !9, size: 32, offset: 128)
121!26 = !DIDerivedType(tag: DW_TAG_member, name: "E", scope: !19, file: !3, line: 5, baseType: !9, size: 32, offset: 160)
122!27 = !DIDerivedType(tag: DW_TAG_member, name: "F", scope: !19, file: !3, line: 5, baseType: !9, size: 32, offset: 192)
123!28 = distinct !DIAssignID()
124!29 = !DILocation(line: 0, scope: !14)
125!30 = !DILocation(line: 11, column: 3, scope: !14)
126!31 = !DILocation(line: 11, column: 15, scope: !14)
127!32 = distinct !DIAssignID()
128!33 = !DILocation(line: 12, column: 11, scope: !14)
129!38 = !DILocation(line: 12, column: 5, scope: !14)
130!39 = !DILocation(line: 12, column: 9, scope: !14)
131!42 = distinct !DIAssignID()
132!43 = !DILocation(line: 13, column: 7, scope: !14)
133!45 = !DILocation(line: 13, column: 3, scope: !14)
134!46 = !DILocation(line: 14, column: 12, scope: !14)
135!47 = !DILocation(line: 15, column: 1, scope: !14)
136!48 = !DILocation(line: 14, column: 3, scope: !14)
137!49 = !DISubprogram(name: "use", linkageName: "_Z3use11LargeStruct", scope: !3, file: !3, line: 9, type: !50, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)
138!50 = !DISubroutineType(types: !51)
139!51 = !{!9, !19}
140!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
141