1 ; RUN: llc -mtriple=bpf -mcpu=v2 < %s | FileCheck -check-prefixes=CHECK,V2 %s
2 ; RUN: llc -mtriple=bpf -mcpu=v4 < %s | FileCheck -check-prefixes=CHECK,V4 %s
4 ; Verify that BPFMISimplifyPatchable::checkADDrr correctly rewrites
7 ; Generated from the following source code:
13 ; } __attribute__((preserve_access_index));
15 ; extern void cu(unsigned long);
17 ; void bar(volatile struct t *t) {
24 ; Using the following command:
25 ; clang -g -O2 -S -emit-llvm --target=bpf t.c -o t.ll
27 @"llvm.t:0:0$0:0" = external global i64, !llvm.preserve.access.index !0 #0
28 @"llvm.t:0:2$0:1" = external global i64, !llvm.preserve.access.index !0 #0
29 @"llvm.t:0:4$0:2" = external global i64, !llvm.preserve.access.index !0 #0
30 @"llvm.t:0:8$0:3" = external global i64, !llvm.preserve.access.index !0 #0
32 ; Function Attrs: nounwind
33 define dso_local void @bar(ptr noundef %t) local_unnamed_addr #1 !dbg !18 {
35 call void @llvm.dbg.value(metadata ptr %t, metadata !24, metadata !DIExpression()), !dbg !25
36 %0 = load i64, ptr @"llvm.t:0:0$0:0", align 8
37 %1 = getelementptr i8, ptr %t, i64 %0
38 %2 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 0, ptr %1)
39 %3 = load volatile i8, ptr %2, align 8, !dbg !26, !tbaa !27
40 %conv = zext i8 %3 to i64, !dbg !34
41 tail call void @cu(i64 noundef %conv) #5, !dbg !35
42 %4 = load i64, ptr @"llvm.t:0:2$0:1", align 8
43 %5 = getelementptr i8, ptr %t, i64 %4
44 %6 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 1, ptr %5)
45 %7 = load volatile i16, ptr %6, align 2, !dbg !36, !tbaa !37
46 %conv1 = zext i16 %7 to i64, !dbg !38
47 tail call void @cu(i64 noundef %conv1) #5, !dbg !39
48 %8 = load i64, ptr @"llvm.t:0:4$0:2", align 8
49 %9 = getelementptr i8, ptr %t, i64 %8
50 %10 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 2, ptr %9)
51 %11 = load volatile i32, ptr %10, align 4, !dbg !40, !tbaa !41
52 %conv2 = zext i32 %11 to i64, !dbg !42
53 tail call void @cu(i64 noundef %conv2) #5, !dbg !43
54 %12 = load i64, ptr @"llvm.t:0:8$0:3", align 8
55 %13 = getelementptr i8, ptr %t, i64 %12
56 %14 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 3, ptr %13)
57 %15 = load volatile i64, ptr %14, align 8, !dbg !44, !tbaa !45
58 tail call void @cu(i64 noundef %15) #5, !dbg !46
64 ; CHECK-NEXT: .Ltmp[[LABEL_UB:.*]]:
66 ; V2-NEXT: r1 = *(u8 *)(r6 + 0)
67 ; V4-NEXT: w1 = *(u8 *)(r6 + 0)
73 ; CHECK-NEXT: .Ltmp[[LABEL_UH:.*]]:
75 ; V2-NEXT: r1 = *(u16 *)(r6 + 2)
76 ; V4-NEXT: w1 = *(u16 *)(r6 + 2)
82 ; CHECK-NEXT: .Ltmp[[LABEL_UW:.*]]:
84 ; V2-NEXT: r1 = *(u32 *)(r6 + 4)
85 ; V4-NEXT: w1 = *(u32 *)(r6 + 4)
91 ; CHECK-NEXT: .Ltmp[[LABEL_UD:.*]]:
93 ; CHECK-NEXT: r1 = *(u64 *)(r6 + 8)
98 ; CHECK: .section .BTF
99 ; CHECK: .long [[STR_T:.*]] # BTF_KIND_STRUCT(id = [[ID:.*]])
101 ; CHECK: .byte 116 # string offset=[[STR_T]]
102 ; CHECK: .ascii "0:0" # string offset=[[STR_UB:.*]]
103 ; CHECK: .ascii "0:1" # string offset=[[STR_UH:.*]]
104 ; CHECK: .ascii "0:2" # string offset=[[STR_UW:.*]]
105 ; CHECK: .ascii "0:3" # string offset=[[STR_UD:.*]]
107 ; CHECK: # FieldReloc
108 ; CHECK: .long .Ltmp[[LABEL_UB]]
109 ; CHECK-NEXT: .long [[ID]]
110 ; CHECK-NEXT: .long [[STR_UB]]
111 ; CHECK-NEXT: .long 0
112 ; CHECK: .long .Ltmp[[LABEL_UH]]
113 ; CHECK-NEXT: .long [[ID]]
114 ; CHECK-NEXT: .long [[STR_UH]]
115 ; CHECK-NEXT: .long 0
116 ; CHECK: .long .Ltmp[[LABEL_UW]]
117 ; CHECK-NEXT: .long [[ID]]
118 ; CHECK-NEXT: .long [[STR_UW]]
119 ; CHECK-NEXT: .long 0
120 ; CHECK: .long .Ltmp[[LABEL_UD]]
121 ; CHECK-NEXT: .long [[ID]]
122 ; CHECK-NEXT: .long [[STR_UD]]
123 ; CHECK-NEXT: .long 0
125 declare !dbg !48 dso_local void @cu(i64 noundef) local_unnamed_addr #2
127 ; Function Attrs: nofree nosync nounwind memory(none)
128 declare ptr @llvm.bpf.passthrough.p0.p0(i32, ptr) #3
130 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
131 declare void @llvm.dbg.value(metadata, metadata, metadata) #4
133 attributes #0 = { "btf_ama" }
134 attributes #1 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
135 attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
136 attributes #3 = { nofree nosync nounwind memory(none) }
137 attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
138 attributes #5 = { nounwind }
140 !llvm.dbg.cu = !{!11}
141 !llvm.module.flags = !{!12, !13, !14, !15, !16}
144 !0 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", file: !1, line: 1, size: 128, elements: !2)
145 !1 = !DIFile(filename: "some.file", directory: "/some/dir", checksumkind: CSK_MD5, checksum: "d08c6eeba11118106c69a68932003da2")
146 !2 = !{!3, !5, !7, !9}
147 !3 = !DIDerivedType(tag: DW_TAG_member, name: "ub", scope: !0, file: !1, line: 2, baseType: !4, size: 8)
148 !4 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
149 !5 = !DIDerivedType(tag: DW_TAG_member, name: "uh", scope: !0, file: !1, line: 3, baseType: !6, size: 16, offset: 16)
150 !6 = !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned)
151 !7 = !DIDerivedType(tag: DW_TAG_member, name: "uw", scope: !0, file: !1, line: 4, baseType: !8, size: 32, offset: 32)
152 !8 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
153 !9 = !DIDerivedType(tag: DW_TAG_member, name: "ud", scope: !0, file: !1, line: 5, baseType: !10, size: 64, offset: 64)
154 !10 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
155 !11 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 18.0.0 (/home/eddy/work/llvm-project/clang 3810f2eb4382d5e2090ce5cd47f45379cb453c35)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
156 !12 = !{i32 7, !"Dwarf Version", i32 5}
157 !13 = !{i32 2, !"Debug Info Version", i32 3}
158 !14 = !{i32 1, !"wchar_size", i32 4}
159 !15 = !{i32 7, !"frame-pointer", i32 2}
160 !16 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
161 !17 = !{!"clang version 18.0.0 (/home/eddy/work/llvm-project/clang 3810f2eb4382d5e2090ce5cd47f45379cb453c35)"}
162 !18 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 20, type: !19, scopeLine: 20, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !11, retainedNodes: !23)
163 !19 = !DISubroutineType(types: !20)
165 !21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64)
166 !22 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !0)
168 !24 = !DILocalVariable(name: "t", arg: 1, scope: !18, file: !1, line: 20, type: !21)
169 !25 = !DILocation(line: 0, scope: !18)
170 !26 = !DILocation(line: 21, column: 9, scope: !18)
171 !27 = !{!28, !29, i64 0}
172 !28 = !{!"t", !29, i64 0, !31, i64 2, !32, i64 4, !33, i64 8}
173 !29 = !{!"omnipotent char", !30, i64 0}
174 !30 = !{!"Simple C/C++ TBAA"}
175 !31 = !{!"short", !29, i64 0}
176 !32 = !{!"int", !29, i64 0}
177 !33 = !{!"long", !29, i64 0}
178 !34 = !DILocation(line: 21, column: 6, scope: !18)
179 !35 = !DILocation(line: 21, column: 3, scope: !18)
180 !36 = !DILocation(line: 22, column: 9, scope: !18)
181 !37 = !{!28, !31, i64 2}
182 !38 = !DILocation(line: 22, column: 6, scope: !18)
183 !39 = !DILocation(line: 22, column: 3, scope: !18)
184 !40 = !DILocation(line: 23, column: 9, scope: !18)
185 !41 = !{!28, !32, i64 4}
186 !42 = !DILocation(line: 23, column: 6, scope: !18)
187 !43 = !DILocation(line: 23, column: 3, scope: !18)
188 !44 = !DILocation(line: 24, column: 9, scope: !18)
189 !45 = !{!28, !33, i64 8}
190 !46 = !DILocation(line: 24, column: 3, scope: !18)
191 !47 = !DILocation(line: 25, column: 1, scope: !18)
192 !48 = !DISubprogram(name: "cu", scope: !1, file: !1, line: 10, type: !49, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !51)
193 !49 = !DISubroutineType(types: !50)
196 !52 = !DILocalVariable(arg: 1, scope: !48, file: !1, line: 10, type: !10)