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; store 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; void foo(volatile struct t *t) { 16; t->ub = 1; 17; t->uh = 2; 18; t->uw = 3; 19; t->ud = 4; 20; } 21; 22; Using the following command: 23; clang -g -O2 -S -emit-llvm --target=bpf t.c -o t.ll 24 25@"llvm.t:0:0$0:0" = external global i64, !llvm.preserve.access.index !0 #0 26@"llvm.t:0:2$0:1" = external global i64, !llvm.preserve.access.index !0 #0 27@"llvm.t:0:4$0:2" = external global i64, !llvm.preserve.access.index !0 #0 28@"llvm.t:0:8$0:3" = external global i64, !llvm.preserve.access.index !0 #0 29 30; Function Attrs: nofree nounwind 31define dso_local void @foo(ptr noundef %t, i64 noundef %v) local_unnamed_addr #1 !dbg !18 { 32entry: 33 call void @llvm.dbg.value(metadata ptr %t, metadata !24, metadata !DIExpression()), !dbg !26 34 call void @llvm.dbg.value(metadata i64 %v, metadata !25, metadata !DIExpression()), !dbg !26 35 %conv = trunc i64 %v to i8, !dbg !27 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 store volatile i8 %conv, ptr %2, align 8, !dbg !28, !tbaa !29 40 %conv1 = trunc i64 %v to i16, !dbg !36 41 %3 = load i64, ptr @"llvm.t:0:2$0:1", align 8 42 %4 = getelementptr i8, ptr %t, i64 %3 43 %5 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 1, ptr %4) 44 store volatile i16 %conv1, ptr %5, align 2, !dbg !37, !tbaa !38 45 %conv2 = trunc i64 %v to i32, !dbg !39 46 %6 = load i64, ptr @"llvm.t:0:4$0:2", align 8 47 %7 = getelementptr i8, ptr %t, i64 %6 48 %8 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 2, ptr %7) 49 store volatile i32 %conv2, ptr %8, align 4, !dbg !40, !tbaa !41 50 %9 = load i64, ptr @"llvm.t:0:8$0:3", align 8 51 %10 = getelementptr i8, ptr %t, i64 %9 52 %11 = tail call ptr @llvm.bpf.passthrough.p0.p0(i32 3, ptr %10) 53 store volatile i64 %v, ptr %11, align 8, !dbg !42, !tbaa !43 54 ret void, !dbg !44 55} 56 57; CHECK: foo: 58; CHECK: prologue_end 59; CHECK-NEXT: .Ltmp[[LABEL_UB:.*]]: 60; CHECK-NEXT: .Ltmp 61; V2-NEXT: *(u8 *)(r1 + 0) = r2 62; V4-NEXT: *(u8 *)(r1 + 0) = w2 63; CHECK-NEXT: .loc 64; CHECK-NEXT: .Ltmp[[LABEL_UH:.*]]: 65; CHECK-NEXT: .Ltmp 66; V2-NEXT: *(u16 *)(r1 + 2) = r2 67; V4-NEXT: *(u16 *)(r1 + 2) = w2 68; CHECK-NEXT: .loc 69; CHECK-NEXT: .Ltmp[[LABEL_UW:.*]]: 70; CHECK-NEXT: .Ltmp 71; V2-NEXT: *(u32 *)(r1 + 4) = r2 72; V4-NEXT: *(u32 *)(r1 + 4) = w2 73; CHECK-NEXT: .loc 74; CHECK-NEXT: .Ltmp[[LABEL_UD:.*]]: 75; CHECK-NEXT: .Ltmp 76; CHECK-NEXT: *(u64 *)(r1 + 8) = r2 77 78; CHECK: .section .BTF 79; CHECK: .long [[STR_T:.*]] # BTF_KIND_STRUCT(id = [[ID:.*]]) 80 81; CHECK: .byte 116 # string offset=[[STR_T]] 82; CHECK: .ascii "0:0" # string offset=[[STR_UB:.*]] 83; CHECK: .ascii "0:1" # string offset=[[STR_UH:.*]] 84; CHECK: .ascii "0:2" # string offset=[[STR_UW:.*]] 85; CHECK: .ascii "0:3" # string offset=[[STR_UD:.*]] 86 87; CHECK: # FieldReloc 88; CHECK: .long .Ltmp[[LABEL_UB]] 89; CHECK-NEXT: .long [[ID]] 90; CHECK-NEXT: .long [[STR_UB]] 91; CHECK-NEXT: .long 0 92; CHECK: .long .Ltmp[[LABEL_UH]] 93; CHECK-NEXT: .long [[ID]] 94; CHECK-NEXT: .long [[STR_UH]] 95; CHECK-NEXT: .long 0 96; CHECK: .long .Ltmp[[LABEL_UW]] 97; CHECK-NEXT: .long [[ID]] 98; CHECK-NEXT: .long [[STR_UW]] 99; CHECK-NEXT: .long 0 100; CHECK: .long .Ltmp[[LABEL_UD]] 101; CHECK-NEXT: .long [[ID]] 102; CHECK-NEXT: .long [[STR_UD]] 103; CHECK-NEXT: .long 0 104 105; Function Attrs: nofree nosync nounwind memory(none) 106declare ptr @llvm.bpf.passthrough.p0.p0(i32, ptr) #2 107 108; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 109declare void @llvm.dbg.value(metadata, metadata, metadata) #3 110 111attributes #0 = { "btf_ama" } 112attributes #1 = { nofree nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 113attributes #2 = { nofree nosync nounwind memory(none) } 114attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 115 116!llvm.dbg.cu = !{!11} 117!llvm.module.flags = !{!12, !13, !14, !15, !16} 118!llvm.ident = !{!17} 119 120!0 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", file: !1, line: 1, size: 128, elements: !2) 121!1 = !DIFile(filename: "some.file", directory: "/some/dir", checksumkind: CSK_MD5, checksum: "2067f770ab52f9042a61e5bf50a913bd") 122!2 = !{!3, !5, !7, !9} 123!3 = !DIDerivedType(tag: DW_TAG_member, name: "ub", scope: !0, file: !1, line: 2, baseType: !4, size: 8) 124!4 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char) 125!5 = !DIDerivedType(tag: DW_TAG_member, name: "uh", scope: !0, file: !1, line: 3, baseType: !6, size: 16, offset: 16) 126!6 = !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned) 127!7 = !DIDerivedType(tag: DW_TAG_member, name: "uw", scope: !0, file: !1, line: 4, baseType: !8, size: 32, offset: 32) 128!8 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 129!9 = !DIDerivedType(tag: DW_TAG_member, name: "ud", scope: !0, file: !1, line: 5, baseType: !10, size: 64, offset: 64) 130!10 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned) 131!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) 132!12 = !{i32 7, !"Dwarf Version", i32 5} 133!13 = !{i32 2, !"Debug Info Version", i32 3} 134!14 = !{i32 1, !"wchar_size", i32 4} 135!15 = !{i32 7, !"frame-pointer", i32 2} 136!16 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 137!17 = !{!"clang version 18.0.0 (/home/eddy/work/llvm-project/clang 3810f2eb4382d5e2090ce5cd47f45379cb453c35)"} 138!18 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 13, type: !19, scopeLine: 13, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !11, retainedNodes: !23) 139!19 = !DISubroutineType(types: !20) 140!20 = !{null, !21, !10} 141!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64) 142!22 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !0) 143!23 = !{!24, !25} 144!24 = !DILocalVariable(name: "t", arg: 1, scope: !18, file: !1, line: 13, type: !21) 145!25 = !DILocalVariable(name: "v", arg: 2, scope: !18, file: !1, line: 13, type: !10) 146!26 = !DILocation(line: 0, scope: !18) 147!27 = !DILocation(line: 14, column: 11, scope: !18) 148!28 = !DILocation(line: 14, column: 9, scope: !18) 149!29 = !{!30, !31, i64 0} 150!30 = !{!"t", !31, i64 0, !33, i64 2, !34, i64 4, !35, i64 8} 151!31 = !{!"omnipotent char", !32, i64 0} 152!32 = !{!"Simple C/C++ TBAA"} 153!33 = !{!"short", !31, i64 0} 154!34 = !{!"int", !31, i64 0} 155!35 = !{!"long", !31, i64 0} 156!36 = !DILocation(line: 15, column: 11, scope: !18) 157!37 = !DILocation(line: 15, column: 9, scope: !18) 158!38 = !{!30, !33, i64 2} 159!39 = !DILocation(line: 16, column: 11, scope: !18) 160!40 = !DILocation(line: 16, column: 9, scope: !18) 161!41 = !{!30, !34, i64 4} 162!42 = !DILocation(line: 17, column: 9, scope: !18) 163!43 = !{!30, !35, i64 8} 164!44 = !DILocation(line: 18, column: 1, scope: !18) 165