1 ; RUN: opt -passes=inline -S < %s | FileCheck %s
2 ; RUN: opt -passes='cgscc(inline)' -S < %s | FileCheck %s
5 ; Make sure doit is not inlined since the blockaddress is taken
6 ; which could be unsafe
7 ; CHECK: store ptr blockaddress(@doit, %here), ptr %pptr, align 8
9 @i = global i32 1, align 4
10 @ptr1 = common global ptr null, align 8
12 define void @doit(ptr nocapture %pptr, i32 %cond) nounwind uwtable {
14 %tobool = icmp eq i32 %cond, 0
15 br i1 %tobool, label %if.end, label %here
18 store ptr blockaddress(@doit, %here), ptr %pptr, align 8
25 define void @f(i32 %cond) nounwind uwtable {
27 call void @doit(ptr @ptr1, i32 %cond)
31 ; PR27233: We can inline @run into @init. Don't crash on it.
33 ; CHECK-LABEL: define void @init
34 ; CHECK: store ptr blockaddress(@run, %bb)
44 store ptr blockaddress(@run, %bb), ptr @run.bb, align 8
51 @run.bb = global [1 x ptr] zeroinitializer
53 ; Check that a function referenced by a global blockaddress wont be inlined,
54 ; even if it contains a callbr. We might be able to relax this in the future
55 ; as long as the global blockaddress is updated correctly.
56 @ba = internal global ptr blockaddress(@foo, %7), align 8
57 define internal i32 @foo(i32) {
58 %2 = alloca i32, align 4
59 %3 = alloca i32, align 4
60 store i32 %0, ptr %3, align 4
61 %4 = load i32, ptr %3, align 4
62 callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,!i,!i,~{dirflag},~{fpsr},~{flags}"(i32 %4) #1
63 to label %5 [label %7, label %6]
65 ; <label>:5: ; preds = %1
66 store i32 0, ptr %2, align 4
69 ; <label>:6: ; preds = %1
70 store i32 1, ptr %2, align 4
73 ; <label>:7: ; preds = %1
74 store i32 2, ptr %2, align 4
77 ; <label>:8: ; preds = %7, %6, %5
78 %9 = load i32, ptr %2, align 4
81 define dso_local i32 @bar() {
82 %1 = call i32 @foo(i32 0)
86 ; CHECK: define dso_local i32 @bar() {
87 ; CHECK: %1 = call i32 @foo(i32 0)
91 ; Triple check that even with a global aggregate whose member is a blockaddress,
92 ; we still don't inline referred to functions.
94 %struct.foo = type { ptr }
96 @my_foo = dso_local global %struct.foo { ptr blockaddress(@baz, %7) }
98 define internal i32 @baz(i32) {
99 %2 = alloca i32, align 4
100 %3 = alloca i32, align 4
101 store i32 %0, ptr %3, align 4
102 %4 = load i32, ptr %3, align 4
103 callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,!i,!i,~{dirflag},~{fpsr},~{flags}"(i32 %4) #1
104 to label %5 [label %7, label %6]
106 ; <label>:5: ; preds = %1
107 store i32 0, ptr %2, align 4
110 ; <label>:6: ; preds = %1
111 store i32 1, ptr %2, align 4
114 ; <label>:7: ; preds = %1
115 store i32 2, ptr %2, align 4
118 ; <label>:8: ; preds = %7, %6, %5
119 %9 = load i32, ptr %2, align 4
122 define dso_local i32 @quux() {
123 %1 = call i32 @baz(i32 0)
127 ; CHECK: define dso_local i32 @quux() {
128 ; CHECK: %1 = call i32 @baz(i32 0)