brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · 9774ca4 Raw
105 lines · plain
1; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s2;3; Check position of bpf-preserve-static-offset pass in the pipeline:4; - preserve.static.offset call is preserved if address is passed as5;   a parameter to an inline-able function;6; - second bpf-preserve-static-offset pass (after inlining) should introduce7;   getelementptr.and.store call using the preserved marker after loops8;   unrolling;9; - memory(argmem: readwrite) and tbaa attributes should allow10;   removing one getelementptr.and.store call.11;12; Source:13;    #define __ctx __attribute__((preserve_static_offset))14;    15;    struct foo {16;      int a;17;      int b[4];18;    } __ctx;19;    20;    static inline void bar(int * restrict p, unsigned long i) {21;      p[0] = i;22;    }23;    24;    void quux(struct foo *p){25;      unsigned long i = 0;26;    #pragma clang loop unroll(full)27;      while (i < 2) {28;        bar(p->b, i);29;        ++i;30;      }31;    }32;33; Compilation flag:34;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \35;       | opt -passes=function(sroa) -S -o -36 37%struct.foo = type { i32, [4 x i32] }38 39; Function Attrs: nounwind40define dso_local void @quux(ptr noundef %p) #0 {41entry:42  br label %while.cond43 44while.cond:                                       ; preds = %while.body, %entry45  %i.0 = phi i64 [ 0, %entry ], [ %inc, %while.body ]46  %cmp = icmp ult i64 %i.0, 247  br i1 %cmp, label %while.body, label %while.end48 49while.body:                                       ; preds = %while.cond50  %0 = call ptr @llvm.preserve.static.offset(ptr %p)51  %b = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 152  %arraydecay = getelementptr inbounds [4 x i32], ptr %b, i64 0, i64 053  call void @bar(ptr noundef %arraydecay, i64 noundef %i.0)54  %inc = add i64 %i.0, 155  br label %while.cond, !llvm.loop !256 57while.end:                                        ; preds = %while.cond58  ret void59}60 61; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)62declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #163 64; Function Attrs: inlinehint nounwind65define internal void @bar(ptr noalias noundef %p, i64 noundef %i) #2 {66entry:67  %conv = trunc i64 %i to i3268  %arrayidx = getelementptr inbounds i32, ptr %p, i64 069  store i32 %conv, ptr %arrayidx, align 4, !tbaa !570  ret void71}72 73; CHECK:      define dso_local void @quux(ptr noundef writeonly captures(none) %[[p:.*]])74; CHECK-NEXT: entry:75; CHECK-NEXT:   tail call void (i32, ptr, i1, i8, i8, i8, i1, ...)76; CHECK-SAME:     @llvm.bpf.getelementptr.and.store.i3277; CHECK-SAME:       (i32 1,78; CHECK-SAME:        ptr writeonly elementtype(i8) %[[p]],79; CHECK-SAME:        i1 false, i8 0, i8 1, i8 2, i1 true, i64 immarg 4)80; CHECK-NEXT:   ret void81 82; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)83declare ptr @llvm.preserve.static.offset(ptr readnone) #384 85; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)86declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #187 88attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }89attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }90attributes #2 = { inlinehint nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }91attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }92 93!llvm.module.flags = !{!0}94!llvm.ident = !{!1}95 96!0 = !{i32 1, !"wchar_size", i32 4}97!1 = !{!"clang"}98!2 = distinct !{!2, !3, !4}99!3 = !{!"llvm.loop.mustprogress"}100!4 = !{!"llvm.loop.unroll.full"}101!5 = !{!6, !6, i64 0}102!6 = !{!"int", !7, i64 0}103!7 = !{!"omnipotent char", !8, i64 0}104!8 = !{!"Simple C/C++ TBAA"}105