xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/store-zero.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
2;
3; Check that stores from zero offset are not modified by bpf-preserve-static-offset.
4;
5; Source:
6;    #define __ctx __attribute__((preserve_static_offset))
7;
8;    struct foo {
9;      int a;
10;    } __ctx;
11;
12;    void bar(struct foo *p) {
13;      p->a = 0;
14;    }
15;
16; Compilation flag:
17;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
18;       | opt -passes=function(sroa) -S -o -
19
20%struct.foo = type { i32 }
21
22; Function Attrs: nounwind
23define dso_local void @bar(ptr noundef %p) #0 {
24entry:
25  %0 = call ptr @llvm.preserve.static.offset(ptr %p)
26  %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 0
27  store i32 0, ptr %a, align 4, !tbaa !2
28  ret void
29}
30
31; CHECK:      define dso_local void @bar(ptr noundef writeonly captures(none) initializes((0, 4)) %[[p:.*]])
32; CHECK-NEXT: entry:
33; CHECK-NEXT:   store i32 0, ptr %[[p]], align 4, !tbaa
34; CHECK-NEXT:   ret void
35
36; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
37declare ptr @llvm.preserve.static.offset(ptr readnone) #1
38
39attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
40attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
41
42!llvm.module.flags = !{!0}
43!llvm.ident = !{!1}
44
45!0 = !{i32 1, !"wchar_size", i32 4}
46!1 = !{!"clang"}
47!2 = !{!3, !4, i64 0}
48!3 = !{!"foo", !4, i64 0}
49!4 = !{!"int", !5, i64 0}
50!5 = !{!"omnipotent char", !6, i64 0}
51!6 = !{!"Simple C/C++ TBAA"}
52