1; RUN: opt -O2 %s | llvm-dis > %t1 2; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s 3; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s 4; 5; Source Code: 6; #define _(x) (__builtin_preserve_access_index(x)) 7; struct s {int a; int b;}; 8; int test(struct s *arg) { return *(const int *)_(&arg->b); } 9; Compiler flag to generate IR: 10; clang -target bpf -S -O2 -g -emit-llvm -Xclang -disable-llvm-passes test.c 11 12target triple = "bpf" 13 14%struct.s = type { i32, i32 } 15 16; Function Attrs: nounwind readonly 17define dso_local i32 @test(ptr readonly %arg) local_unnamed_addr #0 !dbg !11 { 18entry: 19 call void @llvm.dbg.value(metadata ptr %arg, metadata !20, metadata !DIExpression()), !dbg !21 20 %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr elementtype(%struct.s) %arg, i32 1, i32 1), !dbg !22, !llvm.preserve.access.index !15 21 %1 = load i32, ptr %0, align 4, !dbg !23, !tbaa !24 22 ret i32 %1, !dbg !28 23} 24 25; CHECK-LABEL: test 26; CHECK-ALU64: r0 = *(u32 *)(r1 + 4) 27; CHECK-ALU32: w0 = *(u32 *)(r1 + 4) 28; CHECK: exit 29; 30; CHECK: .long 1 # BTF_KIND_STRUCT(id = 2) 31; 32; CHECK: .byte 115 # string offset=1 33; CHECK: .ascii ".text" # string offset=20 34; CHECK: .ascii "0:1" # string offset=26 35; 36; CHECK: .long 16 # FieldReloc 37; CHECK-NEXT: .long 20 # Field reloc section string offset=20 38; CHECK-NEXT: .long 1 39; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 40; CHECK-NEXT: .long 2 41; CHECK-NEXT: .long 26 42; CHECK-NEXT: .long 0 43 44; Function Attrs: nounwind readnone 45declare ptr @llvm.preserve.struct.access.index.p0.p0.ss(ptr, i32, i32) #1 46 47; Function Attrs: nounwind readnone speculatable willreturn 48declare void @llvm.dbg.value(metadata, metadata, metadata) #2 49 50attributes #0 = { nounwind readonly "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" } 51attributes #1 = { nounwind readnone } 52attributes #2 = { nounwind readnone speculatable willreturn } 53 54!llvm.dbg.cu = !{!0} 55!llvm.module.flags = !{!7, !8, !9} 56!llvm.ident = !{!10} 57 58!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 6e353b4df3aa452ed4741a5e5caea02b1a876d8c)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None) 59!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core") 60!2 = !{} 61!3 = !{!4} 62!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64) 63!5 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !6) 64!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 65!7 = !{i32 2, !"Dwarf Version", i32 4} 66!8 = !{i32 2, !"Debug Info Version", i32 3} 67!9 = !{i32 1, !"wchar_size", i32 4} 68!10 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 6e353b4df3aa452ed4741a5e5caea02b1a876d8c)"} 69!11 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !19) 70!12 = !DISubroutineType(types: !13) 71!13 = !{!6, !14} 72!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64) 73!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 2, size: 64, elements: !16) 74!16 = !{!17, !18} 75!17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 2, baseType: !6, size: 32) 76!18 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !15, file: !1, line: 2, baseType: !6, size: 32, offset: 32) 77!19 = !{!20} 78!20 = !DILocalVariable(name: "arg", arg: 1, scope: !11, file: !1, line: 3, type: !14) 79!21 = !DILocation(line: 0, scope: !11) 80!22 = !DILocation(line: 3, column: 48, scope: !11) 81!23 = !DILocation(line: 3, column: 34, scope: !11) 82!24 = !{!25, !25, i64 0} 83!25 = !{!"int", !26, i64 0} 84!26 = !{!"omnipotent char", !27, i64 0} 85!27 = !{!"Simple C/C++ TBAA"} 86!28 = !DILocation(line: 3, column: 27, scope: !11) 87