1030b8cb1SEduard Zingerman; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s 2030b8cb1SEduard Zingerman; 3030b8cb1SEduard Zingerman; Check position of bpf-preserve-static-offset pass in the pipeline: 4030b8cb1SEduard Zingerman; - preserve.static.offset call is preserved if address is passed as 5030b8cb1SEduard Zingerman; a parameter to an inline-able function; 6030b8cb1SEduard Zingerman; - second bpf-preserve-static-offset pass (after inlining) should introduce 7030b8cb1SEduard Zingerman; getelementptr.and.load call using the preserved marker. 8030b8cb1SEduard Zingerman; 9030b8cb1SEduard Zingerman; Source: 10030b8cb1SEduard Zingerman; #define __ctx __attribute__((preserve_static_offset)) 11030b8cb1SEduard Zingerman; 12030b8cb1SEduard Zingerman; struct bar { 13030b8cb1SEduard Zingerman; int aa; 14030b8cb1SEduard Zingerman; int bb; 15030b8cb1SEduard Zingerman; }; 16030b8cb1SEduard Zingerman; 17030b8cb1SEduard Zingerman; struct foo { 18030b8cb1SEduard Zingerman; int a; 19030b8cb1SEduard Zingerman; struct bar b; 20030b8cb1SEduard Zingerman; } __ctx; 21030b8cb1SEduard Zingerman; 22030b8cb1SEduard Zingerman; extern void consume(int); 23030b8cb1SEduard Zingerman; 24030b8cb1SEduard Zingerman; static inline void bar(struct bar *p){ 25030b8cb1SEduard Zingerman; consume(p->bb); 26030b8cb1SEduard Zingerman; } 27030b8cb1SEduard Zingerman; 28030b8cb1SEduard Zingerman; void quux(struct foo *p) { 29030b8cb1SEduard Zingerman; bar(&p->b); 30030b8cb1SEduard Zingerman; } 31030b8cb1SEduard Zingerman; 32030b8cb1SEduard Zingerman; Compilation flag: 33030b8cb1SEduard Zingerman; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \ 34030b8cb1SEduard Zingerman; | opt -passes=function(sroa) -S -o - 35030b8cb1SEduard Zingerman 36030b8cb1SEduard Zingerman%struct.foo = type { i32, %struct.bar } 37030b8cb1SEduard Zingerman%struct.bar = type { i32, i32 } 38030b8cb1SEduard Zingerman 39030b8cb1SEduard Zingerman; Function Attrs: nounwind 40030b8cb1SEduard Zingermandefine dso_local void @quux(ptr noundef %p) #0 { 41030b8cb1SEduard Zingermanentry: 42030b8cb1SEduard Zingerman %0 = call ptr @llvm.preserve.static.offset(ptr %p) 43030b8cb1SEduard Zingerman %b = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1 44030b8cb1SEduard Zingerman call void @bar(ptr noundef %b) 45030b8cb1SEduard Zingerman ret void 46030b8cb1SEduard Zingerman} 47030b8cb1SEduard Zingerman 48030b8cb1SEduard Zingerman; Function Attrs: inlinehint nounwind 49030b8cb1SEduard Zingermandefine internal void @bar(ptr noundef %p) #1 { 50030b8cb1SEduard Zingermanentry: 51030b8cb1SEduard Zingerman %bb = getelementptr inbounds %struct.bar, ptr %p, i32 0, i32 1 52030b8cb1SEduard Zingerman %0 = load i32, ptr %bb, align 4, !tbaa !2 53030b8cb1SEduard Zingerman call void @consume(i32 noundef %0) 54030b8cb1SEduard Zingerman ret void 55030b8cb1SEduard Zingerman} 56030b8cb1SEduard Zingerman 57*29441e4fSNikita Popov; CHECK: define dso_local void @quux(ptr noundef readonly captures(none) %[[p:.*]]) 58030b8cb1SEduard Zingerman; CHECK: %[[bb_i1:.*]] = tail call i32 (ptr, i1, i8, i8, i8, i1, ...) 59030b8cb1SEduard Zingerman; CHECK-SAME: @llvm.bpf.getelementptr.and.load.i32 6090ba3309SNikita Popov; CHECK-SAME: (ptr readonly elementtype(i8) %[[p]], 6190ba3309SNikita Popov; CHECK-SAME: i1 false, i8 0, i8 1, i8 2, i1 true, i64 immarg 8) 62030b8cb1SEduard Zingerman; CHECK-SAME: #[[v2:.*]], !tbaa 63030b8cb1SEduard Zingerman; CHECK-NEXT: tail call void @consume(i32 noundef %[[bb_i1]]) 64030b8cb1SEduard Zingerman; CHECK: attributes #[[v2]] = { memory(argmem: read) } 65030b8cb1SEduard Zingerman 66030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 67030b8cb1SEduard Zingermandeclare ptr @llvm.preserve.static.offset(ptr readnone) #2 68030b8cb1SEduard Zingerman 69030b8cb1SEduard Zingermandeclare void @consume(i32 noundef) #3 70030b8cb1SEduard Zingerman 71030b8cb1SEduard Zingermanattributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 72030b8cb1SEduard Zingermanattributes #1 = { inlinehint nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 73030b8cb1SEduard Zingermanattributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 74030b8cb1SEduard Zingermanattributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 75030b8cb1SEduard Zingerman 76030b8cb1SEduard Zingerman!llvm.module.flags = !{!0} 77030b8cb1SEduard Zingerman!llvm.ident = !{!1} 78030b8cb1SEduard Zingerman 79030b8cb1SEduard Zingerman!0 = !{i32 1, !"wchar_size", i32 4} 80030b8cb1SEduard Zingerman!1 = !{!"clang"} 81030b8cb1SEduard Zingerman!2 = !{!3, !4, i64 4} 82030b8cb1SEduard Zingerman!3 = !{!"bar", !4, i64 0, !4, i64 4} 83030b8cb1SEduard Zingerman!4 = !{!"int", !5, i64 0} 84030b8cb1SEduard Zingerman!5 = !{!"omnipotent char", !6, i64 0} 85030b8cb1SEduard Zingerman!6 = !{!"Simple C/C++ TBAA"} 86