xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/store-pai.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
2;
3; Source:
4;    #define __ctx __attribute__((preserve_static_offset))
5;    #define __pai __attribute__((preserve_access_index))
6;
7;    struct foo {
8;      char a[10];
9;    } __pai;
10;
11;    struct bar {
12;      int a;
13;      int b;
14;    } __pai;
15;
16;    struct buz {
17;      int _1;
18;      int _2;
19;      int _3;
20;      union {
21;        struct foo a;
22;        struct bar b[7];
23;      };
24;    } __pai __ctx;
25;
26;    void quux(struct buz *p) {
27;      p->b[5].b = 42;
28;    }
29;
30; Compilation flag:
31;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes \
32;         -debug-info-kind=limited -o - \
33;       | opt -passes=function(sroa) -S -o -
34
35%struct.buz = type { i32, i32, i32, %union.anon }
36%union.anon = type { [7 x %struct.bar] }
37%struct.bar = type { i32, i32 }
38
39; Function Attrs: nounwind
40define dso_local void @quux(ptr noundef %p) #0 !dbg !31 {
41entry:
42  call void @llvm.dbg.value(metadata ptr %p, metadata !36, metadata !DIExpression()), !dbg !37
43  %0 = call ptr @llvm.preserve.static.offset(ptr %p), !dbg !38
44  %1 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.buz) %0, i32 3, i32 3), !dbg !38, !llvm.preserve.access.index !4
45  %2 = call ptr @llvm.preserve.union.access.index.p0.p0(ptr %1, i32 1), !dbg !38, !llvm.preserve.access.index !3
46  %3 = call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([7 x %struct.bar]) %2, i32 1, i32 5), !dbg !39, !llvm.preserve.access.index !21
47  %4 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.bar) %3, i32 1, i32 1), !dbg !40, !llvm.preserve.access.index !22
48  store i32 42, ptr %4, align 4, !dbg !41, !tbaa !42
49  ret void, !dbg !45
50}
51
52; CHECK:      define dso_local void @quux(ptr noundef %[[p:.*]]) {{.*}} {
53; CHECK-NEXT: entry:
54; CHECK-NEXT:   #dbg_value
55; CHECK-NEXT:   call void (i32, ptr, i1, i8, i8, i8, i1, ...)
56; CHECK-SAME:     @llvm.bpf.getelementptr.and.store.i32
57; CHECK-SAME:       (i32 42,
58; CHECK-SAME:        ptr writeonly elementtype(i8) %[[p]],
59; CHECK-SAME:        i1 false, i8 0, i8 1, i8 2, i1 true, i64 immarg 56)
60; CHECK-SAME:      #[[v5:.*]], !tbaa
61; CHECK-NEXT:   ret void, !dbg
62; CHECK-NEXT: }
63; CHECK:      attributes #[[v5]] = { memory(argmem: write) }
64
65; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
66declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
67
68; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
69declare ptr @llvm.preserve.static.offset(ptr readnone) #1
70
71; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
72declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #2
73
74; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
75declare ptr @llvm.preserve.union.access.index.p0.p0(ptr, i32 immarg) #2
76
77; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
78declare ptr @llvm.preserve.array.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #2
79
80; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
81declare void @llvm.dbg.value(metadata, metadata, metadata) #1
82
83attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
84attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
85attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
86
87!llvm.dbg.cu = !{!0}
88!llvm.module.flags = !{!28, !29}
89!llvm.ident = !{!30}
90
91!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, splitDebugInlining: false, nameTableKind: None)
92!1 = !DIFile(filename: "some-file.c", directory: "/some/dir/")
93!2 = !{!3, !21}
94!3 = distinct !DICompositeType(tag: DW_TAG_union_type, scope: !4, file: !1, line: 17, size: 448, elements: !11)
95!4 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "buz", file: !1, line: 13, size: 544, elements: !5)
96!5 = !{!6, !8, !9, !10}
97!6 = !DIDerivedType(tag: DW_TAG_member, name: "_1", scope: !4, file: !1, line: 14, baseType: !7, size: 32)
98!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
99!8 = !DIDerivedType(tag: DW_TAG_member, name: "_2", scope: !4, file: !1, line: 15, baseType: !7, size: 32, offset: 32)
100!9 = !DIDerivedType(tag: DW_TAG_member, name: "_3", scope: !4, file: !1, line: 16, baseType: !7, size: 32, offset: 64)
101!10 = !DIDerivedType(tag: DW_TAG_member, scope: !4, file: !1, line: 17, baseType: !3, size: 448, offset: 96)
102!11 = !{!12, !20}
103!12 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !3, file: !1, line: 18, baseType: !13, size: 80)
104!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !1, line: 4, size: 80, elements: !14)
105!14 = !{!15}
106!15 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !13, file: !1, line: 5, baseType: !16, size: 80)
107!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !17, size: 80, elements: !18)
108!17 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
109!18 = !{!19}
110!19 = !DISubrange(count: 10)
111!20 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !3, file: !1, line: 19, baseType: !21, size: 448)
112!21 = !DICompositeType(tag: DW_TAG_array_type, baseType: !22, size: 448, elements: !26)
113!22 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !1, line: 8, size: 64, elements: !23)
114!23 = !{!24, !25}
115!24 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !22, file: !1, line: 9, baseType: !7, size: 32)
116!25 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !22, file: !1, line: 10, baseType: !7, size: 32, offset: 32)
117!26 = !{!27}
118!27 = !DISubrange(count: 7)
119!28 = !{i32 2, !"Debug Info Version", i32 3}
120!29 = !{i32 1, !"wchar_size", i32 4}
121!30 = !{!"clang"}
122!31 = distinct !DISubprogram(name: "quux", scope: !1, file: !1, line: 23, type: !32, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !35)
123!32 = !DISubroutineType(types: !33)
124!33 = !{null, !34}
125!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64)
126!35 = !{!36}
127!36 = !DILocalVariable(name: "p", arg: 1, scope: !31, file: !1, line: 23, type: !34)
128!37 = !DILocation(line: 0, scope: !31)
129!38 = !DILocation(line: 24, column: 6, scope: !31)
130!39 = !DILocation(line: 24, column: 3, scope: !31)
131!40 = !DILocation(line: 24, column: 11, scope: !31)
132!41 = !DILocation(line: 24, column: 13, scope: !31)
133!42 = !{!43, !43, i64 0}
134!43 = !{!"omnipotent char", !44, i64 0}
135!44 = !{!"Simple C/C++ TBAA"}
136!45 = !DILocation(line: 25, column: 1, scope: !31)
137