1; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s 2; 3; Check handling of a load instruction for a field with non-standard 4; alignment by bpf-preserve-static-offset. 5; 6; Source: 7; #define __ctx __attribute__((preserve_static_offset)) 8; 9; typedef int aligned_int __attribute__((aligned(128))); 10; 11; struct foo { 12; int _; 13; aligned_int a; 14; } __ctx; 15; 16; extern void consume(int); 17; 18; void bar(struct foo *p) { 19; consume(p->a); 20; } 21; 22; Compilation flag: 23; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \ 24; | opt -passes=function(sroa) -S -o - 25 26%struct.foo = type { i32, [124 x i8], i32, [124 x i8] } 27 28; Function Attrs: nounwind 29define dso_local void @bar(ptr noundef %p) #0 { 30entry: 31 %0 = call ptr @llvm.preserve.static.offset(ptr %p) 32 %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 2 33 %1 = load i32, ptr %a, align 128, !tbaa !2 34 call void @consume(i32 noundef %1) 35 ret void 36} 37 38; CHECK: %[[a1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...) 39; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32 40; CHECK-SAME: (ptr readonly elementtype(%struct.foo) %{{[^,]+}}, 41; CHECK-SAME: i1 false, i8 0, i8 1, i8 7, i1 true, i32 immarg 0, i32 immarg 2) 42; ^^^^ 43; alignment 2**7 44; CHECK-SAME: #[[v2:.*]], !tbaa 45; CHECK-NEXT: call void @consume(i32 noundef %[[a1]]) 46; CHECK: attributes #[[v2]] = { memory(argmem: read) } 47 48declare void @consume(i32 noundef) #1 49 50; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 51declare ptr @llvm.preserve.static.offset(ptr readnone) #2 52 53attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 54attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 55attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 56 57!llvm.module.flags = !{!0} 58!llvm.ident = !{!1} 59 60!0 = !{i32 1, !"wchar_size", i32 4} 61!1 = !{!"clang"} 62!2 = !{!3, !4, i64 128} 63!3 = !{!"foo", !4, i64 0, !4, i64 128} 64!4 = !{!"int", !5, i64 0} 65!5 = !{!"omnipotent char", !6, i64 0} 66!6 = !{!"Simple C/C++ TBAA"} 67