1; RUN: llc -mtriple=bpf -mcpu=v4 < %s | FileCheck -check-prefixes=CHECK %s 2 3; Verify that BPFMISimplifyPatchable::checkADDrr correctly rewrites 4; load instructions with sign extension. 5; 6; Generated from the following source code: 7; struct t { 8; signed char sb; 9; signed short sh; 10; signed int sw; 11; } __attribute__((preserve_access_index)); 12; 13; extern void cs(signed long); 14; 15; void buz(volatile struct t *t) { 16; cs(t->sb); 17; cs(t->sh); 18; cs(t->sw); 19; } 20; 21; Using the following command: 22; clang -g -O2 -S -emit-llvm --target=bpf t.c -o t.ll 23 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 27 28; Function Attrs: nounwind 29define dso_local void @buz(ptr noundef %t) local_unnamed_addr #1 !dbg !16 { 30entry: 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 50 ret void, !dbg !41 51} 52 53; CHECK: buz: 54; CHECK: prologue_end 55; CHECK-NEXT: .Ltmp[[LABEL_SB:.*]]: 56; CHECK-NEXT: .Ltmp 57; CHECK-NEXT: r1 = *(s8 *)(r6 + 0) 58; CHECK-NEXT: .loc 59; CHECK-NEXT: .Ltmp 60; CHECK-NEXT: call cs 61; CHECK-NEXT: .Ltmp 62; CHECK-NEXT: .loc 63; CHECK-NEXT: .Ltmp[[LABEL_SH:.*]]: 64; CHECK-NEXT: .Ltmp 65; CHECK-NEXT: r1 = *(s16 *)(r6 + 2) 66; CHECK-NEXT: .loc 67; CHECK-NEXT: .Ltmp 68; CHECK-NEXT: call cs 69; CHECK-NEXT: .Ltmp 70; CHECK-NEXT: .loc 71; CHECK-NEXT: .Ltmp[[LABEL_SW:.*]]: 72; CHECK-NEXT: .Ltmp 73; CHECK-NEXT: r1 = *(s32 *)(r6 + 4) 74; CHECK-NEXT: .loc 75; CHECK-NEXT: .Ltmp 76; CHECK-NEXT: call cs 77 78; CHECK: .section .BTF 79; CHECK: .long [[T:.*]] # BTF_KIND_STRUCT(id = [[ID:.*]]) 80 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:.*]] 85 86; CHECK: # FieldReloc 87; CHECK: .long .Ltmp[[LABEL_SB]] 88; CHECK-NEXT: .long [[ID]] 89; CHECK-NEXT: .long [[STR_SB]] 90; CHECK-NEXT: .long 0 91; CHECK: .long .Ltmp[[LABEL_SH]] 92; CHECK-NEXT: .long [[ID]] 93; CHECK-NEXT: .long [[STR_SH]] 94; CHECK-NEXT: .long 0 95; CHECK: .long .Ltmp[[LABEL_SW]] 96; CHECK-NEXT: .long [[ID]] 97; CHECK-NEXT: .long [[STR_SW]] 98; CHECK-NEXT: .long 0 99 100declare !dbg !42 dso_local void @cs(i64 noundef) local_unnamed_addr #2 101 102; Function Attrs: nofree nosync nounwind memory(none) 103declare ptr @llvm.bpf.passthrough.p0.p0(i32, ptr) #3 104 105; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 106declare void @llvm.dbg.value(metadata, metadata, metadata) #4 107 108attributes #0 = { "btf_ama" } 109attributes #1 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 110attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 111attributes #3 = { nofree nosync nounwind memory(none) } 112attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 113attributes #5 = { nounwind } 114 115!llvm.dbg.cu = !{!9} 116!llvm.module.flags = !{!10, !11, !12, !13, !14} 117!llvm.ident = !{!15} 118 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") 121!2 = !{!3, !5, !7} 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) 137!18 = !{null, !19} 138!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) 139!20 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !0) 140!21 = !{!22} 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) 163!44 = !{null, !45} 164!45 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed) 165!46 = !{!47} 166!47 = !DILocalVariable(arg: 1, scope: !42, file: !1, line: 11, type: !45) 167