xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/memcpy.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 memcpy intructions get dbg.assign
7;; intrinsics with the correct fragment info.
8;;
9;; Also check that the new dbg.assign intrinsics are inserted after each split
10;; store. See llvm/test/DebugInfo/Generic/dbg-assign-sroa-id.ll for the
11;; counterpart check. Ensure that only the value-expression gets fragment info;
12;; that the address-expression remains untouched.
13
14;; $ cat test.cpp
15;; struct LargeStruct {
16;;   int A, B, C;
17;;   int Var;
18;;   int D, E, F;
19;; };
20;; LargeStruct From;
21;; int example() {
22;;   LargeStruct To = From;
23;;   return To.Var;
24;; }
25;; $ clang test.cpp -Xclang -fexperimental-assignment-tracking \
26;;     -Xclang -disable-llvm-passes -O2 -g -c -S -emit-llvm -o -
27
28;; Split alloca.
29; CHECK: entry:
30; CHECK-NEXT: %To.sroa.0 = alloca { i32, i32, i32 }, align 8, !DIAssignID ![[ID_1:[0-9]+]]
31; CHECK-NEXT: #dbg_assign({{.+}} undef, ![[TO:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 96), ![[ID_1]], ptr %To.sroa.0, !DIExpression(),
32
33; CHECK-NEXT: %To.sroa.4 = alloca { i32, i32, i32 }, align 8, !DIAssignID ![[ID_3:[0-9]+]]
34; CHECK-NEXT: #dbg_assign({{.+}} undef, ![[TO]], !DIExpression(DW_OP_LLVM_fragment, 128, 96), ![[ID_3]], ptr %To.sroa.4, !DIExpression(),
35
36;; Split memcpy.
37; CHECK: call void @llvm.memcpy{{.*}}(ptr align 8 %To.sroa.0, ptr align 4 @From, i64 12, i1 false),{{.*}}!DIAssignID ![[ID_4:[0-9]+]]
38;; This slice has been split and is promoted.
39; CHECK: %To.sroa.3.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @From, i64 12)
40; CHECK: call void @llvm.memcpy{{.*}}(ptr align 8 %To.sroa.4, ptr align 4 getelementptr inbounds (i8, ptr @From, i64 16), i64 12, i1 false){{.*}}!DIAssignID ![[ID_6:[0-9]+]]
41
42;; Intrinsics for the splits above.
43; CHECK-NEXT: #dbg_assign({{.+}} undef, ![[TO]], !DIExpression(DW_OP_LLVM_fragment, 0, 96), ![[ID_4]], ptr %To.sroa.0, !DIExpression(),
44; CHECK-NEXT: #dbg_value(i32 %To.sroa.3.0.copyload, ![[TO]], !DIExpression(DW_OP_LLVM_fragment, 96, 32),
45; CHECK-NEXT: #dbg_assign({{.+}} undef, ![[TO]], !DIExpression(DW_OP_LLVM_fragment, 128, 96), ![[ID_6]], ptr %To.sroa.4, !DIExpression(),
46
47target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
48
49%struct.LargeStruct = type { i32, i32, i32, i32, i32, i32, i32 }
50
51@From = dso_local global %struct.LargeStruct zeroinitializer, align 4, !dbg !0
52
53; Function Attrs: nounwind uwtable mustprogress
54define dso_local i32 @_Z7examplev() #0 !dbg !20 {
55entry:
56  %To = alloca %struct.LargeStruct, align 4, !DIAssignID !25
57  call void @llvm.dbg.assign(metadata i1 undef, metadata !24, metadata !DIExpression(), metadata !25, metadata ptr %To, metadata !DIExpression()), !dbg !26
58  %0 = bitcast ptr %To to ptr, !dbg !27
59  call void @llvm.lifetime.start.p0(i64 28, ptr %0) #3, !dbg !27
60  %1 = bitcast ptr %To to ptr, !dbg !28
61  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %1, ptr align 4 @From, i64 28, i1 false), !dbg !28, !DIAssignID !34
62  call void @llvm.dbg.assign(metadata i1 undef, metadata !24, metadata !DIExpression(), metadata !34, metadata ptr %1, metadata !DIExpression()), !dbg !28
63  %Var = getelementptr inbounds %struct.LargeStruct, ptr %To, i32 0, i32 3, !dbg !35
64  %2 = load i32, ptr %Var, align 4, !dbg !35
65  %3 = bitcast ptr %To to ptr, !dbg !38
66  call void @llvm.lifetime.end.p0(i64 28, ptr %3) #3, !dbg !38
67  ret i32 %2, !dbg !39
68}
69
70; Function Attrs: argmemonly nofree nosync nounwind willreturn
71declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
72
73; Function Attrs: argmemonly nofree nosync nounwind willreturn
74declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1
75
76; Function Attrs: argmemonly nofree nosync nounwind willreturn
77declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
78
79; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
80declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2
81
82
83!llvm.dbg.cu = !{!2}
84!llvm.module.flags = !{!16, !17, !18, !1000}
85!llvm.ident = !{!19}
86
87!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
88!1 = distinct !DIGlobalVariable(name: "From", scope: !2, file: !3, line: 6, type: !6, isLocal: false, isDefinition: true)
89!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)
90!3 = !DIFile(filename: "sroa-test.cpp", directory: "/")
91!4 = !{}
92!5 = !{!0}
93!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "LargeStruct", file: !3, line: 1, size: 224, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTS11LargeStruct")
94!7 = !{!8, !10, !11, !12, !13, !14, !15}
95!8 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !6, file: !3, line: 2, baseType: !9, size: 32)
96!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
97!10 = !DIDerivedType(tag: DW_TAG_member, name: "B", scope: !6, file: !3, line: 2, baseType: !9, size: 32, offset: 32)
98!11 = !DIDerivedType(tag: DW_TAG_member, name: "C", scope: !6, file: !3, line: 2, baseType: !9, size: 32, offset: 64)
99!12 = !DIDerivedType(tag: DW_TAG_member, name: "Var", scope: !6, file: !3, line: 3, baseType: !9, size: 32, offset: 96)
100!13 = !DIDerivedType(tag: DW_TAG_member, name: "D", scope: !6, file: !3, line: 4, baseType: !9, size: 32, offset: 128)
101!14 = !DIDerivedType(tag: DW_TAG_member, name: "E", scope: !6, file: !3, line: 4, baseType: !9, size: 32, offset: 160)
102!15 = !DIDerivedType(tag: DW_TAG_member, name: "F", scope: !6, file: !3, line: 4, baseType: !9, size: 32, offset: 192)
103!16 = !{i32 7, !"Dwarf Version", i32 4}
104!17 = !{i32 2, !"Debug Info Version", i32 3}
105!18 = !{i32 1, !"wchar_size", i32 4}
106!19 = !{!"clang version 12.0.0"}
107!20 = distinct !DISubprogram(name: "example", linkageName: "_Z7examplev", scope: !3, file: !3, line: 7, type: !21, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !23)
108!21 = !DISubroutineType(types: !22)
109!22 = !{!9}
110!23 = !{!24}
111!24 = !DILocalVariable(name: "To", scope: !20, file: !3, line: 8, type: !6)
112!25 = distinct !DIAssignID()
113!26 = !DILocation(line: 0, scope: !20)
114!27 = !DILocation(line: 8, column: 3, scope: !20)
115!28 = !DILocation(line: 8, column: 20, scope: !20)
116!34 = distinct !DIAssignID()
117!35 = !DILocation(line: 9, column: 13, scope: !20)
118!38 = !DILocation(line: 10, column: 1, scope: !20)
119!39 = !DILocation(line: 9, column: 3, scope: !20)
120!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
121