1030b8cb1SEduard Zingerman; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s 2030b8cb1SEduard Zingerman; 3030b8cb1SEduard Zingerman; Check handling of a simple load instruction by bpf-preserve-static-offset. 4030b8cb1SEduard Zingerman; Verify: 5030b8cb1SEduard Zingerman; - presence of gep.and.load intrinsic call 6030b8cb1SEduard Zingerman; - correct attributes for intrinsic call 7030b8cb1SEduard Zingerman; - presence of tbaa annotations 8030b8cb1SEduard Zingerman; 9030b8cb1SEduard Zingerman; Source: 10030b8cb1SEduard Zingerman; #define __ctx __attribute__((preserve_static_offset)) 11030b8cb1SEduard Zingerman; 12030b8cb1SEduard Zingerman; struct foo { 13030b8cb1SEduard Zingerman; int _; 14030b8cb1SEduard Zingerman; int a; 15030b8cb1SEduard Zingerman; } __ctx; 16030b8cb1SEduard Zingerman; 17030b8cb1SEduard Zingerman; extern void consume(int); 18030b8cb1SEduard Zingerman; 19030b8cb1SEduard Zingerman; void bar(struct foo *p) { 20030b8cb1SEduard Zingerman; consume(p->a); 21030b8cb1SEduard Zingerman; } 22030b8cb1SEduard Zingerman; 23030b8cb1SEduard Zingerman; Compilation flag: 24030b8cb1SEduard Zingerman; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \ 25030b8cb1SEduard Zingerman; | opt -passes=function(sroa) -S -o - 26030b8cb1SEduard Zingerman 27030b8cb1SEduard Zingerman%struct.foo = type { i32, i32 } 28030b8cb1SEduard Zingerman 29030b8cb1SEduard Zingerman; Function Attrs: nounwind 30030b8cb1SEduard Zingermandefine dso_local void @bar(ptr noundef %p) #0 { 31030b8cb1SEduard Zingermanentry: 32030b8cb1SEduard Zingerman %0 = call ptr @llvm.preserve.static.offset(ptr %p) 33030b8cb1SEduard Zingerman %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1 34030b8cb1SEduard Zingerman %1 = load i32, ptr %a, align 4, !tbaa !2 35030b8cb1SEduard Zingerman call void @consume(i32 noundef %1) 36030b8cb1SEduard Zingerman ret void 37030b8cb1SEduard Zingerman} 38030b8cb1SEduard Zingerman 39030b8cb1SEduard Zingerman; CHECK: define dso_local void @bar(ptr noundef %[[p:.*]]) 40030b8cb1SEduard Zingerman; CHECK: %[[a1:.*]] = call i32 (ptr, i1, i8, i8, i8, i1, ...) 41030b8cb1SEduard Zingerman; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32 42030b8cb1SEduard Zingerman; CHECK-SAME: (ptr readonly elementtype(%struct.foo) %[[p]], 43030b8cb1SEduard Zingerman; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1) 44030b8cb1SEduard Zingerman; CHECK-SAME: #[[v1:.*]], !tbaa 45030b8cb1SEduard Zingerman; CHECK-NEXT: call void @consume(i32 noundef %[[a1]]) 46030b8cb1SEduard Zingerman 47030b8cb1SEduard Zingerman; CHECK: declare i32 48*29441e4fSNikita Popov; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32(ptr captures(none), {{.*}}) #[[v2:.*]] 49030b8cb1SEduard Zingerman 50030b8cb1SEduard Zingerman; CHECK: attributes #[[v2]] = { nocallback nofree nounwind willreturn } 51030b8cb1SEduard Zingerman; CHECK: attributes #[[v1]] = { memory(argmem: read) } 52030b8cb1SEduard Zingerman 53030b8cb1SEduard Zingermandeclare void @consume(i32 noundef) #1 54030b8cb1SEduard Zingerman 55030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 56030b8cb1SEduard Zingermandeclare ptr @llvm.preserve.static.offset(ptr readnone) #2 57030b8cb1SEduard Zingerman 58030b8cb1SEduard Zingermanattributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 59030b8cb1SEduard Zingermanattributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 60030b8cb1SEduard Zingermanattributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 61030b8cb1SEduard Zingerman 62030b8cb1SEduard Zingerman!llvm.module.flags = !{!0} 63030b8cb1SEduard Zingerman!llvm.ident = !{!1} 64030b8cb1SEduard Zingerman 65030b8cb1SEduard Zingerman!0 = !{i32 1, !"wchar_size", i32 4} 66030b8cb1SEduard Zingerman!1 = !{!"clang"} 67030b8cb1SEduard Zingerman!2 = !{!3, !4, i64 4} 68030b8cb1SEduard Zingerman!3 = !{!"foo", !4, i64 0, !4, i64 4} 69030b8cb1SEduard Zingerman!4 = !{!"int", !5, i64 0} 70030b8cb1SEduard Zingerman!5 = !{!"omnipotent char", !6, i64 0} 71030b8cb1SEduard Zingerman!6 = !{!"Simple C/C++ TBAA"} 72