xref: /llvm-project/llvm/test/CodeGen/BPF/preserve-static-offset/load-unroll.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1030b8cb1SEduard Zingerman; RUN: opt -O2 -mtriple=bpf-pc-linux -S -o - %s | FileCheck %s
2030b8cb1SEduard Zingerman;
3030b8cb1SEduard Zingerman; Check position of bpf-preserve-static-offset pass in the pipeline:
4030b8cb1SEduard Zingerman; preserve.static.offset call should be preserved long enough to allow
5030b8cb1SEduard Zingerman; introduction of getelementptr.and.load after loops unrolling.
6030b8cb1SEduard Zingerman;
7030b8cb1SEduard Zingerman; Source:
8030b8cb1SEduard Zingerman;    #define __ctx __attribute__((preserve_static_offset))
9030b8cb1SEduard Zingerman;
10030b8cb1SEduard Zingerman;    struct foo {
11030b8cb1SEduard Zingerman;      int a;
12030b8cb1SEduard Zingerman;      int b[4];
13030b8cb1SEduard Zingerman;    } __ctx;
14030b8cb1SEduard Zingerman;
15030b8cb1SEduard Zingerman;    extern void consume(int);
16030b8cb1SEduard Zingerman;
17030b8cb1SEduard Zingerman;    void bar(struct foo *p){
18030b8cb1SEduard Zingerman;      unsigned long i = 0;
19030b8cb1SEduard Zingerman;    #pragma clang loop unroll(full)
20030b8cb1SEduard Zingerman;      while (i < 2)
21030b8cb1SEduard Zingerman;        consume(p->b[i++]);
22030b8cb1SEduard Zingerman;    }
23030b8cb1SEduard Zingerman;
24030b8cb1SEduard Zingerman; Compilation flag:
25030b8cb1SEduard Zingerman;   clang -cc1 -O2 -triple bpf -S -emit-llvm -disable-llvm-passes -o - \
26030b8cb1SEduard Zingerman;       | opt -passes=function(sroa) -S -o -
27030b8cb1SEduard Zingerman
28030b8cb1SEduard Zingerman%struct.foo = type { i32, [4 x i32] }
29030b8cb1SEduard Zingerman
30030b8cb1SEduard Zingerman; Function Attrs: nounwind
31030b8cb1SEduard Zingermandefine dso_local void @bar(ptr noundef %p) #0 {
32030b8cb1SEduard Zingermanentry:
33030b8cb1SEduard Zingerman  br label %while.cond
34030b8cb1SEduard Zingerman
35030b8cb1SEduard Zingermanwhile.cond:                                       ; preds = %while.body, %entry
36030b8cb1SEduard Zingerman  %i.0 = phi i64 [ 0, %entry ], [ %inc, %while.body ]
37030b8cb1SEduard Zingerman  %cmp = icmp ult i64 %i.0, 2
38030b8cb1SEduard Zingerman  br i1 %cmp, label %while.body, label %while.end
39030b8cb1SEduard Zingerman
40030b8cb1SEduard Zingermanwhile.body:                                       ; preds = %while.cond
41030b8cb1SEduard Zingerman  %0 = call ptr @llvm.preserve.static.offset(ptr %p)
42030b8cb1SEduard Zingerman  %b = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1
43030b8cb1SEduard Zingerman  %inc = add i64 %i.0, 1
44030b8cb1SEduard Zingerman  %arrayidx = getelementptr inbounds [4 x i32], ptr %b, i64 0, i64 %i.0
45030b8cb1SEduard Zingerman  %1 = load i32, ptr %arrayidx, align 4, !tbaa !2
46030b8cb1SEduard Zingerman  call void @consume(i32 noundef %1)
47030b8cb1SEduard Zingerman  br label %while.cond, !llvm.loop !6
48030b8cb1SEduard Zingerman
49030b8cb1SEduard Zingermanwhile.end:                                        ; preds = %while.cond
50030b8cb1SEduard Zingerman  ret void
51030b8cb1SEduard Zingerman}
52030b8cb1SEduard Zingerman
53*29441e4fSNikita Popov; CHECK:      define dso_local void @bar(ptr noundef readonly captures(none) %[[p:.*]])
54030b8cb1SEduard Zingerman; CHECK:        %[[v1:.*]] = tail call i32 (ptr, i1, i8, i8, i8, i1, ...)
55030b8cb1SEduard Zingerman; CHECK-SAME:     @llvm.bpf.getelementptr.and.load.i32
5690ba3309SNikita Popov; CHECK-SAME:       (ptr readonly elementtype(i8) %[[p]],
5790ba3309SNikita Popov; CHECK-SAME:        i1 false, i8 0, i8 1, i8 2, i1 true, i64 immarg 4)
58030b8cb1SEduard Zingerman; CHECK-SAME:      #[[attrs:.*]], !tbaa
59030b8cb1SEduard Zingerman; CHECK-NEXT:   tail call void @consume(i32 noundef %[[v1]])
60030b8cb1SEduard Zingerman; CHECK-NEXT:   %[[v2:.*]] = tail call i32 (ptr, i1, i8, i8, i8, i1, ...)
61030b8cb1SEduard Zingerman; CHECK-SAME:     @llvm.bpf.getelementptr.and.load.i32
6290ba3309SNikita Popov; CHECK-SAME:       (ptr readonly elementtype(i8) %[[p]],
6390ba3309SNikita Popov; CHECK-SAME:        i1 false, i8 0, i8 1, i8 2, i1 true, i64 immarg 8)
64030b8cb1SEduard Zingerman; CHECK-SAME:      #[[attrs]], !tbaa
65030b8cb1SEduard Zingerman; CHECK-NEXT:   tail call void @consume(i32 noundef %[[v2]])
66030b8cb1SEduard Zingerman; CHECK:      attributes #[[attrs]] = { memory(argmem: read) }
67030b8cb1SEduard Zingerman
68030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
69030b8cb1SEduard Zingermandeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
70030b8cb1SEduard Zingerman
71030b8cb1SEduard Zingermandeclare void @consume(i32 noundef) #2
72030b8cb1SEduard Zingerman
73030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
74030b8cb1SEduard Zingermandeclare ptr @llvm.preserve.static.offset(ptr readnone) #3
75030b8cb1SEduard Zingerman
76030b8cb1SEduard Zingerman; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
77030b8cb1SEduard Zingermandeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
78030b8cb1SEduard Zingerman
79030b8cb1SEduard Zingermanattributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
80030b8cb1SEduard Zingermanattributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
81030b8cb1SEduard Zingermanattributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
82030b8cb1SEduard Zingermanattributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
83030b8cb1SEduard Zingerman
84030b8cb1SEduard Zingerman!llvm.module.flags = !{!0}
85030b8cb1SEduard Zingerman!llvm.ident = !{!1}
86030b8cb1SEduard Zingerman
87030b8cb1SEduard Zingerman!0 = !{i32 1, !"wchar_size", i32 4}
88030b8cb1SEduard Zingerman!1 = !{!"clang"}
89030b8cb1SEduard Zingerman!2 = !{!3, !3, i64 0}
90030b8cb1SEduard Zingerman!3 = !{!"int", !4, i64 0}
91030b8cb1SEduard Zingerman!4 = !{!"omnipotent char", !5, i64 0}
92030b8cb1SEduard Zingerman!5 = !{!"Simple C/C++ TBAA"}
93030b8cb1SEduard Zingerman!6 = distinct !{!6, !7, !8}
94030b8cb1SEduard Zingerman!7 = !{!"llvm.loop.mustprogress"}
95030b8cb1SEduard Zingerman!8 = !{!"llvm.loop.unroll.full"}
96