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