1 ; RUN: opt < %s -inline -S | FileCheck %s
2 ; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
4 ; The verifier does catch problems with inlining of byval arguments that has a
5 ; different address space compared to the alloca. But running instcombine
6 ; after inline used to trigger asserts unless we disallow such inlining.
7 ; RUN: opt < %s -inline -instcombine -disable-output 2>/dev/null
9 target datalayout = "p:32:32-p1:64:64-p2:16:16-n16:32:64"
11 ; Inlining a byval struct should cause an explicit copy into an alloca.
13 %struct.ss = type { i32, i64 }
14 @.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1]
16 define internal void @f(%struct.ss* byval(%struct.ss) %b) nounwind {
18 %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
19 %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1]
20 %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
21 store i32 %tmp2, i32* %tmp, align 4
25 declare i32 @printf(i8*, ...) nounwind
27 define i32 @test1() nounwind {
29 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
30 %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
31 store i32 1, i32* %tmp1, align 8
32 %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
33 store i64 2, i64* %tmp4, align 4
34 call void @f(%struct.ss* byval(%struct.ss) %S) nounwind
37 ; CHECK: %S1 = alloca %struct.ss
38 ; CHECK: %S = alloca %struct.ss
39 ; CHECK: call void @llvm.memcpy
43 ; Inlining a byval struct should NOT cause an explicit copy
44 ; into an alloca if the function is readonly
46 define internal i32 @f2(%struct.ss* byval(%struct.ss) %b) nounwind readonly {
48 %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
49 %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1]
50 %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
54 define i32 @test2() nounwind {
56 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
57 %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
58 store i32 1, i32* %tmp1, align 8
59 %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
60 store i64 2, i64* %tmp4, align 4
61 %X = call i32 @f2(%struct.ss* byval(%struct.ss) %S) nounwind
64 ; CHECK: %S = alloca %struct.ss
65 ; CHECK-NOT: call void @llvm.memcpy
70 ; Inlining a byval with an explicit alignment needs to use *at least* that
71 ; alignment on the generated alloca.
73 declare void @g3(%struct.ss* %p)
75 define internal void @f3(%struct.ss* byval(%struct.ss) align 64 %b) nounwind {
76 call void @g3(%struct.ss* %b) ;; Could make alignment assumptions!
80 define void @test3() nounwind {
82 %S = alloca %struct.ss, align 1 ;; May not be aligned.
83 call void @f3(%struct.ss* byval(%struct.ss) align 64 %S) nounwind
86 ; CHECK: %S1 = alloca %struct.ss, align 64
87 ; CHECK: %S = alloca %struct.ss
88 ; CHECK: call void @llvm.memcpy
89 ; CHECK: call void @g3(%struct.ss* %S1)
94 ; Inlining a byval struct should NOT cause an explicit copy
95 ; into an alloca if the function is readonly, but should increase an alloca's
96 ; alignment to satisfy an explicit alignment request.
98 define internal i32 @f4(%struct.ss* byval(%struct.ss) align 64 %b) nounwind readonly {
99 call void @g3(%struct.ss* %b)
103 define i32 @test4() nounwind {
105 %S = alloca %struct.ss, align 2 ; <%struct.ss*> [#uses=4]
106 %X = call i32 @f4(%struct.ss* byval(%struct.ss) align 64 %S) nounwind
109 ; CHECK: %S = alloca %struct.ss, align 64
110 ; CHECK-NOT: call void @llvm.memcpy
111 ; CHECK: call void @g3
115 %struct.S0 = type { i32 }
117 @b = global %struct.S0 { i32 1 }, align 4
118 @a = common global i32 0, align 4
120 define internal void @f5(%struct.S0* byval(%struct.S0) nocapture readonly align 4 %p) {
122 store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4
123 %f2 = getelementptr inbounds %struct.S0, %struct.S0* %p, i64 0, i32 0
124 %0 = load i32, i32* %f2, align 4
125 store i32 %0, i32* @a, align 4
129 define i32 @test5() {
131 tail call void @f5(%struct.S0* byval(%struct.S0) align 4 @b)
132 %0 = load i32, i32* @a, align 4
135 ; CHECK: store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4
136 ; CHECK-NOT: load i32, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4
139 ; Inlining a byval struct that is in a different address space compared to the
140 ; alloca address space is at the moment not expected. That would need
141 ; adjustments inside the inlined function since the address space attribute of
142 ; the inlined argument changes.
144 %struct.S1 = type { i32 }
146 @d = addrspace(1) global %struct.S1 { i32 1 }, align 4
147 @c = common addrspace(1) global i32 0, align 4
149 define internal void @f5_as1(%struct.S1 addrspace(1)* byval(%struct.S1) nocapture readonly align 4 %p) {
151 store i32 0, i32 addrspace(1)* getelementptr inbounds (%struct.S1, %struct.S1 addrspace(1)* @d, i64 0, i32 0), align 4
152 %f2 = getelementptr inbounds %struct.S1, %struct.S1 addrspace(1)* %p, i64 0, i32 0
153 %0 = load i32, i32 addrspace(1)* %f2, align 4
154 store i32 %0, i32 addrspace(1)* @c, align 4
158 define i32 @test5_as1() {
160 tail call void @f5_as1(%struct.S1 addrspace(1)* byval(%struct.S1) align 4 @d)
161 %0 = load i32, i32 addrspace(1)* @c, align 4
163 ; CHECK: @test5_as1()
164 ; CHECK: call void @f5_as1