1 ; RUN: opt --bpf-check-and-opt-ir -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
3 ; Check that unroll of getelementptr.and.store restores volatile.
6 ; #define __ctx __attribute__((preserve_static_offset))
13 ; extern void consume(int);
15 ; void bar(struct foo *p){
20 ; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
21 ; | opt -passes=sroa,bpf-preserve-static-offset -S -o -
23 %struct.foo = type { i32, i32 }
25 ; Function Attrs: nounwind
26 define dso_local void @bar(ptr noundef %p) #0 {
28 call void (i32, ptr, i1, i8, i8, i8, i1, ...)
29 @llvm.bpf.getelementptr.and.store.i32
31 ptr elementtype(%struct.foo) %p,
32 i1 true, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1),
37 ; CHECK: define dso_local void @bar(ptr noundef %[[p:.*]])
39 ; CHECK: %[[v2:.*]] = getelementptr inbounds %struct.foo, ptr %[[p]], i32 0, i32 1
40 ; CHECK: store volatile i32 42, ptr %[[v2]], align 4
42 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
43 declare ptr @llvm.preserve.static.offset(ptr readnone) #1
45 ; Function Attrs: nocallback nofree nounwind willreturn
46 declare void @llvm.bpf.getelementptr.and.store.i32(i32, ptr nocapture, i1 immarg, i8 immarg, i8 immarg, i8 immarg, i1 immarg, ...) #2
48 attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
49 attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
50 attributes #2 = { nocallback nofree nounwind willreturn }
52 !llvm.module.flags = !{!0}
55 !0 = !{i32 1, !"wchar_size", i32 4}
58 !3 = !{!"foo", !4, i64 0, !4, i64 4}
59 !4 = !{!"int", !5, i64 0}
60 !5 = !{!"omnipotent char", !6, i64 0}
61 !6 = !{!"Simple C/C++ TBAA"}