blob: 51ba8109b39b0df67f9df1361f04656dc3818a7a [file] [log] [blame]
Bob Wilson694a10e2011-01-13 17:45:08 +00001; RUN: opt < %s -scalarrepl -S | FileCheck %s
Chris Lattnerd2fa7812009-01-07 08:11:13 +00002; PR3290
Kenneth Uildriksb908f8a2009-11-03 15:29:06 +00003target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
Chris Lattnerd2fa7812009-01-07 08:11:13 +00004
5;; Store of integer to whole alloca struct.
6define i32 @test1(i64 %V) nounwind {
Bob Wilson694a10e2011-01-13 17:45:08 +00007; CHECK: test1
8; CHECK-NOT: alloca
Chris Lattnerd2fa7812009-01-07 08:11:13 +00009 %X = alloca {{i32, i32}}
10 %Y = bitcast {{i32,i32}}* %X to i64*
11 store i64 %V, i64* %Y
12
13 %A = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 0
14 %B = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 1
15 %a = load i32* %A
16 %b = load i32* %B
17 %c = add i32 %a, %b
18 ret i32 %c
19}
20
21;; Store of integer to whole struct/array alloca.
22define float @test2(i128 %V) nounwind {
Bob Wilson694a10e2011-01-13 17:45:08 +000023; CHECK: test2
24; CHECK-NOT: alloca
Chris Lattnerd2fa7812009-01-07 08:11:13 +000025 %X = alloca {[4 x float]}
26 %Y = bitcast {[4 x float]}* %X to i128*
27 store i128 %V, i128* %Y
28
29 %A = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 0
30 %B = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 3
31 %a = load float* %A
32 %b = load float* %B
Dan Gohmanae3a0be2009-06-04 22:49:04 +000033 %c = fadd float %a, %b
Chris Lattnerd2fa7812009-01-07 08:11:13 +000034 ret float %c
35}
36
Chris Lattner5ffe6ac2009-01-08 05:42:05 +000037;; Load of whole alloca struct as integer
38define i64 @test3(i32 %a, i32 %b) nounwind {
Bob Wilson694a10e2011-01-13 17:45:08 +000039; CHECK: test3
40; CHECK-NOT: alloca
Chris Lattner5ffe6ac2009-01-08 05:42:05 +000041 %X = alloca {{i32, i32}}
42
43 %A = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 0
44 %B = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 1
45 store i32 %a, i32* %A
46 store i32 %b, i32* %B
47
48 %Y = bitcast {{i32,i32}}* %X to i64*
49 %Z = load i64* %Y
50 ret i64 %Z
51}
52
53;; load of integer from whole struct/array alloca.
54define i128 @test4(float %a, float %b) nounwind {
Bob Wilson694a10e2011-01-13 17:45:08 +000055; CHECK: test4
56; CHECK-NOT: alloca
Chris Lattner5ffe6ac2009-01-08 05:42:05 +000057 %X = alloca {[4 x float]}
58 %A = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 0
59 %B = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 3
60 store float %a, float* %A
61 store float %b, float* %B
62
63 %Y = bitcast {[4 x float]}* %X to i128*
64 %V = load i128* %Y
65 ret i128 %V
66}
Bob Wilson694a10e2011-01-13 17:45:08 +000067
68;; If the elements of a struct or array alloca contain padding, SROA can still
69;; split up the alloca as long as there is no padding between the elements.
70%padded = type { i16, i8 }
Chris Lattner1afcace2011-07-09 17:41:24 +000071define void @test5([4 x %padded]* %p, [4 x %padded]* %q) {
Bob Wilson694a10e2011-01-13 17:45:08 +000072entry:
73; CHECK: test5
74; CHECK-NOT: i128
Chris Lattner1afcace2011-07-09 17:41:24 +000075 %var = alloca [4 x %padded], align 4
76 %vari8 = bitcast [4 x %padded]* %var to i8*
77 %pi8 = bitcast [4 x %padded]* %p to i8*
Bob Wilson704d1342011-01-13 17:45:11 +000078 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %vari8, i8* %pi8, i32 16, i32 4, i1 false)
Chris Lattner1afcace2011-07-09 17:41:24 +000079 %qi8 = bitcast [4 x %padded]* %q to i8*
Bob Wilson704d1342011-01-13 17:45:11 +000080 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %qi8, i8* %vari8, i32 16, i32 4, i1 false)
Bob Wilson694a10e2011-01-13 17:45:08 +000081 ret void
82}
83
Bob Wilson704d1342011-01-13 17:45:11 +000084;; Check that an array alloca can be split up when it is also accessed with
85;; a load or store as a homogeneous structure with the same element type and
86;; number of elements as the array.
87%homogeneous = type { <8 x i16>, <8 x i16>, <8 x i16> }
88%wrapped_array = type { [3 x <8 x i16>] }
89define void @test6(i8* %p, %wrapped_array* %arr) {
90entry:
91; CHECK: test6
92; CHECK: store <8 x i16>
93; CHECK: store <8 x i16>
94; CHECK: store <8 x i16>
95 %var = alloca %wrapped_array, align 16
96 %res = call %homogeneous @test6callee(i8* %p)
97 %varcast = bitcast %wrapped_array* %var to %homogeneous*
98 store %homogeneous %res, %homogeneous* %varcast
99 %tmp1 = bitcast %wrapped_array* %arr to i8*
100 %tmp2 = bitcast %wrapped_array* %var to i8*
101 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp1, i8* %tmp2, i32 48, i32 16, i1 false)
102 ret void
103}
104
105declare %homogeneous @test6callee(i8* nocapture) nounwind
106
107declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind