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
4 define dso_local ptr @second(ptr %p) {
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
13 define dso_local void @top() {
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()
36 define dso_local ptr @gen() {
38 %call = call ptr (...) @ext()
42 declare dso_local ptr @ext(...)
44 define dso_local ptr @wrapper(ptr %fn) {
49 define dso_local void @run(ptr %fn) {
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()
62 define dso_local void @third() {
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)