xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/rewrite.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 example() {
21;;   LargeStruct S = {0};
22;;   S.Var = Glob;
23;;   return S.Var;
24;; }
25;; $ clang test.cpp -Xclang -disable-llvm-passes -O2 -g -c -S -emit-llvm -o -
26
27; CHECK: entry:
28; CHECK-NEXT:   %S.sroa.0 = alloca { i32, i32, i32 }, align 8, !DIAssignID ![[ID_1:[0-9]+]]
29; CHECK-NEXT:   #dbg_assign(i1 undef, ![[VAR:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 96), ![[ID_1]], ptr %S.sroa.0, !DIExpression(),
30
31;; The middle slice has been promoted, so the alloca has gone away.
32
33; CHECK-NEXT:   %S.sroa.5 = alloca { i32, i32, i32 }, align 8, !DIAssignID ![[ID_3:[0-9]+]]
34; CHECK-NEXT:   #dbg_assign(i1 undef, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 128, 96), ![[ID_3]], ptr %S.sroa.5, !DIExpression(),
35
36;; The memset has been sliced up (middle slice removed).
37; CHECK: call void @llvm.memset{{.*}}(ptr align 8 %S.sroa.0, i8 0, i64 12, i1 false), !dbg !{{.+}}, !DIAssignID ![[ID_5:[0-9]+]]
38; CHECK: call void @llvm.memset{{.*}}(ptr align 8 %S.sroa.5, i8 0, i64 12, i1 false), !dbg !{{.+}}, !DIAssignID ![[ID_6:[0-9]+]]
39
40; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 0, 96), ![[ID_5]], ptr %S.sroa.0, !DIExpression(),
41;; Check the middle slice (no memset) gets a correct dbg.assign.
42; CHECK-NEXT: #dbg_value(i32 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 96, 32),
43; CHECK-NEXT:   #dbg_assign(i8 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 128, 96), ![[ID_6]], ptr %S.sroa.5, !DIExpression(),
44
45;; mem2reg promotes the load/store to the middle slice created by SROA:
46; CHECK-NEXT: %0 = load i32, ptr @Glob, align 4, !dbg !{{.+}}
47; CHECK-NEXT: #dbg_value(i32 %0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 96, 32),
48
49target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
50
51%struct.LargeStruct = type { i32, i32, i32, i32, i32, i32, i32 }
52
53@Glob = dso_local global i32 0, align 4, !dbg !0
54@Cond = dso_local global i8 0, align 1, !dbg !6
55
56; Function Attrs: nounwind uwtable mustprogress
57define dso_local i32 @_Z7examplev() #0 !dbg !14 {
58entry:
59  %S = alloca %struct.LargeStruct, align 4, !DIAssignID !28
60  call void @llvm.dbg.assign(metadata i1 undef, metadata !18, metadata !DIExpression(), metadata !28, metadata ptr %S, metadata !DIExpression()), !dbg !29
61  %0 = bitcast ptr %S to ptr, !dbg !30
62  call void @llvm.lifetime.start.p0(i64 28, ptr %0) #4, !dbg !30
63  %1 = bitcast ptr %S to ptr, !dbg !31
64  call void @llvm.memset.p0.i64(ptr align 4 %1, i8 0, i64 28, i1 false), !dbg !31, !DIAssignID !32
65  call void @llvm.dbg.assign(metadata i8 0, metadata !18, metadata !DIExpression(), metadata !32, metadata ptr %1, metadata !DIExpression()), !dbg !31
66  %2 = load i32, ptr @Glob, align 4, !dbg !33
67  %Var = getelementptr inbounds %struct.LargeStruct, ptr %S, i32 0, i32 3, !dbg !38
68  store i32 %2, ptr %Var, align 4, !dbg !39, !DIAssignID !42
69  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
70  %Var1 = getelementptr inbounds %struct.LargeStruct, ptr %S, i32 0, i32 3, !dbg !43
71  %3 = load i32, ptr %Var1, align 4, !dbg !43
72  %4 = bitcast ptr %S to ptr, !dbg !44
73  call void @llvm.lifetime.end.p0(i64 28, ptr %4) #4, !dbg !44
74  ret i32 %3, !dbg !45
75}
76
77; Function Attrs: argmemonly nofree nosync nounwind willreturn
78declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
79
80; Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
81declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2
82
83; Function Attrs: argmemonly nofree nosync nounwind willreturn
84declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
85
86; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
87declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #3
88
89!llvm.dbg.cu = !{!2}
90!llvm.module.flags = !{!10, !11, !12, !1000}
91!llvm.ident = !{!13}
92
93!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
94!1 = distinct !DIGlobalVariable(name: "Glob", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true)
95!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)
96!3 = !DIFile(filename: "test.cpp", directory: "/")
97!4 = !{}
98!5 = !{!0, !6}
99!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
100!7 = distinct !DIGlobalVariable(name: "Cond", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true)
101!8 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
102!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
103!10 = !{i32 7, !"Dwarf Version", i32 4}
104!11 = !{i32 2, !"Debug Info Version", i32 3}
105!12 = !{i32 1, !"wchar_size", i32 4}
106!13 = !{!"clang version 12.0.0"}
107!14 = distinct !DISubprogram(name: "example", linkageName: "_Z7examplev", scope: !3, file: !3, line: 9, type: !15, scopeLine: 9, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !17)
108!15 = !DISubroutineType(types: !16)
109!16 = !{!9}
110!17 = !{!18}
111!18 = !DILocalVariable(name: "S", scope: !14, file: !3, line: 10, type: !19)
112!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "LargeStruct", file: !3, line: 2, size: 224, flags: DIFlagTypePassByValue, elements: !20, identifier: "_ZTS11LargeStruct")
113!20 = !{!21, !22, !23, !24, !25, !26, !27}
114!21 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !19, file: !3, line: 3, baseType: !9, size: 32)
115!22 = !DIDerivedType(tag: DW_TAG_member, name: "B", scope: !19, file: !3, line: 3, baseType: !9, size: 32, offset: 32)
116!23 = !DIDerivedType(tag: DW_TAG_member, name: "C", scope: !19, file: !3, line: 3, baseType: !9, size: 32, offset: 64)
117!24 = !DIDerivedType(tag: DW_TAG_member, name: "Var", scope: !19, file: !3, line: 4, baseType: !9, size: 32, offset: 96)
118!25 = !DIDerivedType(tag: DW_TAG_member, name: "D", scope: !19, file: !3, line: 5, baseType: !9, size: 32, offset: 128)
119!26 = !DIDerivedType(tag: DW_TAG_member, name: "E", scope: !19, file: !3, line: 5, baseType: !9, size: 32, offset: 160)
120!27 = !DIDerivedType(tag: DW_TAG_member, name: "F", scope: !19, file: !3, line: 5, baseType: !9, size: 32, offset: 192)
121!28 = distinct !DIAssignID()
122!29 = !DILocation(line: 0, scope: !14)
123!30 = !DILocation(line: 10, column: 3, scope: !14)
124!31 = !DILocation(line: 10, column: 15, scope: !14)
125!32 = distinct !DIAssignID()
126!33 = !DILocation(line: 11, column: 11, scope: !14)
127!38 = !DILocation(line: 11, column: 5, scope: !14)
128!39 = !DILocation(line: 11, column: 9, scope: !14)
129!42 = distinct !DIAssignID()
130!43 = !DILocation(line: 12, column: 12, scope: !14)
131!44 = !DILocation(line: 13, column: 1, scope: !14)
132!45 = !DILocation(line: 12, column: 3, scope: !14)
133!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
134