xref: /llvm-project/llvm/test/CodeGen/BPF/CORE/offset-reloc-simplify-patchable-2.ll (revision 08d92dedd26c66bd203cc3b45f982d7aeb214995)
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
3
4; Verify that BPFMISimplifyPatchable::checkADDrr correctly rewrites
5; load instructions.
6;
7; Generated from the following source code:
8;   struct t {
9;     unsigned char  ub;
10;     unsigned short uh;
11;     unsigned int   uw;
12;     unsigned long  ud;
13;   } __attribute__((preserve_access_index));
14;
15;   extern void cu(unsigned long);
16;
17;   void bar(volatile struct t *t) {
18;     cu(t->ub);
19;     cu(t->uh);
20;     cu(t->uw);
21;     cu(t->ud);
22;   }
23;
24; Using the following command:
25;   clang -g -O2 -S -emit-llvm --target=bpf t.c -o t.ll
26
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
31
32; Function Attrs: nounwind
33define dso_local void @bar(ptr noundef %t) local_unnamed_addr #1 !dbg !18 {
34entry:
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
59  ret void, !dbg !47
60}
61
62; CHECK: bar:
63; CHECK:      prologue_end
64; CHECK-NEXT: .Ltmp[[LABEL_UB:.*]]:
65; CHECK-NEXT: .Ltmp
66; V2-NEXT:        r1 = *(u8 *)(r6 + 0)
67; V4-NEXT:        w1 = *(u8 *)(r6 + 0)
68; CHECK-NEXT:     .loc
69; CHECK-NEXT: .Ltmp
70; CHECK-NEXT:     call cu
71; CHECK-NEXT: .Ltmp
72; CHECK-NEXT:     .loc
73; CHECK-NEXT: .Ltmp[[LABEL_UH:.*]]:
74; CHECK-NEXT: .Ltmp
75; V2-NEXT:        r1 = *(u16 *)(r6 + 2)
76; V4-NEXT:        w1 = *(u16 *)(r6 + 2)
77; CHECK-NEXT:     .loc
78; CHECK-NEXT: .Ltmp
79; CHECK-NEXT:     call cu
80; CHECK-NEXT: .Ltmp
81; CHECK-NEXT:     .loc
82; CHECK-NEXT: .Ltmp[[LABEL_UW:.*]]:
83; CHECK-NEXT: .Ltmp
84; V2-NEXT:        r1 = *(u32 *)(r6 + 4)
85; V4-NEXT:        w1 = *(u32 *)(r6 + 4)
86; CHECK-NEXT:     .loc
87; CHECK-NEXT: .Ltmp
88; CHECK-NEXT:     call cu
89; CHECK-NEXT: .Ltmp
90; CHECK-NEXT:     .loc
91; CHECK-NEXT: .Ltmp[[LABEL_UD:.*]]:
92; CHECK-NEXT: .Ltmp
93; CHECK-NEXT:     r1 = *(u64 *)(r6 + 8)
94; CHECK-NEXT:     .loc
95; CHECK-NEXT: .Ltmp
96; CHECK-NEXT:     call cu
97
98; CHECK: .section .BTF
99; CHECK: .long [[STR_T:.*]]  # BTF_KIND_STRUCT(id = [[ID:.*]])
100
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:.*]]
106
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
124
125declare !dbg !48 dso_local void @cu(i64 noundef) local_unnamed_addr #2
126
127; Function Attrs: nofree nosync nounwind memory(none)
128declare ptr @llvm.bpf.passthrough.p0.p0(i32, ptr) #3
129
130; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
131declare void @llvm.dbg.value(metadata, metadata, metadata) #4
132
133attributes #0 = { "btf_ama" }
134attributes #1 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
135attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
136attributes #3 = { nofree nosync nounwind memory(none) }
137attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
138attributes #5 = { nounwind }
139
140!llvm.dbg.cu = !{!11}
141!llvm.module.flags = !{!12, !13, !14, !15, !16}
142!llvm.ident = !{!17}
143
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)
164!20 = !{null, !21}
165!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64)
166!22 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !0)
167!23 = !{!24}
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)
194!50 = !{null, !10}
195!51 = !{!52}
196!52 = !DILocalVariable(arg: 1, scope: !48, file: !1, line: 10, type: !10)
197