1 ; RUN: opt --bpf-check-and-opt-ir -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
3 ; Check unroll of getelementptr.and.store when direct memory offset is
4 ; used instead of field indexes.
7 ; #define __ctx __attribute__((preserve_static_offset))
19 ; void buz(struct bar *p) {
20 ; ((struct foo *)(((char*)&p->b) + 1))->bb = 42;
24 ; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
25 ; | opt -passes=sroa,bpf-preserve-static-offset -S -o -
27 ; Function Attrs: nounwind
28 define dso_local void @buz(ptr noundef %p) #0 {
30 call void (i8, ptr, i1, i8, i8, i8, i1, ...)
31 @llvm.bpf.getelementptr.and.store.i8
33 ptr writeonly elementtype(i8) %p,
34 i1 false, i8 0, i8 1, i8 0, i1 true, i64 immarg 3)
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
43 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
44 declare ptr @llvm.preserve.static.offset(ptr readnone) #1
46 ; Function Attrs: nocallback nofree nounwind willreturn
47 declare void @llvm.bpf.getelementptr.and.store.i8(i8, ptr nocapture, i1 immarg, i8 immarg, i8 immarg, i8 immarg, i1 immarg, ...) #2
49 attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
50 attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
51 attributes #2 = { nocallback nofree nounwind willreturn }
52 attributes #3 = { memory(argmem: write) }
54 !llvm.module.flags = !{!0}
57 !0 = !{i32 1, !"wchar_size", i32 4}
60 !3 = !{!"foo", !4, i64 0, !4, i64 1}
61 !4 = !{!"omnipotent char", !5, i64 0}
62 !5 = !{!"Simple C/C++ TBAA"}