1; RUN: llc -O2 -march=bpf -mcpu=v3 < %s | FileCheck %s
2; Source code:
3;   struct t3 {
4;     int i;
5;   } __attribute__((preserve_access_index));
6;   struct t2 {
7;     void *pad;
8;     struct t3 *f;
9;  } __attribute__((preserve_access_index));
10;  struct t1 {
11;    void *pad;
12;    struct t2 *q;
13;  } __attribute__((preserve_access_index));
14;
15;  int g;
16;  int test(struct t1 *p) {
17;    struct t2 *q = p->q;
18;    if (q)
19;      return 0;
20;    struct t3 *f = q->f;
21;    if (!f) g = 5;
22;    return 0;
23;  }
24; Compilation flag:
25;   clang -target bpf -O2 -g -S -emit-llvm t.c
26
27@g = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
28@"llvm.t2:0:8$0:1" = external global i64, !llvm.preserve.access.index !6 #0
29@"llvm.t1:0:8$0:1" = external global i64, !llvm.preserve.access.index !15 #0
30
31; Function Attrs: mustprogress nofree nosync nounwind willreturn
32define dso_local i32 @test(ptr noundef readonly %p) local_unnamed_addr #1 !dbg !25 {
33entry:
34  call void @llvm.dbg.value(metadata ptr %p, metadata !30, metadata !DIExpression()), !dbg !33
35  %0 = load i64, ptr @"llvm.t1:0:8$0:1", align 8
36  %1 = getelementptr i8, ptr %p, i64 %0
37  %2 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 1, ptr %1)
38  %3 = load ptr, ptr %2, align 8, !dbg !34, !tbaa !35
39  call void @llvm.dbg.value(metadata ptr %3, metadata !31, metadata !DIExpression()), !dbg !33
40  %tobool.not = icmp eq ptr %3, null, !dbg !40
41  br i1 %tobool.not, label %if.end, label %cleanup, !dbg !42
42
43; CHECK-LABEL: test
44; CHECK:       r1 = *(u64 *)(r1 + 8)
45; CHECK:       if r1 != 0 goto
46
47if.end:                                           ; preds = %entry
48  %4 = load i64, ptr @"llvm.t2:0:8$0:1", align 8
49  %5 = getelementptr i8, ptr null, i64 %4
50  %6 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 0, ptr %5)
51  %7 = load ptr, ptr %6, align 8, !dbg !43, !tbaa !44
52  call void @llvm.dbg.value(metadata ptr %7, metadata !32, metadata !DIExpression()), !dbg !33
53  %tobool1.not = icmp eq ptr %7, null, !dbg !46
54  br i1 %tobool1.not, label %if.then2, label %cleanup, !dbg !48
55
56; CHECK:       r1 = 8
57; CHECK:       r1 = *(u64 *)(r1 + 0)
58; CHECK:       if r1 != 0 goto
59
60if.then2:                                         ; preds = %if.end
61  store i32 5, ptr @g, align 4, !dbg !49, !tbaa !50
62  br label %cleanup, !dbg !52
63
64cleanup:                                          ; preds = %if.end, %if.then2, %entry
65  ret i32 0, !dbg !53
66}
67
68; Function Attrs: nofree nosync nounwind readnone
69declare ptr @llvm.bpf.passthrough.p0.p0(i32, ptr) #2
70
71; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
72declare void @llvm.dbg.value(metadata, metadata, metadata) #3
73
74attributes #0 = { "btf_ama" }
75attributes #1 = { mustprogress nofree nosync nounwind willreturn "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
76attributes #2 = { nofree nosync nounwind readnone }
77attributes #3 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
78
79!llvm.dbg.cu = !{!2}
80!llvm.module.flags = !{!20, !21, !22, !23}
81!llvm.ident = !{!24}
82
83!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
84!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 13, type: !5, isLocal: false, isDefinition: true)
85!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git ca2be81e34a6d87edb8e555dfac94ab68ee20f70)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
86!3 = !DIFile(filename: "t.c", directory: "/tmp/home/yhs/work/tests/llvm/nullptr", checksumkind: CSK_MD5, checksum: "2c0ea9b3c647baf31f56992f9142b0df")
87!4 = !{!0}
88!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
89!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t2", file: !3, line: 4, size: 128, elements: !7)
90!7 = !{!8, !10}
91!8 = !DIDerivedType(tag: DW_TAG_member, name: "pad", scope: !6, file: !3, line: 5, baseType: !9, size: 64)
92!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
93!10 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !6, file: !3, line: 6, baseType: !11, size: 64, offset: 64)
94!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
95!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t3", file: !3, line: 1, size: 32, elements: !13)
96!13 = !{!14}
97!14 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !12, file: !3, line: 2, baseType: !5, size: 32)
98!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !3, line: 8, size: 128, elements: !16)
99!16 = !{!17, !18}
100!17 = !DIDerivedType(tag: DW_TAG_member, name: "pad", scope: !15, file: !3, line: 9, baseType: !9, size: 64)
101!18 = !DIDerivedType(tag: DW_TAG_member, name: "q", scope: !15, file: !3, line: 10, baseType: !19, size: 64, offset: 64)
102!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
103!20 = !{i32 7, !"Dwarf Version", i32 5}
104!21 = !{i32 2, !"Debug Info Version", i32 3}
105!22 = !{i32 1, !"wchar_size", i32 4}
106!23 = !{i32 7, !"frame-pointer", i32 2}
107!24 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git ca2be81e34a6d87edb8e555dfac94ab68ee20f70)"}
108!25 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 14, type: !26, scopeLine: 14, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !29)
109!26 = !DISubroutineType(types: !27)
110!27 = !{!5, !28}
111!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64)
112!29 = !{!30, !31, !32}
113!30 = !DILocalVariable(name: "p", arg: 1, scope: !25, file: !3, line: 14, type: !28)
114!31 = !DILocalVariable(name: "q", scope: !25, file: !3, line: 15, type: !19)
115!32 = !DILocalVariable(name: "f", scope: !25, file: !3, line: 18, type: !11)
116!33 = !DILocation(line: 0, scope: !25)
117!34 = !DILocation(line: 15, column: 21, scope: !25)
118!35 = !{!36, !37, i64 8}
119!36 = !{!"t1", !37, i64 0, !37, i64 8}
120!37 = !{!"any pointer", !38, i64 0}
121!38 = !{!"omnipotent char", !39, i64 0}
122!39 = !{!"Simple C/C++ TBAA"}
123!40 = !DILocation(line: 16, column: 7, scope: !41)
124!41 = distinct !DILexicalBlock(scope: !25, file: !3, line: 16, column: 7)
125!42 = !DILocation(line: 16, column: 7, scope: !25)
126!43 = !DILocation(line: 18, column: 21, scope: !25)
127!44 = !{!45, !37, i64 8}
128!45 = !{!"t2", !37, i64 0, !37, i64 8}
129!46 = !DILocation(line: 19, column: 8, scope: !47)
130!47 = distinct !DILexicalBlock(scope: !25, file: !3, line: 19, column: 7)
131!48 = !DILocation(line: 19, column: 7, scope: !25)
132!49 = !DILocation(line: 19, column: 13, scope: !47)
133!50 = !{!51, !51, i64 0}
134!51 = !{!"int", !38, i64 0}
135!52 = !DILocation(line: 19, column: 11, scope: !47)
136!53 = !DILocation(line: 21, column: 1, scope: !25)
137