xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/store-align.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
2;
3; Check handling of a store 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;    void bar(struct foo *p) {
17;      p->a = 7;
18;    }
19;
20; Compilation flag:
21;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
22;       | opt -passes=function(sroa) -S -o -
23
24%struct.foo = type { i32, [124 x i8], i32, [124 x i8] }
25
26; Function Attrs: nounwind
27define dso_local void @bar(ptr noundef %p) #0 {
28entry:
29  %0 = call ptr @llvm.preserve.static.offset(ptr %p)
30  %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 2
31  store i32 7, ptr %a, align 128, !tbaa !2
32  ret void
33}
34
35; CHECK:      define dso_local void @bar(ptr noundef writeonly captures(none) %[[p:.*]])
36; CHECK:        tail call void (i32, ptr, i1, i8, i8, i8, i1, ...)
37; CHECK-SAME:     @llvm.bpf.getelementptr.and.store.i32
38; CHECK-SAME:       (i32 7,
39; CHECK-SAME:        ptr writeonly elementtype(%struct.foo) %[[p]],
40; CHECK-SAME:        i1 false, i8 0, i8 1, i8 7, i1 true, i32 immarg 0, i32 immarg 2)
41; CHECK-SAME:      #[[v2:.*]], !tbaa
42; CHECK:      attributes #[[v2]] = { memory(argmem: write) }
43
44; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
45declare ptr @llvm.preserve.static.offset(ptr readnone) #1
46
47attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
48attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
49
50!llvm.module.flags = !{!0}
51!llvm.ident = !{!1}
52
53!0 = !{i32 1, !"wchar_size", i32 4}
54!1 = !{!"clang"}
55!2 = !{!3, !4, i64 128}
56!3 = !{!"foo", !4, i64 0, !4, i64 128}
57!4 = !{!"int", !5, i64 0}
58!5 = !{!"omnipotent char", !6, i64 0}
59!6 = !{!"Simple C/C++ TBAA"}
60