xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/load-simple.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
2;
3; Check handling of a simple load instruction by bpf-preserve-static-offset.
4; Verify:
5; - presence of gep.and.load intrinsic call
6; - correct attributes for intrinsic call
7; - presence of tbaa annotations
8;
9; Source:
10;    #define __ctx __attribute__((preserve_static_offset))
11;
12;    struct foo {
13;      int _;
14;      int a;
15;    } __ctx;
16;
17;    extern void consume(int);
18;
19;    void bar(struct foo *p) {
20;      consume(p->a);
21;    }
22;
23; Compilation flag:
24;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
25;       | opt -passes=function(sroa) -S -o -
26
27%struct.foo = type { i32, i32 }
28
29; Function Attrs: nounwind
30define dso_local void @bar(ptr noundef %p) #0 {
31entry:
32  %0 = call ptr @llvm.preserve.static.offset(ptr %p)
33  %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
34  %1 = load i32, ptr %a, align 4, !tbaa !2
35  call void @consume(i32 noundef %1)
36  ret void
37}
38
39; CHECK:      define dso_local void @bar(ptr noundef %[[p:.*]])
40; CHECK:      %[[a1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...)
41; CHECK-SAME:    @llvm.bpf.getelementptr.and.load.i32
42; CHECK-SAME:      (ptr readonly elementtype(%struct.foo) %[[p]],
43; CHECK-SAME:       i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1)
44; CHECK-SAME:         #[[v1:.*]], !tbaa
45; CHECK-NEXT: call void @consume(i32 noundef %[[a1]])
46
47; CHECK:      declare i32
48; CHECK-SAME:    @llvm.bpf.getelementptr.and.load.i32(ptr captures(none), {{.*}}) #[[v2:.*]]
49
50; CHECK:      attributes #[[v2]] = { nocallback nofree nounwind willreturn }
51; CHECK:      attributes #[[v1]] = { memory(argmem: read) }
52
53declare void @consume(i32 noundef) #1
54
55; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
56declare ptr @llvm.preserve.static.offset(ptr readnone) #2
57
58attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
59attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
60attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
61
62!llvm.module.flags = !{!0}
63!llvm.ident = !{!1}
64
65!0 = !{i32 1, !"wchar_size", i32 4}
66!1 = !{!"clang"}
67!2 = !{!3, !4, i64 4}
68!3 = !{!"foo", !4, i64 0, !4, i64 4}
69!4 = !{!"int", !5, i64 0}
70!5 = !{!"omnipotent char", !6, i64 0}
71!6 = !{!"Simple C/C++ TBAA"}
72