Fix "make check" in Release by removing debug-only options from an 'opt' invocation.
[oota-llvm.git] / test / Transforms / ScalarRepl / vector_promote.ll
1 ; RUN: opt < %s -scalarrepl -S | FileCheck %s
2 target 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"
3 target triple = "x86_64-apple-darwin10.0.0"
4
5 define void @test1(<4 x float>* %F, float %f) {
6 entry:
7         %G = alloca <4 x float>, align 16               ; <<4 x float>*> [#uses=3]
8         %tmp = load <4 x float>* %F             ; <<4 x float>> [#uses=2]
9         %tmp3 = fadd <4 x float> %tmp, %tmp             ; <<4 x float>> [#uses=1]
10         store <4 x float> %tmp3, <4 x float>* %G
11         %G.upgrd.1 = getelementptr <4 x float>* %G, i32 0, i32 0                ; <float*> [#uses=1]
12         store float %f, float* %G.upgrd.1
13         %tmp4 = load <4 x float>* %G            ; <<4 x float>> [#uses=2]
14         %tmp6 = fadd <4 x float> %tmp4, %tmp4           ; <<4 x float>> [#uses=1]
15         store <4 x float> %tmp6, <4 x float>* %F
16         ret void
17 ; CHECK: @test1
18 ; CHECK-NOT: alloca
19 ; CHECK: %tmp = load <4 x float>* %F
20 ; CHECK: fadd <4 x float> %tmp, %tmp
21 ; CHECK-NEXT: insertelement <4 x float> %tmp3, float %f, i32 0
22 }
23
24 define void @test2(<4 x float>* %F, float %f) {
25 entry:
26         %G = alloca <4 x float>, align 16               ; <<4 x float>*> [#uses=3]
27         %tmp = load <4 x float>* %F             ; <<4 x float>> [#uses=2]
28         %tmp3 = fadd <4 x float> %tmp, %tmp             ; <<4 x float>> [#uses=1]
29         store <4 x float> %tmp3, <4 x float>* %G
30         %tmp.upgrd.2 = getelementptr <4 x float>* %G, i32 0, i32 2              ; <float*> [#uses=1]
31         store float %f, float* %tmp.upgrd.2
32         %tmp4 = load <4 x float>* %G            ; <<4 x float>> [#uses=2]
33         %tmp6 = fadd <4 x float> %tmp4, %tmp4           ; <<4 x float>> [#uses=1]
34         store <4 x float> %tmp6, <4 x float>* %F
35         ret void
36 ; CHECK: @test2
37 ; CHECK-NOT: alloca
38 ; CHECK: %tmp = load <4 x float>* %F
39 ; CHECK: fadd <4 x float> %tmp, %tmp
40 ; CHECK-NEXT: insertelement <4 x float> %tmp3, float %f, i32 2
41 }
42
43 define void @test3(<4 x float>* %F, float* %f) {
44 entry:
45         %G = alloca <4 x float>, align 16               ; <<4 x float>*> [#uses=2]
46         %tmp = load <4 x float>* %F             ; <<4 x float>> [#uses=2]
47         %tmp3 = fadd <4 x float> %tmp, %tmp             ; <<4 x float>> [#uses=1]
48         store <4 x float> %tmp3, <4 x float>* %G
49         %tmp.upgrd.3 = getelementptr <4 x float>* %G, i32 0, i32 2              ; <float*> [#uses=1]
50         %tmp.upgrd.4 = load float* %tmp.upgrd.3         ; <float> [#uses=1]
51         store float %tmp.upgrd.4, float* %f
52         ret void
53 ; CHECK: @test3
54 ; CHECK-NOT: alloca
55 ; CHECK: %tmp = load <4 x float>* %F
56 ; CHECK: fadd <4 x float> %tmp, %tmp
57 ; CHECK-NEXT: extractelement <4 x float> %tmp3, i32 2
58 }
59
60 define void @test4(<4 x float>* %F, float* %f) {
61 entry:
62         %G = alloca <4 x float>, align 16               ; <<4 x float>*> [#uses=2]
63         %tmp = load <4 x float>* %F             ; <<4 x float>> [#uses=2]
64         %tmp3 = fadd <4 x float> %tmp, %tmp             ; <<4 x float>> [#uses=1]
65         store <4 x float> %tmp3, <4 x float>* %G
66         %G.upgrd.5 = getelementptr <4 x float>* %G, i32 0, i32 0                ; <float*> [#uses=1]
67         %tmp.upgrd.6 = load float* %G.upgrd.5           ; <float> [#uses=1]
68         store float %tmp.upgrd.6, float* %f
69         ret void
70 ; CHECK: @test4
71 ; CHECK-NOT: alloca
72 ; CHECK: %tmp = load <4 x float>* %F
73 ; CHECK: fadd <4 x float> %tmp, %tmp
74 ; CHECK-NEXT: extractelement <4 x float> %tmp3, i32 0
75 }
76
77 define i32 @test5(float %X) {  ;; should turn into bitcast.
78         %X_addr = alloca [4 x float]
79         %X1 = getelementptr [4 x float]* %X_addr, i32 0, i32 2
80         store float %X, float* %X1
81         %a = bitcast float* %X1 to i32*
82         %tmp = load i32* %a
83         ret i32 %tmp
84 ; CHECK: @test5
85 ; CHECK-NEXT: bitcast float %X to i32
86 ; CHECK-NEXT: ret i32
87 }
88
89
90 define i64 @test6(<2 x float> %X) {
91         %X_addr = alloca <2 x float>
92         store <2 x float> %X, <2 x float>* %X_addr
93         %P = bitcast <2 x float>* %X_addr to i64*
94         %tmp = load i64* %P
95         ret i64 %tmp
96 ; CHECK: @test6
97 ; CHECK: bitcast <2 x float> %X to i64
98 ; CHECK: ret i64
99 }
100
101 define float @test7(<4 x float> %x) {
102         %a = alloca <4 x float>
103         store <4 x float> %x, <4 x float>* %a
104         %p = bitcast <4 x float>* %a to <2 x float>*
105         %b = load <2 x float>* %p
106         %q = getelementptr <4 x float>* %a, i32 0, i32 2
107         %c = load float* %q
108         ret float %c
109 ; CHECK: @test7
110 ; CHECK-NOT: alloca
111 ; CHECK: bitcast <4 x float> %x to <2 x double>
112 ; CHECK-NEXT: extractelement <2 x double>
113 ; CHECK-NEXT: bitcast double %tmp4 to <2 x float>
114 ; CHECK-NEXT: extractelement <4 x float>
115 }
116
117 define void @test8(<4 x float> %x, <2 x float> %y) {
118         %a = alloca <4 x float>
119         store <4 x float> %x, <4 x float>* %a
120         %p = bitcast <4 x float>* %a to <2 x float>*
121         store <2 x float> %y, <2 x float>* %p
122         ret void
123 ; CHECK: @test8
124 ; CHECK-NOT: alloca
125 ; CHECK: bitcast <4 x float> %x to <2 x double>
126 ; CHECK-NEXT: bitcast <2 x float> %y to double
127 ; CHECK-NEXT: insertelement <2 x double>
128 ; CHECK-NEXT: bitcast <2 x double> %tmp2 to <4 x float>
129 }
130
131 define i256 @test9(<4 x i256> %x) {
132         %a = alloca <4 x i256>
133         store <4 x i256> %x, <4 x i256>* %a
134         %p = bitcast <4 x i256>* %a to <2 x i256>*
135         %b = load <2 x i256>* %p
136         %q = getelementptr <4 x i256>* %a, i32 0, i32 2
137         %c = load i256* %q
138         ret i256 %c
139 ; CHECK: @test9
140 ; CHECK-NOT: alloca
141 ; CHECK: bitcast <4 x i256> %x to <2 x i512>
142 ; CHECK-NEXT: extractelement <2 x i512>
143 ; CHECK-NEXT: bitcast i512 %tmp4 to <2 x i256>
144 ; CHECK-NEXT: extractelement <4 x i256>
145 }
146
147 define void @test10(<4 x i256> %x, <2 x i256> %y) {
148         %a = alloca <4 x i256>
149         store <4 x i256> %x, <4 x i256>* %a
150         %p = bitcast <4 x i256>* %a to <2 x i256>*
151         store <2 x i256> %y, <2 x i256>* %p
152         ret void
153 ; CHECK: @test10
154 ; CHECK-NOT: alloca
155 ; CHECK: bitcast <4 x i256> %x to <2 x i512>
156 ; CHECK-NEXT: bitcast <2 x i256> %y to i512
157 ; CHECK-NEXT: insertelement <2 x i512>
158 ; CHECK-NEXT: bitcast <2 x i512> %tmp2 to <4 x i256>
159 }
160
161 %union.v = type { <2 x i64> }
162
163 define void @test11(<2 x i64> %x) {
164   %a = alloca %union.v
165   %p = getelementptr inbounds %union.v* %a, i32 0, i32 0
166   store <2 x i64> %x, <2 x i64>* %p, align 16
167   %q = getelementptr inbounds %union.v* %a, i32 0, i32 0
168   %r = bitcast <2 x i64>* %q to <4 x float>*
169   %b = load <4 x float>* %r, align 16
170   ret void
171 ; CHECK: @test11
172 ; CHECK-NOT: alloca
173 }
174
175 define void @test12() {
176 entry:
177   %a = alloca <64 x i8>, align 64
178   store <64 x i8> undef, <64 x i8>* %a, align 64
179   %p = bitcast <64 x i8>* %a to <16 x i8>*
180   %0 = load <16 x i8>* %p, align 64
181   store <16 x i8> undef, <16 x i8>* %p, align 64
182   %q = bitcast <16 x i8>* %p to <64 x i8>*
183   %1 = load <64 x i8>* %q, align 64
184   ret void
185 ; CHECK: @test12
186 ; CHECK-NOT: alloca
187 ; CHECK: extractelement <4 x i128>
188 ; CHECK: insertelement <4 x i128>
189 }
190
191 define float @test13(<4 x float> %x, <2 x i32> %y) {
192         %a = alloca <4 x float>
193         store <4 x float> %x, <4 x float>* %a
194         %p = bitcast <4 x float>* %a to <2 x float>*
195         %b = load <2 x float>* %p
196         %q = getelementptr <4 x float>* %a, i32 0, i32 2
197         %c = load float* %q
198         %r = bitcast <4 x float>* %a to <2 x i32>*
199         store <2 x i32> %y, <2 x i32>* %r
200         ret float %c
201 ; CHECK: @test13
202 ; CHECK-NOT: alloca
203 ; CHECK: bitcast <4 x float> %x to i128
204 }
205
206 define <3 x float> @test14(<3 x float> %x)  {
207 entry:
208   %x.addr = alloca <3 x float>, align 16
209   %r = alloca <3 x i32>, align 16
210   %extractVec = shufflevector <3 x float> %x, <3 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
211   %storetmp = bitcast <3 x float>* %x.addr to <4 x float>*
212   store <4 x float> %extractVec, <4 x float>* %storetmp, align 16
213   %tmp = load <3 x float>* %x.addr, align 16
214   %cmp = fcmp une <3 x float> %tmp, zeroinitializer
215   %sext = sext <3 x i1> %cmp to <3 x i32>
216   %and = and <3 x i32> <i32 1065353216, i32 1065353216, i32 1065353216>, %sext
217   %extractVec1 = shufflevector <3 x i32> %and, <3 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
218   %storetmp2 = bitcast <3 x i32>* %r to <4 x i32>*
219   store <4 x i32> %extractVec1, <4 x i32>* %storetmp2, align 16
220   %tmp3 = load <3 x i32>* %r, align 16
221   %0 = bitcast <3 x i32> %tmp3 to <3 x float>
222   %tmp4 = load <3 x float>* %x.addr, align 16
223   ret <3 x float> %tmp4
224 ; CHECK: @test14
225 ; CHECK-NOT: alloca
226 ; CHECK: shufflevector <4 x i32> %extractVec1, <4 x i32> undef, <3 x i32> <i32 0, i32 1, i32 2>
227 }
228
229 define void @test15(<3 x i64>* sret %agg.result, <3 x i64> %x, <3 x i64> %min) {
230 entry:
231   %x.addr = alloca <3 x i64>, align 32
232   %min.addr = alloca <3 x i64>, align 32
233   %extractVec = shufflevector <3 x i64> %x, <3 x i64> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
234   %storetmp = bitcast <3 x i64>* %x.addr to <4 x i64>*
235   store <4 x i64> %extractVec, <4 x i64>* %storetmp, align 32
236   %extractVec1 = shufflevector <3 x i64> %min, <3 x i64> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
237   %storetmp2 = bitcast <3 x i64>* %min.addr to <4 x i64>*
238   store <4 x i64> %extractVec1, <4 x i64>* %storetmp2, align 32
239   %tmp = load <3 x i64>* %x.addr
240   %tmp5 = extractelement <3 x i64> %tmp, i32 0
241   %tmp11 = insertelement <3 x i64> %tmp, i64 %tmp5, i32 0
242   store <3 x i64> %tmp11, <3 x i64>* %x.addr
243   %tmp30 = load <3 x i64>* %x.addr, align 32
244   store <3 x i64> %tmp30, <3 x i64>* %agg.result
245   ret void
246 ; CHECK: @test15
247 ; CHECK-NOT: alloca
248 ; CHECK: shufflevector <4 x i64> %tmpV2, <4 x i64> undef, <3 x i32> <i32 0, i32 1, i32 2>
249 }
250
251 define <4 x float> @test16(<4 x float> %x, i64 %y0, i64 %y1) {
252 entry:
253   %tmp8 = bitcast <4 x float> undef to <2 x double>
254   %tmp9 = bitcast i64 %y0 to double
255   %tmp10 = insertelement <2 x double> %tmp8, double %tmp9, i32 0
256   %tmp11 = bitcast <2 x double> %tmp10 to <4 x float>
257   %tmp3 = bitcast <4 x float> %tmp11 to <2 x double>
258   %tmp4 = bitcast i64 %y1 to double
259   %tmp5 = insertelement <2 x double> %tmp3, double %tmp4, i32 1
260   %tmp6 = bitcast <2 x double> %tmp5 to <4 x float>
261         ret <4 x float> %tmp6
262 ; CHECK: @test16
263 ; CHECK-NOT: alloca
264 ; CHECK: bitcast <4 x float> %tmp11 to <2 x double>
265 }