72 lines · plain
1; RUN: opt -passes=bpf-preserve-static-offset -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Check handling of a simple load instruction by bpf-preserve-static-offset.4; Verify:5; - presence of gep.and.load intrinsic call6; - correct attributes for intrinsic call7; - presence of tbaa annotations8;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: nounwind30define 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 134 %1 = load i32, ptr %a, align 4, !tbaa !235 call void @consume(i32 noundef %1)36 ret void37}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.i3242; 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:.*]], !tbaa45; CHECK-NEXT: call void @consume(i32 noundef %[[a1]])46 47; CHECK: declare i3248; 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) #154 55; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)56declare ptr @llvm.preserve.static.offset(ptr readnone) #257 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