[PowerPC] Eliminate compares - add i32 sext/zext handling for SETULT/SETUGT
[llvm-core.git] / test / Transforms / Inline / byval.ll
blobaeb9964b2171e8e0a7d7bb80f2914532e9370457
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  {
10 entry:
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
15         ret void
18 declare i32 @printf(i8*, ...) nounwind 
20 define i32 @test1() nounwind  {
21 entry:
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 
28         ret i32 0
29 ; CHECK: @test1()
30 ; CHECK: %S1 = alloca %struct.ss
31 ; CHECK: %S = alloca %struct.ss
32 ; CHECK: call void @llvm.memcpy
33 ; CHECK: ret i32 0
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 {
40 entry:
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]
44         ret i32 %tmp2
47 define i32 @test2() nounwind  {
48 entry:
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 
55         ret i32 %X
56 ; CHECK: @test2()
57 ; CHECK: %S = alloca %struct.ss
58 ; CHECK-NOT: call void @llvm.memcpy
59 ; CHECK: ret i32
63 ; Inlining a byval with an explicit alignment needs to use *at least* that
64 ; alignment on the generated alloca.
65 ; PR8769
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!
70    ret void
73 define void @test3() nounwind  {
74 entry:
75         %S = alloca %struct.ss, align 1  ;; May not be aligned.
76         call void @f3( %struct.ss* byval align 64 %S) nounwind 
77         ret void
78 ; CHECK: @test3()
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)
83 ; CHECK: ret void
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)
93         ret i32 4
96 define i32 @test4() nounwind  {
97 entry:
98         %S = alloca %struct.ss, align 2         ; <%struct.ss*> [#uses=4]
99         %X = call i32 @f4( %struct.ss* byval align 64 %S ) nounwind 
100         ret i32 %X
101 ; CHECK: @test4()
102 ; CHECK: %S = alloca %struct.ss, align 64
103 ; CHECK-NOT: call void @llvm.memcpy
104 ; CHECK: call void @g3
105 ; CHECK: ret i32 4
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) {
114 entry:
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
119         ret void
122 define i32 @test5() {
123 entry:
124         tail call void @f5(%struct.S0* byval align 4 @b)
125         %0 = load i32, i32* @a, align 4
126         ret i32 %0
127 ; CHECK: @test5()
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