1; RUN: opt --bpf-check-and-opt-ir -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s 2; 3; Check unroll of getelementptr.and.store when direct memory offset is 4; used instead of field indexes. 5; 6; Source: 7; #define __ctx __attribute__((preserve_static_offset)) 8; 9; struct foo { 10; char aa; 11; char bb; 12; }; 13; 14; struct bar { 15; char a; 16; struct foo b; 17; } __ctx; 18; 19; void buz(struct bar *p) { 20; ((struct foo *)(((char*)&p->b) + 1))->bb = 42; 21; } 22; 23; Compilation flag: 24; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \ 25; | opt -passes=sroa,bpf-preserve-static-offset -S -o - 26 27; Function Attrs: nounwind 28define dso_local void @buz(ptr noundef %p) #0 { 29entry: 30 call void (i8, ptr, i1, i8, i8, i8, i1, ...) 31 @llvm.bpf.getelementptr.and.store.i8 32 (i8 42, 33 ptr writeonly elementtype(i8) %p, 34 i1 false, i8 0, i8 1, i8 0, i1 true, i64 immarg 3) 35 #3, !tbaa !2 36 ret void 37} 38 39; CHECK: define dso_local void @buz(ptr noundef %[[p:.*]]) 40; CHECK: %[[v2:.*]] = getelementptr inbounds i8, ptr %[[p]], i64 3 41; CHECK: store i8 42, ptr %[[v2]], align 1 42 43; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 44declare ptr @llvm.preserve.static.offset(ptr readnone) #1 45 46; Function Attrs: nocallback nofree nounwind willreturn 47declare void @llvm.bpf.getelementptr.and.store.i8(i8, ptr nocapture, i1 immarg, i8 immarg, i8 immarg, i8 immarg, i1 immarg, ...) #2 48 49attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 50attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 51attributes #2 = { nocallback nofree nounwind willreturn } 52attributes #3 = { memory(argmem: write) } 53 54!llvm.module.flags = !{!0} 55!llvm.ident = !{!1} 56 57!0 = !{i32 1, !"wchar_size", i32 4} 58!1 = !{!"clang"} 59!2 = !{!3, !4, i64 1} 60!3 = !{!"foo", !4, i64 0, !4, i64 1} 61!4 = !{!"omnipotent char", !5, i64 0} 62!5 = !{!"Simple C/C++ TBAA"} 63