89 lines · plain
1; RUN: opt -passes=argpromotion -mtriple=bpf-pc-linux -S %s | FileCheck %s2; Source:3; struct t {4; int a, b, c, d, e, f, g;5; };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;8; }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;11; }12; void init(void *);13; int bar(void) {14; struct t v1, v2, v3;15; init(&v1); init(&v2); init(&v3);16; return foo1(&v1, &v2, &v3) + foo2(&v1, &v2, &v3);17; }18; Compilation flag:19; clang -target bpf -O2 -S t.c -mllvm -print-before=argpromotion -mllvm -print-module-scope20; and then do some manual tailoring to remove some attributes/metadata which is not used21; by argpromotion pass.22 23%struct.t = type { i32, i32, i32, i32, i32, i32, i32 }24 25define i32 @bar() {26entry:27 %v1 = alloca %struct.t, align 428 %v2 = alloca %struct.t, align 429 %v3 = alloca %struct.t, align 430 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, %call136 ret i32 %add37}38 39declare void @init(ptr noundef)40 41define internal i32 @foo1(ptr nocapture noundef readonly %p1, ptr nocapture noundef readonly %p2, ptr nocapture noundef readonly %p3) {42entry:43 %0 = load i32, ptr %p1, align 444 %b = getelementptr inbounds %struct.t, ptr %p1, i64 0, i32 145 %1 = load i32, ptr %b, align 446 %add = add nsw i32 %1, %047 %c = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 248 %2 = load i32, ptr %c, align 449 %add1 = add nsw i32 %add, %250 %e = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 451 %3 = load i32, ptr %e, align 452 %add2 = add nsw i32 %add1, %353 %f = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 554 %4 = load i32, ptr %f, align 455 %add3 = add nsw i32 %add2, %456 %g = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 657 %5 = load i32, ptr %g, align 458 %add4 = add nsw i32 %add3, %559 ret i32 %add460}61 62; Without number-of-argument constraint, argpromotion will create a function signature with 6 arguments. Since63; bpf target only supports maximum 5 arguments, so no argpromotion here.64;65; CHECK: i32 @foo1(ptr noundef readonly captures(none) %p1, ptr noundef readonly captures(none) %p2, ptr noundef readonly captures(none) %p3)66 67define internal i32 @foo2(ptr noundef %p1, ptr noundef %p2, ptr noundef %p3) {68entry:69 %0 = load i32, ptr %p1, align 470 %b = getelementptr inbounds %struct.t, ptr %p1, i64 0, i32 171 %1 = load i32, ptr %b, align 472 %add = add nsw i32 %0, %173 %c = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 274 %2 = load i32, ptr %c, align 475 %add1 = add nsw i32 %add, %276 %e = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 477 %3 = load i32, ptr %e, align 478 %add2 = add nsw i32 %add1, %379 %f = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 580 %4 = load i32, ptr %f, align 481 %add3 = add nsw i32 %add2, %482 ret i32 %add383}84 85; Without number-of-argument constraint, argpromotion will create a function signature with 5 arguments, which equals86; the maximum number of argument permitted by bpf backend, so argpromotion result code does work.87;88; CHECK: i32 @foo2(i32 %p1.0.val, i32 %p1.4.val, i32 %p2.8.val, i32 %p2.16.val, i32 %p3.20.val)89