File: argpromotion.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (88 lines) | stat: -rw-r--r-- 3,552 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
; RUN: opt -passes=argpromotion -mtriple=bpf-pc-linux -S %s | FileCheck %s
; Source:
;  struct t {
;    int a, b, c, d, e, f, g;
;  };
;  __attribute__((noinline)) static int foo1(struct t *p1, struct t *p2, struct t *p3) {
;    return p1->a + p1->b + p2->c + p2->e + p3->f + p3->g;
;  }
;  __attribute__((noinline)) static int foo2(struct t *p1, struct t *p2, struct t *p3) {
;    return p1->a + p1->b + p2->c + p2->e + p3->f;
;  }
;  void init(void *);
;  int bar(void) {
;    struct t v1, v2, v3;
;    init(&v1); init(&v2); init(&v3);
;    return foo1(&v1, &v2, &v3) + foo2(&v1, &v2, &v3);
;  }
; Compilation flag:
;   clang -target bpf -O2 -S t.c -mllvm -print-before=argpromotion -mllvm -print-module-scope
;   and then do some manual tailoring to remove some attributes/metadata which is not used
;   by argpromotion pass.

%struct.t = type { i32, i32, i32, i32, i32, i32, i32 }

define i32 @bar() {
entry:
  %v1 = alloca %struct.t, align 4
  %v2 = alloca %struct.t, align 4
  %v3 = alloca %struct.t, align 4
  call void @init(ptr noundef nonnull %v1)
  call void @init(ptr noundef nonnull %v2)
  call void @init(ptr noundef nonnull %v3)
  %call = call fastcc i32 @foo1(ptr noundef nonnull %v1, ptr noundef nonnull %v2, ptr noundef nonnull %v3)
  %call1 = call fastcc i32 @foo2(ptr noundef nonnull %v1, ptr noundef nonnull %v2, ptr noundef nonnull %v3)
  %add = add nsw i32 %call, %call1
  ret i32 %add
}

declare void @init(ptr noundef)

define internal i32 @foo1(ptr nocapture noundef readonly %p1, ptr nocapture noundef readonly %p2, ptr nocapture noundef readonly %p3) {
entry:
  %0 = load i32, ptr %p1, align 4
  %b = getelementptr inbounds %struct.t, ptr %p1, i64 0, i32 1
  %1 = load i32, ptr %b, align 4
  %add = add nsw i32 %1, %0
  %c = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 2
  %2 = load i32, ptr %c, align 4
  %add1 = add nsw i32 %add, %2
  %e = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 4
  %3 = load i32, ptr %e, align 4
  %add2 = add nsw i32 %add1, %3
  %f = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 5
  %4 = load i32, ptr %f, align 4
  %add3 = add nsw i32 %add2, %4
  %g = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 6
  %5 = load i32, ptr %g, align 4
  %add4 = add nsw i32 %add3, %5
  ret i32 %add4
}

; Without number-of-argument constraint, argpromotion will create a function signature with 6 arguments. Since
; bpf target only supports maximum 5 arguments, so no argpromotion here.
;
; CHECK:  i32 @foo1(ptr nocapture noundef readonly %p1, ptr nocapture noundef readonly %p2, ptr nocapture noundef readonly %p3)

define internal i32 @foo2(ptr noundef %p1, ptr noundef %p2, ptr noundef %p3) {
entry:
  %0 = load i32, ptr %p1, align 4
  %b = getelementptr inbounds %struct.t, ptr %p1, i64 0, i32 1
  %1 = load i32, ptr %b, align 4
  %add = add nsw i32 %0, %1
  %c = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 2
  %2 = load i32, ptr %c, align 4
  %add1 = add nsw i32 %add, %2
  %e = getelementptr inbounds %struct.t, ptr %p2, i64 0, i32 4
  %3 = load i32, ptr %e, align 4
  %add2 = add nsw i32 %add1, %3
  %f = getelementptr inbounds %struct.t, ptr %p3, i64 0, i32 5
  %4 = load i32, ptr %f, align 4
  %add3 = add nsw i32 %add2, %4
  ret i32 %add3
}

; Without number-of-argument constraint, argpromotion will create a function signature with 5 arguments, which equals
; the maximum number of argument permitted by bpf backend, so argpromotion result code does work.
;
; CHECK:  i32 @foo2(i32 %p1.0.val, i32 %p1.4.val, i32 %p2.8.val, i32 %p2.16.val, i32 %p3.20.val)