xref: /llvm-project/llvm/test/Transforms/Inline/inline_call.ll (revision 151602c7a9935558ca671b35359989b261045db0)
1; Check the optimizer doesn't crash at inlining the function top and all of its callees are inlined.
2; RUN: opt < %s -O3 -S | FileCheck %s
3
4define dso_local ptr @second(ptr %p) {
5entry:
6  %p.addr = alloca ptr, align 8
7  store ptr %p, ptr %p.addr, align 8
8  %tmp = load ptr, ptr %p.addr, align 8
9  %tmp1 = load ptr, ptr %tmp, align 8
10  ret ptr %tmp1
11}
12
13define dso_local void @top()  {
14entry:
15  ; CHECK: {{.*}} = {{.*}} call {{.*}} @ext
16  ; CHECK-NOT: {{.*}} = {{.*}} call {{.*}} @third
17  ; CHECK-NOT: {{.*}} = {{.*}} call {{.*}} @second
18  ; CHECK-NOT: {{.*}} = {{.*}} call {{.*}} @wrapper
19  %q = alloca ptr, align 8
20  store ptr @third, ptr %q, align 8
21  %tmp = call ptr @second(ptr %q)
22  ; The call to 'wrapper' here is to ensure that its function attributes
23  ; i.e., returning its parameter and having no side effect, will be decuded
24  ; before the next round of inlining happens to 'top' to expose the bug.
25  %call =  call ptr @wrapper(ptr %tmp)
26  ; The indirect call here is to confuse the alias analyzer so that
27  ; an incomplete graph will be built during the first round of inlining.
28  ; This allows the current function to be processed before the actual
29  ; callee, i.e., the function 'run', is processed. Once it's simplified to
30  ; a direct call, it also enables an additional round of inlining with all
31  ; function attributes deduced.
32  call void (...) %call()
33  ret void
34}
35
36define dso_local ptr @gen() {
37entry:
38  %call = call ptr (...) @ext()
39  ret ptr %call
40}
41
42declare dso_local ptr @ext(...)
43
44define dso_local ptr @wrapper(ptr %fn) {
45entry:
46  ret ptr %fn
47}
48
49define dso_local void @run(ptr %fn) {
50entry:
51  %fn.addr = alloca ptr, align 8
52  %f = alloca ptr, align 8
53  store ptr %fn, ptr %fn.addr, align 8
54  %tmp = load ptr, ptr %fn.addr, align 8
55  %call = call ptr @wrapper(ptr %tmp)
56  store ptr %call, ptr %f, align 8
57  %tmp1 = load ptr, ptr %f, align 8
58  call void (...) %tmp1()
59  ret void
60}
61
62define dso_local void @third() {
63entry:
64  %f = alloca ptr, align 8
65  %call = call ptr @gen()
66  store ptr %call, ptr %f, align 8
67  %tmp = load ptr, ptr %f, align 8
68  call void @run(ptr %tmp)
69  ret void
70}