1 ; RUN: opt < %s -inline -S | FileCheck %s
2 ; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
4 ; Inlining a byval struct should cause an explicit copy into an alloca.
6 %struct.ss = type { i32, i64 }
7 @.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1]
9 define internal void @f(%struct.ss* byval %b) nounwind {
11 %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
12 %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1]
13 %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
14 store i32 %tmp2, i32* %tmp, align 4
18 declare i32 @printf(i8*, ...) nounwind
20 define i32 @test1() nounwind {
22 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
23 %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
24 store i32 1, i32* %tmp1, align 8
25 %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
26 store i64 2, i64* %tmp4, align 4
27 call void @f( %struct.ss* byval %S ) nounwind
30 ; CHECK: %S1 = alloca %struct.ss
31 ; CHECK: %S = alloca %struct.ss
32 ; CHECK: call void @llvm.memcpy
36 ; Inlining a byval struct should NOT cause an explicit copy
37 ; into an alloca if the function is readonly
39 define internal i32 @f2(%struct.ss* byval %b) nounwind readonly {
41 %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
42 %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1]
43 %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
47 define i32 @test2() nounwind {
49 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
50 %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
51 store i32 1, i32* %tmp1, align 8
52 %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
53 store i64 2, i64* %tmp4, align 4
54 %X = call i32 @f2( %struct.ss* byval %S ) nounwind
57 ; CHECK: %S = alloca %struct.ss
58 ; CHECK-NOT: call void @llvm.memcpy
63 ; Inlining a byval with an explicit alignment needs to use *at least* that
64 ; alignment on the generated alloca.
66 declare void @g3(%struct.ss* %p)
68 define internal void @f3(%struct.ss* byval align 64 %b) nounwind {
69 call void @g3(%struct.ss* %b) ;; Could make alignment assumptions!
73 define void @test3() nounwind {
75 %S = alloca %struct.ss, align 1 ;; May not be aligned.
76 call void @f3( %struct.ss* byval align 64 %S) nounwind
79 ; CHECK: %S1 = alloca %struct.ss, align 64
80 ; CHECK: %S = alloca %struct.ss
81 ; CHECK: call void @llvm.memcpy
82 ; CHECK: call void @g3(%struct.ss* %S1)
87 ; Inlining a byval struct should NOT cause an explicit copy
88 ; into an alloca if the function is readonly, but should increase an alloca's
89 ; alignment to satisfy an explicit alignment request.
91 define internal i32 @f4(%struct.ss* byval align 64 %b) nounwind readonly {
92 call void @g3(%struct.ss* %b)
96 define i32 @test4() nounwind {
98 %S = alloca %struct.ss, align 2 ; <%struct.ss*> [#uses=4]
99 %X = call i32 @f4( %struct.ss* byval align 64 %S ) nounwind
102 ; CHECK: %S = alloca %struct.ss, align 64
103 ; CHECK-NOT: call void @llvm.memcpy
104 ; CHECK: call void @g3
108 %struct.S0 = type { i32 }
110 @b = global %struct.S0 { i32 1 }, align 4
111 @a = common global i32 0, align 4
113 define internal void @f5(%struct.S0* byval nocapture readonly align 4 %p) {
115 store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4
116 %f2 = getelementptr inbounds %struct.S0, %struct.S0* %p, i64 0, i32 0
117 %0 = load i32, i32* %f2, align 4
118 store i32 %0, i32* @a, align 4
122 define i32 @test5() {
124 tail call void @f5(%struct.S0* byval align 4 @b)
125 %0 = load i32, i32* @a, align 4
128 ; CHECK: store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4
129 ; CHECK-NOT: load i32, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4