74 lines · plain
1; RUN: opt --bpf-check-and-opt-ir -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Check unroll of getelementptr.and.load when several field indexes4; are specified in a chain.5;6; Source:7; #define __ctx __attribute__((preserve_static_offset))8; 9; struct bar {10; int aa;11; int bb;12; };13; 14; struct foo {15; int a;16; struct bar b;17; } __ctx;18; 19; extern void consume(int);20; 21; void buz(struct foo *p) {22; consume(p->b.bb);23; }24;25; Compilation flag:26; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \27; | opt -passes=sroa,bpf-preserve-static-offset -S -o -28 29%struct.foo = type { i32, %struct.bar }30%struct.bar = type { i32, i32 }31 32; Function Attrs: nounwind33define dso_local void @buz(ptr noundef %p) #0 {34entry:35 %bb1 = call i32 (ptr, i1, i8, i8, i8, i1, ...)36 @llvm.bpf.getelementptr.and.load.i3237 (ptr readonly elementtype(%struct.foo) %p,38 i1 false, i8 0, i8 1, i8 2, i1 true, i32 immarg 0, i32 immarg 1, i32 immarg 1)39 #4, !tbaa !240 call void @consume(i32 noundef %bb1)41 ret void42}43 44; CHECK: define dso_local void @buz(ptr noundef %[[p:.*]])45; CHECK: %[[bb11:.*]] = getelementptr inbounds %struct.foo, ptr %[[p]], i32 0, i32 1, i32 146; CHECK: %[[v2:.*]] = load i32, ptr %[[bb11]], align 447; CHECK: call void @consume(i32 noundef %[[v2]])48 49declare void @consume(i32 noundef) #150 51; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)52declare ptr @llvm.preserve.static.offset(ptr readnone) #253 54; Function Attrs: nocallback nofree nounwind willreturn55declare i32 @llvm.bpf.getelementptr.and.load.i32(ptr nocapture, i1 immarg, i8 immarg, i8 immarg, i8 immarg, i1 immarg, ...) #356 57attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }58attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }59attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }60attributes #3 = { nocallback nofree nounwind willreturn }61attributes #4 = { memory(argmem: read) }62 63!llvm.module.flags = !{!0}64!llvm.ident = !{!1}65 66!0 = !{i32 1, !"wchar_size", i32 4}67!1 = !{!"clang"}68!2 = !{!3, !4, i64 8}69!3 = !{!"foo", !4, i64 0, !7, i64 4}70!4 = !{!"int", !5, i64 0}71!5 = !{!"omnipotent char", !6, i64 0}72!6 = !{!"Simple C/C++ TBAA"}73!7 = !{!"bar", !4, i64 0, !4, i64 4}74