1 ; RUN: opt -O2 %s | llvm-dis > %t1
2 ; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK64 %s
3 ; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK32 %s
11 ; FIELD_BYTE_OFFSET = 0,
18 ; void bpf_probe_read(ptr, unsigned, const ptr);
19 ; int field_read(struct s *arg) {
20 ; unsigned long long ull;
21 ; unsigned offset = __builtin_preserve_field_info(arg->b2, FIELD_BYTE_OFFSET);
22 ; unsigned size = __builtin_preserve_field_info(arg->b2, FIELD_BYTE_SIZE);
25 ; bpf_probe_read(&ull, size, (const ptr)arg + offset);
26 ; lshift = __builtin_preserve_field_info(arg->b2, FIELD_LSHIFT_U64);
27 ; #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
28 ; lshift = lshift + (size << 3) - 64;
31 ; if (__builtin_preserve_field_info(arg->b2, FIELD_SIGNEDNESS))
32 ; return (long long)ull >> __builtin_preserve_field_info(arg->b2, FIELD_RSHIFT_U64);
33 ; return ull >> __builtin_preserve_field_info(arg->b2, FIELD_RSHIFT_U64);
36 ; clang -target bpfel -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
38 target triple = "bpfel"
40 %struct.s = type { i32, i16 }
42 ; Function Attrs: nounwind
43 define dso_local i32 @field_read(ptr %arg) local_unnamed_addr #0 !dbg !20 {
45 %ull = alloca i64, align 8
46 call void @llvm.dbg.value(metadata ptr %arg, metadata !31, metadata !DIExpression()), !dbg !37
47 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ull) #5, !dbg !38
48 %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr elementtype(%struct.s) %arg, i32 1, i32 2), !dbg !39, !llvm.preserve.access.index !25
49 %1 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 0), !dbg !40
50 call void @llvm.dbg.value(metadata i32 %1, metadata !34, metadata !DIExpression()), !dbg !37
51 %2 = tail call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 1), !dbg !41
52 call void @llvm.dbg.value(metadata i32 %2, metadata !35, metadata !DIExpression()), !dbg !37
53 %idx.ext = zext i32 %1 to i64, !dbg !43
54 %add.ptr = getelementptr i8, ptr %arg, i64 %idx.ext, !dbg !43
55 call void @bpf_probe_read(ptr nonnull %ull, i32 %2, ptr %add.ptr) #5, !dbg !44
56 %3 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 4), !dbg !45
57 call void @llvm.dbg.value(metadata i32 %3, metadata !36, metadata !DIExpression()), !dbg !37
58 %4 = load i64, ptr %ull, align 8, !dbg !46, !tbaa !47
59 call void @llvm.dbg.value(metadata i64 %4, metadata !32, metadata !DIExpression()), !dbg !37
60 %sh_prom = zext i32 %3 to i64, !dbg !46
61 %shl = shl i64 %4, %sh_prom, !dbg !46
62 call void @llvm.dbg.value(metadata i64 %shl, metadata !32, metadata !DIExpression()), !dbg !37
63 %5 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 3), !dbg !51
64 %tobool = icmp eq i32 %5, 0, !dbg !51
65 %6 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %0, i64 5), !dbg !37
66 %sh_prom1 = zext i32 %6 to i64, !dbg !37
67 %shr = ashr i64 %shl, %sh_prom1, !dbg !53
68 %shr3 = lshr i64 %shl, %sh_prom1, !dbg !53
69 %retval.0.in = select i1 %tobool, i64 %shr3, i64 %shr, !dbg !53
70 %retval.0 = trunc i64 %retval.0.in to i32, !dbg !37
71 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ull) #5, !dbg !54
72 ret i32 %retval.0, !dbg !54
75 ; CHECK: r{{[0-9]+}} = 4
76 ; CHECK: r{{[0-9]+}} = 4
77 ; CHECK: r{{[0-9]+}} <<= 51
78 ; CHECK64: r{{[0-9]+}} s>>= 60
79 ; CHECK64: r{{[0-9]+}} >>= 60
80 ; CHECK32: r{{[0-9]+}} >>= 60
81 ; CHECK32: r{{[0-9]+}} s>>= 60
82 ; CHECK: r{{[0-9]+}} = 1
84 ; CHECK: .byte 115 # string offset=1
85 ; CHECK: .ascii ".text" # string offset=30
86 ; CHECK: .ascii "0:2" # string offset=73
88 ; CHECK: .long 16 # FieldReloc
89 ; CHECK-NEXT: .long 30 # Field reloc section string offset=30
91 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
93 ; CHECK-NEXT: .long 73
95 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
97 ; CHECK-NEXT: .long 73
99 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
100 ; CHECK-NEXT: .long 2
101 ; CHECK-NEXT: .long 73
102 ; CHECK-NEXT: .long 4
103 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
104 ; CHECK-NEXT: .long 2
105 ; CHECK-NEXT: .long 73
106 ; CHECK-NEXT: .long 5
107 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
108 ; CHECK-NEXT: .long 2
109 ; CHECK-NEXT: .long 73
110 ; CHECK-NEXT: .long 5
111 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
112 ; CHECK-NEXT: .long 2
113 ; CHECK-NEXT: .long 73
114 ; CHECK-NEXT: .long 3
116 ; Function Attrs: argmemonly nounwind willreturn
117 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #1
119 ; Function Attrs: nounwind readnone
120 declare ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr, i32, i32) #2
122 ; Function Attrs: nounwind readnone
123 declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64) #2
125 declare dso_local void @bpf_probe_read(ptr, i32, ptr) local_unnamed_addr #3
127 ; Function Attrs: argmemonly nounwind willreturn
128 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #1
130 ; Function Attrs: nounwind readnone speculatable willreturn
131 declare void @llvm.dbg.value(metadata, metadata, metadata) #4
133 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
134 attributes #1 = { argmemonly nounwind willreturn }
135 attributes #2 = { nounwind readnone }
136 attributes #3 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
137 attributes #4 = { nounwind readnone speculatable willreturn }
138 attributes #5 = { nounwind }
141 !llvm.module.flags = !{!16, !17, !18}
144 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 923aa0ce806f7739b754167239fee2c9a15e2f31)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !12, nameTableKind: None)
145 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
147 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 6, baseType: !4, size: 32, elements: !5)
148 !4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
149 !5 = !{!6, !7, !8, !9, !10, !11}
150 !6 = !DIEnumerator(name: "FIELD_BYTE_OFFSET", value: 0, isUnsigned: true)
151 !7 = !DIEnumerator(name: "FIELD_BYTE_SIZE", value: 1, isUnsigned: true)
152 !8 = !DIEnumerator(name: "FIELD_EXISTENCE", value: 2, isUnsigned: true)
153 !9 = !DIEnumerator(name: "FIELD_SIGNEDNESS", value: 3, isUnsigned: true)
154 !10 = !DIEnumerator(name: "FIELD_LSHIFT_U64", value: 4, isUnsigned: true)
155 !11 = !DIEnumerator(name: "FIELD_RSHIFT_U64", value: 5, isUnsigned: true)
157 !13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
158 !14 = !DIDerivedType(tag: DW_TAG_const_type, baseType: null)
159 !15 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
160 !16 = !{i32 2, !"Dwarf Version", i32 4}
161 !17 = !{i32 2, !"Debug Info Version", i32 3}
162 !18 = !{i32 1, !"wchar_size", i32 4}
163 !19 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 923aa0ce806f7739b754167239fee2c9a15e2f31)"}
164 !20 = distinct !DISubprogram(name: "field_read", scope: !1, file: !1, line: 15, type: !21, scopeLine: 15, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !30)
165 !21 = !DISubroutineType(types: !22)
167 !23 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
168 !24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !25, size: 64)
169 !25 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 1, size: 64, elements: !26)
170 !26 = !{!27, !28, !29}
171 !27 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !25, file: !1, line: 2, baseType: !23, size: 32)
172 !28 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !25, file: !1, line: 3, baseType: !23, size: 9, offset: 32, flags: DIFlagBitField, extraData: i64 32)
173 !29 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !25, file: !1, line: 4, baseType: !23, size: 4, offset: 41, flags: DIFlagBitField, extraData: i64 32)
174 !30 = !{!31, !32, !34, !35, !36}
175 !31 = !DILocalVariable(name: "arg", arg: 1, scope: !20, file: !1, line: 15, type: !24)
176 !32 = !DILocalVariable(name: "ull", scope: !20, file: !1, line: 16, type: !33)
177 !33 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)
178 !34 = !DILocalVariable(name: "offset", scope: !20, file: !1, line: 17, type: !4)
179 !35 = !DILocalVariable(name: "size", scope: !20, file: !1, line: 18, type: !4)
180 !36 = !DILocalVariable(name: "lshift", scope: !20, file: !1, line: 19, type: !4)
181 !37 = !DILocation(line: 0, scope: !20)
182 !38 = !DILocation(line: 16, column: 3, scope: !20)
183 !39 = !DILocation(line: 17, column: 56, scope: !20)
184 !40 = !DILocation(line: 17, column: 21, scope: !20)
185 !41 = !DILocation(line: 18, column: 19, scope: !20)
186 !42 = !DILocation(line: 21, column: 30, scope: !20)
187 !43 = !DILocation(line: 21, column: 48, scope: !20)
188 !44 = !DILocation(line: 21, column: 3, scope: !20)
189 !45 = !DILocation(line: 22, column: 12, scope: !20)
190 !46 = !DILocation(line: 26, column: 7, scope: !20)
191 !47 = !{!48, !48, i64 0}
192 !48 = !{!"long long", !49, i64 0}
193 !49 = !{!"omnipotent char", !50, i64 0}
194 !50 = !{!"Simple C/C++ TBAA"}
195 !51 = !DILocation(line: 27, column: 7, scope: !52)
196 !52 = distinct !DILexicalBlock(scope: !20, file: !1, line: 27, column: 7)
197 !53 = !DILocation(line: 27, column: 7, scope: !20)
198 !54 = !DILocation(line: 30, column: 1, scope: !20)