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"
5 define void @test1(<4 x float>* %F, float %f) {
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
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
24 define void @test2(<4 x float>* %F, float %f) {
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
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
43 define void @test3(<4 x float>* %F, float* %f) {
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
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
60 define void @test4(<4 x float>* %F, float* %f) {
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
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
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*
85 ; CHECK-NEXT: bitcast float %X to i32
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*
97 ; CHECK: bitcast <2 x float> %X to i64
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
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>
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
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>
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
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>
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
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>
161 %union.v = type { <2 x i64> }
163 define void @test11(<2 x i64> %x) {
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
175 define void @test12() {
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
187 ; CHECK: extractelement <4 x i128>
188 ; CHECK: insertelement <4 x i128>
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
198 %r = bitcast <4 x float>* %a to <2 x i32>*
199 store <2 x i32> %y, <2 x i32>* %r
203 ; CHECK: bitcast <4 x float> %x to i128
206 define <3 x float> @test14(<3 x float> %x) {
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
226 ; CHECK: shufflevector <4 x i32> %extractVec1, <4 x i32> undef, <3 x i32> <i32 0, i32 1, i32 2>
229 define void @test15(<3 x i64>* sret %agg.result, <3 x i64> %x, <3 x i64> %min) {
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
248 ; CHECK: shufflevector <4 x i64> %tmpV2, <4 x i64> undef, <3 x i32> <i32 0, i32 1, i32 2>
251 define <4 x float> @test16(<4 x float> %x, i64 %y0, i64 %y1) {
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
264 ; CHECK: bitcast <4 x float> %tmp11 to <2 x double>