68 lines · plain
1; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Check that bpf-preserve-static-offset folds chain of GEP instructions.4; The GEP chain in this example has type mismatch and thus is5; folded as i8 access.6;7; Source (modified by hand):8; #define __ctx __attribute__((preserve_static_offset))9; 10; struct foo {11; char aa;12; char bb;13; };14; 15; struct bar {16; char a;17; struct foo b;18; } __ctx;19; 20; void buz(struct bar *p) {21; ((struct foo *)(((char*)&p->b) + 1))->bb = 42;22; }23;24; Compilation flag:25; clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \26; | opt -passes=function(sroa) -S -o -27;28; Modified to remove one of the 'inbounds' from one of the getelementptr.29 30%struct.bar = type { i8, %struct.foo }31%struct.foo = type { i8, i8 }32 33; Function Attrs: nounwind34define dso_local void @buz(ptr noundef %p) #0 {35entry:36 %0 = call ptr @llvm.preserve.static.offset(ptr %p)37 %b = getelementptr inbounds %struct.bar, ptr %0, i32 0, i32 138 %add.ptr = getelementptr i8, ptr %b, i64 139 %bb = getelementptr inbounds %struct.foo, ptr %add.ptr, i32 0, i32 140 store i8 42, ptr %bb, align 1, !tbaa !241 ret void42}43 44; CHECK: define dso_local void @buz(ptr noundef writeonly captures(none) %[[p:.*]])45; CHECK: tail call void (i8, ptr, i1, i8, i8, i8, i1, ...)46; CHECK-SAME: @llvm.bpf.getelementptr.and.store.i847; CHECK-SAME: (i8 42,48; CHECK-SAME: ptr writeonly elementtype(i8) %[[p]],49; CHECK-SAME: i1 false, i8 0, i8 1, i8 0, i1 false, i64 immarg 3)50; CHECK-SAME: #[[v2:.*]], !tbaa ![[v3:.*]]51; CHECK: attributes #[[v2]] = { memory(argmem: write) }52 53; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)54declare ptr @llvm.preserve.static.offset(ptr readnone) #155 56attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }57attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }58 59!llvm.module.flags = !{!0}60!llvm.ident = !{!1}61 62!0 = !{i32 1, !"wchar_size", i32 4}63!1 = !{!"clang"}64!2 = !{!3, !4, i64 1}65!3 = !{!"foo", !4, i64 0, !4, i64 1}66!4 = !{!"omnipotent char", !5, i64 0}67!5 = !{!"Simple C/C++ TBAA"}68