xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/store-undo-chain.ll (revision 030b8cb1561db4161b108b59044717d89026cf70)
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 several field indexes
4; are specified in a chain.
5;
6; Source:
7;    #define __ctx __attribute__((preserve_static_offset))
8;
9;    struct bar {
10;      int aa;
11;      int bb;
12;    };
13;
14;    struct foo {
15;      int a;
16;      struct bar b;
17;    } __ctx;
18;
19;    void buz(struct foo *p) {
20;      p->b.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%struct.foo = type { i32, %struct.bar }
28%struct.bar = type { i32, i32 }
29
30; Function Attrs: nounwind
31define dso_local void @buz(ptr noundef %p) #0 {
32entry:
33  call void (i32, ptr, i1, i8, i8, i8, i1, ...)
34    @llvm.bpf.getelementptr.and.store.i32
35      (i32 42,
36       ptr writeonly elementtype(%struct.foo) %p,
37       i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1, i32 immarg 1)
38    #3, !tbaa !2
39  ret void
40}
41
42; CHECK: define dso_local void @buz(ptr noundef %[[p:.*]])
43; CHECK:   %[[v2:.*]] = getelementptr inbounds %struct.foo, ptr %[[p]], i32 0, i32 1, i32 1
44; CHECK:   store i32 42, ptr %[[v2]], align 4
45; CHECK:   ret void
46
47; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
48declare ptr @llvm.preserve.static.offset(ptr readnone) #1
49
50; Function Attrs: nocallback nofree nounwind willreturn
51declare void @llvm.bpf.getelementptr.and.store.i32(i32, ptr nocapture, i1 immarg, i8 immarg, i8 immarg, i8 immarg, i1 immarg, ...) #2
52
53attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
54attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
55attributes #2 = { nocallback nofree nounwind willreturn }
56attributes #3 = { memory(argmem: write) }
57
58!llvm.module.flags = !{!0}
59!llvm.ident = !{!1}
60
61!0 = !{i32 1, !"wchar_size", i32 4}
62!1 = !{!"clang"}
63!2 = !{!3, !4, i64 8}
64!3 = !{!"foo", !4, i64 0, !7, i64 4}
65!4 = !{!"int", !5, i64 0}
66!5 = !{!"omnipotent char", !6, i64 0}
67!6 = !{!"Simple C/C++ TBAA"}
68!7 = !{!"bar", !4, i64 0, !4, i64 4}
69