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