1 ; RUN: llc -mtriple=bpf -mcpu=v4 < %s | FileCheck -check-prefixes=CHECK %s
3 ; Verify that BPFMISimplifyPatchable::checkADDrr correctly rewrites
4 ; load instructions with sign extension.
6 ; Generated from the following source code:
11 ; } __attribute__((preserve_access_index));
13 ; extern void cs(signed long);
15 ; void buz(volatile struct t *t) {
21 ; Using the following command:
22 ; clang -g -O2 -S -emit-llvm --target=bpf t.c -o t.ll
24 @"llvm.t:0:0$0:0" = external global i64, !llvm.preserve.access.index !0 #0
25 @"llvm.t:0:2$0:1" = external global i64, !llvm.preserve.access.index !0 #0
26 @"llvm.t:0:4$0:2" = external global i64, !llvm.preserve.access.index !0 #0
28 ; Function Attrs: nounwind
29 define dso_local void @buz(ptr noundef %t) local_unnamed_addr #1 !dbg !16 {
31 call void @llvm.dbg.value(metadata ptr %t, metadata !22, metadata !DIExpression()), !dbg !23
32 %0 = load i64, ptr @"llvm.t:0:0$0:0", align 8
33 %1 = getelementptr i8, ptr %t, i64 %0
34 %2 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 0, ptr %1)
35 %3 = load volatile i8, ptr %2, align 4, !dbg !24, !tbaa !25
36 %conv = sext i8 %3 to i64, !dbg !31
37 tail call void @cs(i64 noundef %conv) #5, !dbg !32
38 %4 = load i64, ptr @"llvm.t:0:2$0:1", align 8
39 %5 = getelementptr i8, ptr %t, i64 %4
40 %6 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 1, ptr %5)
41 %7 = load volatile i16, ptr %6, align 2, !dbg !33, !tbaa !34
42 %conv1 = sext i16 %7 to i64, !dbg !35
43 tail call void @cs(i64 noundef %conv1) #5, !dbg !36
44 %8 = load i64, ptr @"llvm.t:0:4$0:2", align 8
45 %9 = getelementptr i8, ptr %t, i64 %8
46 %10 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 2, ptr %9)
47 %11 = load volatile i32, ptr %10, align 4, !dbg !37, !tbaa !38
48 %conv2 = sext i32 %11 to i64, !dbg !39
49 tail call void @cs(i64 noundef %conv2) #5, !dbg !40
55 ; CHECK-NEXT: .Ltmp[[LABEL_SB:.*]]:
57 ; CHECK-NEXT: r1 = *(s8 *)(r6 + 0)
63 ; CHECK-NEXT: .Ltmp[[LABEL_SH:.*]]:
65 ; CHECK-NEXT: r1 = *(s16 *)(r6 + 2)
71 ; CHECK-NEXT: .Ltmp[[LABEL_SW:.*]]:
73 ; CHECK-NEXT: r1 = *(s32 *)(r6 + 4)
78 ; CHECK: .section .BTF
79 ; CHECK: .long [[T:.*]] # BTF_KIND_STRUCT(id = [[ID:.*]])
81 ; CHECK: .byte 116 # string offset=[[T]]
82 ; CHECK: .ascii "0:0" # string offset=[[STR_SB:.*]]
83 ; CHECK: .ascii "0:1" # string offset=[[STR_SH:.*]]
84 ; CHECK: .ascii "0:2" # string offset=[[STR_SW:.*]]
87 ; CHECK: .long .Ltmp[[LABEL_SB]]
88 ; CHECK-NEXT: .long [[ID]]
89 ; CHECK-NEXT: .long [[STR_SB]]
91 ; CHECK: .long .Ltmp[[LABEL_SH]]
92 ; CHECK-NEXT: .long [[ID]]
93 ; CHECK-NEXT: .long [[STR_SH]]
95 ; CHECK: .long .Ltmp[[LABEL_SW]]
96 ; CHECK-NEXT: .long [[ID]]
97 ; CHECK-NEXT: .long [[STR_SW]]
100 declare !dbg !42 dso_local void @cs(i64 noundef) local_unnamed_addr #2
102 ; Function Attrs: nofree nosync nounwind memory(none)
103 declare ptr @llvm.bpf.passthrough.p0.p0(i32, ptr) #3
105 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
106 declare void @llvm.dbg.value(metadata, metadata, metadata) #4
108 attributes #0 = { "btf_ama" }
109 attributes #1 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
110 attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
111 attributes #3 = { nofree nosync nounwind memory(none) }
112 attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
113 attributes #5 = { nounwind }
116 !llvm.module.flags = !{!10, !11, !12, !13, !14}
119 !0 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", file: !1, line: 1, size: 64, elements: !2)
120 !1 = !DIFile(filename: "some.file", directory: "/some/dir", checksumkind: CSK_MD5, checksum: "2316ba0d3e8def5d297ad400e78b1782")
122 !3 = !DIDerivedType(tag: DW_TAG_member, name: "sb", scope: !0, file: !1, line: 6, baseType: !4, size: 8)
123 !4 = !DIBasicType(name: "signed char", size: 8, encoding: DW_ATE_signed_char)
124 !5 = !DIDerivedType(tag: DW_TAG_member, name: "sh", scope: !0, file: !1, line: 7, baseType: !6, size: 16, offset: 16)
125 !6 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
126 !7 = !DIDerivedType(tag: DW_TAG_member, name: "sw", scope: !0, file: !1, line: 8, baseType: !8, size: 32, offset: 32)
127 !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
128 !9 = 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)
129 !10 = !{i32 7, !"Dwarf Version", i32 5}
130 !11 = !{i32 2, !"Debug Info Version", i32 3}
131 !12 = !{i32 1, !"wchar_size", i32 4}
132 !13 = !{i32 7, !"frame-pointer", i32 2}
133 !14 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
134 !15 = !{!"clang version 18.0.0 (/home/eddy/work/llvm-project/clang 3810f2eb4382d5e2090ce5cd47f45379cb453c35)"}
135 !16 = distinct !DISubprogram(name: "buz", scope: !1, file: !1, line: 27, type: !17, scopeLine: 27, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !9, retainedNodes: !21)
136 !17 = !DISubroutineType(types: !18)
138 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
139 !20 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !0)
141 !22 = !DILocalVariable(name: "t", arg: 1, scope: !16, file: !1, line: 27, type: !19)
142 !23 = !DILocation(line: 0, scope: !16)
143 !24 = !DILocation(line: 28, column: 9, scope: !16)
144 !25 = !{!26, !27, i64 0}
145 !26 = !{!"t", !27, i64 0, !29, i64 2, !30, i64 4}
146 !27 = !{!"omnipotent char", !28, i64 0}
147 !28 = !{!"Simple C/C++ TBAA"}
148 !29 = !{!"short", !27, i64 0}
149 !30 = !{!"int", !27, i64 0}
150 !31 = !DILocation(line: 28, column: 6, scope: !16)
151 !32 = !DILocation(line: 28, column: 3, scope: !16)
152 !33 = !DILocation(line: 29, column: 9, scope: !16)
153 !34 = !{!26, !29, i64 2}
154 !35 = !DILocation(line: 29, column: 6, scope: !16)
155 !36 = !DILocation(line: 29, column: 3, scope: !16)
156 !37 = !DILocation(line: 30, column: 9, scope: !16)
157 !38 = !{!26, !30, i64 4}
158 !39 = !DILocation(line: 30, column: 6, scope: !16)
159 !40 = !DILocation(line: 30, column: 3, scope: !16)
160 !41 = !DILocation(line: 31, column: 1, scope: !16)
161 !42 = !DISubprogram(name: "cs", scope: !1, file: !1, line: 11, type: !43, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !46)
162 !43 = !DISubroutineType(types: !44)
164 !45 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
166 !47 = !DILocalVariable(arg: 1, scope: !42, file: !1, line: 11, type: !45)