1 ; RUN: opt < %s -inline -S | FileCheck %s
3 ; Inlining a byval struct should cause an explicit copy into an alloca.
5 %struct.ss = type { i32, i64 }
6 @.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1]
8 define internal void @f(%struct.ss* byval %b) nounwind {
10 %tmp = getelementptr %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
11 %tmp1 = load i32* %tmp, align 4 ; <i32> [#uses=1]
12 %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
13 store i32 %tmp2, i32* %tmp, align 4
17 declare i32 @printf(i8*, ...) nounwind
19 define i32 @test1() nounwind {
21 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
22 %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
23 store i32 1, i32* %tmp1, align 8
24 %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
25 store i64 2, i64* %tmp4, align 4
26 call void @f( %struct.ss* byval %S ) nounwind
29 ; CHECK: %S1 = alloca %struct.ss
30 ; CHECK: %S = alloca %struct.ss
31 ; CHECK: call void @llvm.memcpy
35 ; Inlining a byval struct should NOT cause an explicit copy
36 ; into an alloca if the function is readonly
38 define internal i32 @f2(%struct.ss* byval %b) nounwind readonly {
40 %tmp = getelementptr %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
41 %tmp1 = load i32* %tmp, align 4 ; <i32> [#uses=1]
42 %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
46 define i32 @test2() nounwind {
48 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
49 %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
50 store i32 1, i32* %tmp1, align 8
51 %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
52 store i64 2, i64* %tmp4, align 4
53 %X = call i32 @f2( %struct.ss* byval %S ) nounwind
56 ; CHECK: %S = alloca %struct.ss
57 ; CHECK-NOT: call void @llvm.memcpy
62 ; Inlining a byval with an explicit alignment needs to use *at least* that
63 ; alignment on the generated alloca.
65 declare void @g3(%struct.ss* %p)
67 define internal void @f3(%struct.ss* byval align 64 %b) nounwind {
68 call void @g3(%struct.ss* %b) ;; Could make alignment assumptions!
72 define void @test3() nounwind {
74 %S = alloca %struct.ss, align 1 ;; May not be aligned.
75 call void @f3( %struct.ss* byval align 64 %S) nounwind
78 ; CHECK: %S1 = alloca %struct.ss, align 64
79 ; CHECK: %S = alloca %struct.ss
80 ; CHECK: call void @llvm.memcpy
81 ; CHECK: call void @g3(%struct.ss* %S1)
86 ; Inlining a byval struct should NOT cause an explicit copy
87 ; into an alloca if the function is readonly, but should increase an alloca's
88 ; alignment to satisfy an explicit alignment request.
90 define internal i32 @f4(%struct.ss* byval align 64 %b) nounwind readonly {
91 call void @g3(%struct.ss* %b)
95 define i32 @test4() nounwind {
97 %S = alloca %struct.ss, align 2 ; <%struct.ss*> [#uses=4]
98 %X = call i32 @f4( %struct.ss* byval align 64 %S ) nounwind
101 ; CHECK: %S = alloca %struct.ss, align 64
102 ; CHECK-NOT: call void @llvm.memcpy
103 ; CHECK: call void @g3
107 %struct.S0 = type { i32 }
109 @b = global %struct.S0 { i32 1 }, align 4
110 @a = common global i32 0, align 4
112 define internal void @f5(%struct.S0* byval nocapture readonly align 4 %p) {
114 store i32 0, i32* getelementptr inbounds (%struct.S0* @b, i64 0, i32 0), align 4
115 %f2 = getelementptr inbounds %struct.S0* %p, i64 0, i32 0
116 %0 = load i32* %f2, align 4
117 store i32 %0, i32* @a, align 4
121 define i32 @test5() {
123 tail call void @f5(%struct.S0* byval align 4 @b)
124 %0 = load i32* @a, align 4
127 ; CHECK: store i32 0, i32* getelementptr inbounds (%struct.S0* @b, i64 0, i32 0), align 4
128 ; CHECK-NOT: load i32* getelementptr inbounds (%struct.S0* @b, i64 0, i32 0), align 4