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