brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · d8fa348 Raw
75 lines · plain
1; RUN: opt --bpf-check-and-opt-ir -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Check that getelementptr.and.load unroll can skip 'inbounds' flag.4;5; Source (IR modified by hand):6;    #define __ctx __attribute__((preserve_static_offset))7;    8;    struct bar {9;      int aa;10;      int bb;11;    };12;    13;    struct foo {14;      int a;15;      struct bar b;16;    } __ctx;17;    18;    extern void consume(int);19;    20;    void buz(struct foo *p) {21;      consume(p->b.bb);22;    }23;24; Compilation flag:25;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \26;       | opt -passes=sroa,bpf-preserve-static-offset -S -o -27;28; Modified to set 'inbounds' flag to false.29 30%struct.foo = type { i32, %struct.bar }31%struct.bar = type { i32, i32 }32 33; Function Attrs: nounwind34define dso_local void @buz(ptr noundef %p) #0 {35entry:36  %bb1 = call i32 (ptr, i1, i8, i8, i8, i1, ...)37    @llvm.bpf.getelementptr.and.load.i3238      (ptr readonly elementtype(%struct.foo) %p,39       i1 false, i8 0, i8 1, i8 2, i1 false, i32 immarg 0, i32 immarg 1, i32 immarg 1)40    #4, !tbaa !241  call void @consume(i32 noundef %bb1)42  ret void43}44 45; CHECK: define dso_local void @buz(ptr noundef %[[p:.*]])46; CHECK:   %[[bb11:.*]] = getelementptr %struct.foo, ptr %[[p]], i32 0, i32 1, i32 147; CHECK:   %[[v2:.*]] = load i32, ptr %[[bb11]], align 448; CHECK:   call void @consume(i32 noundef %[[v2]])49 50declare void @consume(i32 noundef) #151 52; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)53declare ptr @llvm.preserve.static.offset(ptr readnone) #254 55; Function Attrs: nocallback nofree nounwind willreturn56declare i32 @llvm.bpf.getelementptr.and.load.i32(ptr nocapture, i1 immarg, i8 immarg, i8 immarg, i8 immarg, i1 immarg, ...) #357 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) }61attributes #3 = { nocallback nofree nounwind willreturn }62attributes #4 = { memory(argmem: read) }63 64!llvm.module.flags = !{!0}65!llvm.ident = !{!1}66 67!0 = !{i32 1, !"wchar_size", i32 4}68!1 = !{!"clang"}69!2 = !{!3, !4, i64 8}70!3 = !{!"foo", !4, i64 0, !7, i64 4}71!4 = !{!"int", !5, i64 0}72!5 = !{!"omnipotent char", !6, i64 0}73!6 = !{!"Simple C/C++ TBAA"}74!7 = !{!"bar", !4, i64 0, !4, i64 4}75