1 ; RUN: opt -passes=argpromotion -mtriple=bpf-pc-linux -S %s | FileCheck %s
4 ; int a, b, c, d, e, f, g;
6 ; __attribute__((noinline)) static int foo1(struct t *p1, struct t *p2, struct t *p3) {
7 ; return p1->a + p1->b + p2->c + p2->e + p3->f + p3->g;
9 ; __attribute__((noinline)) static int foo2(struct t *p1, struct t *p2, struct t *p3) {
10 ; return p1->a + p1->b + p2->c + p2->e + p3->f;
14 ; struct t v1, v2, v3;
15 ; init(&v1); init(&v2); init(&v3);
16 ; return foo1(&v1, &v2, &v3) + foo2(&v1, &v2, &v3);
19 ; clang -target bpf -O2 -S t.c -mllvm -print-before=argpromotion -mllvm -print-module-scope
20 ; and then do some manual tailoring to remove some attributes/metadata which is not used
21 ; by argpromotion pass.
23 %struct.t = type { i32, i32, i32, i32, i32, i32, i32 }
27 %v1 = alloca %struct.t, align 4
28 %v2 = alloca %struct.t, align 4
29 %v3 = alloca %struct.t, align 4
30 call void @init(ptr noundef nonnull %v1)
31 call void @init(ptr noundef nonnull %v2)
32 call void @init(ptr noundef nonnull %v3)
33 %call = call fastcc i32 @foo1(ptr noundef nonnull %v1, ptr noundef nonnull %v2, ptr noundef nonnull %v3)
34 %call1 = call fastcc i32 @foo2(ptr noundef nonnull %v1, ptr noundef nonnull %v2, ptr noundef nonnull %v3)
35 %add = add nsw i32 %call, %call1
39 declare void @init(ptr noundef)
41 define internal i32 @foo1(ptr nocapture noundef readonly %p1, ptr nocapture noundef readonly %p2, ptr nocapture noundef readonly %p3) {
43 %0 = load i32, ptr %p1, align 4
44 %b = getelementptr inbounds %struct.t, ptr %p1, i64 0, i32 1
45 %1 = load i32, ptr %b, align 4
46 %add = add nsw i32 %1, %0
47 %c = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 2
48 %2 = load i32, ptr %c, align 4
49 %add1 = add nsw i32 %add, %2
50 %e = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 4
51 %3 = load i32, ptr %e, align 4
52 %add2 = add nsw i32 %add1, %3
53 %f = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 5
54 %4 = load i32, ptr %f, align 4
55 %add3 = add nsw i32 %add2, %4
56 %g = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 6
57 %5 = load i32, ptr %g, align 4
58 %add4 = add nsw i32 %add3, %5
62 ; Without number-of-argument constraint, argpromotion will create a function signature with 6 arguments. Since
63 ; bpf target only supports maximum 5 arguments, so no argpromotion here.
65 ; CHECK: i32 @foo1(ptr nocapture noundef readonly %p1, ptr nocapture noundef readonly %p2, ptr nocapture noundef readonly %p3)
67 define internal i32 @foo2(ptr noundef %p1, ptr noundef %p2, ptr noundef %p3) {
69 %0 = load i32, ptr %p1, align 4
70 %b = getelementptr inbounds %struct.t, ptr %p1, i64 0, i32 1
71 %1 = load i32, ptr %b, align 4
72 %add = add nsw i32 %0, %1
73 %c = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 2
74 %2 = load i32, ptr %c, align 4
75 %add1 = add nsw i32 %add, %2
76 %e = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 4
77 %3 = load i32, ptr %e, align 4
78 %add2 = add nsw i32 %add1, %3
79 %f = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 5
80 %4 = load i32, ptr %f, align 4
81 %add3 = add nsw i32 %add2, %4
85 ; Without number-of-argument constraint, argpromotion will create a function signature with 5 arguments, which equals
86 ; the maximum number of argument permitted by bpf backend, so argpromotion result code does work.
88 ; CHECK: i32 @foo2(i32 %p1.0.val, i32 %p1.4.val, i32 %p2.8.val, i32 %p2.16.val, i32 %p3.20.val)