1; RUN: llc -march=sparc < %s | FileCheck %s -check-prefix=V8 -check-prefix=V8-BE
2; RUN: llc -march=sparcel < %s | FileCheck %s -check-prefix=V8 -check-prefix=V8-EL
3; RUN: llc -march=sparc -O0 < %s | FileCheck %s -check-prefix=V8-UNOPT
4; RUN: llc -march=sparc -mattr=v9 < %s | FileCheck %s -check-prefix=V9
5; RUN: llc -mtriple=sparc64-unknown-linux < %s | FileCheck %s -check-prefix=SPARC64
6; RUN: llc -march=sparc -mcpu=niagara4 < %s  | FileCheck %s -check-prefix=VIS3
7; RUN: llc -march=sparcv9 -mcpu=niagara4 < %s | FileCheck %s -check-prefix=VIS3-64
8
9; V8-LABEL:     test_neg:
10; V8:     call get_double
11; V8-BE:     fnegs %f0, %f0
12; V8-EL:     fnegs %f1, %f1
13
14; V8-UNOPT-LABEL:     test_neg:
15; V8-UNOPT:     fnegs
16; V8-UNOPT:     ! implicit-def
17; V8-UNOPT:     fmovs {{.+}}, %f0
18; V8-UNOPT:     fmovs {{.+}}, %f1
19
20; V9-LABEL:     test_neg:
21; V9:     fnegd %f0, %f0
22
23; SPARC64-LABEL: test_neg:
24; SPARC64:       fnegd %f0, %f0
25
26define double @test_neg() {
27entry:
28  %0 = tail call double @get_double()
29  %1 = fsub double -0.000000e+00, %0
30  ret double %1
31}
32
33; V8-LABEL:     test_abs:
34; V8-BE:     fabss %f0, %f0
35; V8-EL:     fabss %f1, %f1
36
37; V8-UNOPT-LABEL:     test_abs:
38; V8-UNOPT:     fabss
39; V8-UNOPT:     ! implicit-def
40; V8-UNOPT:     fmovs {{.+}}, %f0
41; V8-UNOPT:     fmovs {{.+}}, %f1
42
43; V9-LABEL:     test_abs:
44; V9:     fabsd %f0, %f0
45
46
47; SPARC64-LABEL:     test_abs:
48; SPARC64:     fabsd %f0, %f0
49
50define double @test_abs() {
51entry:
52  %0 = tail call double @get_double()
53  %1 = tail call double @llvm.fabs.f64(double %0)
54  ret double %1
55}
56
57declare double @get_double()
58declare double @llvm.fabs.f64(double) nounwind readonly
59
60; V8-LABEL:    test_v9_floatreg:
61; V8:          fsubd {{.+}}, {{.+}}, [[R:%f(((1|2)?(0|2|4|6|8))|30)]]
62; V8:          std [[R]], [%{{.+}}]
63; V8:          ldd [%{{.+}}], %f0
64; V8:          faddd {{.+}}, {{.+}}, {{.+}}
65
66; V9-LABEL:    test_v9_floatreg:
67; V9:          fsubd {{.+}}, {{.+}}, {{.+}}
68; V9:          faddd {{.+}}, {{.+}}, %f0
69
70; SPARC64-LABEL:    test_v9_floatreg:
71; SPARC64:          fsubd {{.+}}, {{.+}}, {{.+}}
72; SPARC64:          faddd {{.+}}, {{.+}}, %f0
73
74define double @test_v9_floatreg() {
75entry:
76  %0 = tail call double @get_double()
77  %1 = tail call double @get_double()
78  %2 = fsub double %0, %1
79  tail call void asm sideeffect "", "~{f0},~{f2},~{f3},~{f4},~{f5},~{f6},~{f7},~{f8},~{f9},~{f10},~{f11},~{f12},~{f13},~{f14},~{f15},~{f16},~{f17},~{f18},~{f19},~{f20},~{f21},~{f22},~{f23},~{f24},~{f25},~{f26},~{f27},~{f28},~{f29},~{f30},~{f31}"()
80  %3 = fadd double %2, %2
81  ret double %3
82}
83
84; V8-LABEL:    test_xtos_stox
85; V8:          call __floatdisf
86; V8:          call __fixsfdi
87
88; V9-LABEL:    test_xtos_stox
89; V9:          call __floatdisf
90; V9:          call __fixsfdi
91
92; SPARC64-LABEL:    test_xtos_stox
93; SPARC64:          fxtos
94; SPARC64:          fstox
95
96define void @test_xtos_stox(i64 %a, i64* %ptr0, float* %ptr1) {
97entry:
98  %0 = sitofp i64 %a to float
99  store float %0, float* %ptr1, align 8
100  %1 = fptosi float %0 to i64
101  store i64 %1, i64* %ptr0, align 8
102  ret void
103}
104
105; V8-LABEL:    test_itos_stoi
106; V8:          fitos
107; V8:          fstoi
108
109; V9-LABEL:    test_itos_stoi
110; V9:          fitos
111; V9:          fstoi
112
113; SPARC64-LABEL:    test_itos_stoi
114; SPARC64:          fitos
115; SPARC64:          fstoi
116
117define void @test_itos_stoi(i32 %a, i32* %ptr0, float* %ptr1) {
118entry:
119  %0 = sitofp i32 %a to float
120  store float %0, float* %ptr1, align 8
121  %1 = fptosi float %0 to i32
122  store i32 %1, i32* %ptr0, align 8
123  ret void
124}
125
126
127; V8-LABEL:    test_xtod_dtox
128; V8:          call __floatdidf
129; V8:          call __fixdfdi
130
131; V9-LABEL:    test_xtod_dtox
132; V9:          call __floatdidf
133; V9:          call __fixdfdi
134
135; SPARC64-LABEL:    test_xtod_dtox
136; SPARC64:          fxtod
137; SPARC64:          fdtox
138
139define void @test_xtod_dtox(i64 %a, i64* %ptr0, double* %ptr1) {
140entry:
141  %0 = sitofp i64 %a to double
142  store double %0, double* %ptr1, align 8
143  %1 = fptosi double %0 to i64
144  store i64 %1, i64* %ptr0, align 8
145  ret void
146}
147
148; V8-LABEL:    test_itod_dtoi
149; V8:          fitod
150; V8:          fdtoi
151
152; V9-LABEL:    test_itod_dtoi
153; V9:          fitod
154; V9:          fdtoi
155
156; SPARC64-LABEL:    test_itod_dtoi
157; SPARC64:          fitod
158; SPARC64:          fdtoi
159
160define void @test_itod_dtoi(i32 %a, double %b, i32* %ptr0, double* %ptr1) {
161entry:
162  %0 = sitofp i32 %a to double
163  store double %0, double* %ptr1, align 8
164  %1 = fptosi double %b to i32
165  store i32 %1, i32* %ptr0, align 8
166  ret void
167}
168
169; V8-LABEL:    test_uxtos_stoux
170; V8:          call __floatundisf
171; V8:          call __fixunssfdi
172
173; V9-LABEL:    test_uxtos_stoux
174; V9:          call __floatundisf
175; V9:          call __fixunssfdi
176
177; SPARC64-LABEL:   test_uxtos_stoux
178; SPARC64-NOT:     call __floatundisf
179; SPARC64-NOT:     call __fixunssfdi
180
181define void @test_uxtos_stoux(i64 %a, i64* %ptr0, float* %ptr1) {
182entry:
183  %0 = uitofp i64 %a to float
184  store float %0, float* %ptr1, align 8
185  %1 = fptoui float %0 to i64
186  store i64 %1, i64* %ptr0, align 8
187  ret void
188}
189
190; V8-LABEL:    test_utos_stou
191; V8:          fdtos
192; V8:          fstoi
193
194; V9-LABEL:    test_utos_stou
195; V9:          fdtos
196; V9:          fstoi
197
198; SPARC64-LABEL:    test_utos_stou
199; SPARC64:     fxtos
200; SPARC64:     fstoi
201
202define void @test_utos_stou(i32 %a, i32* %ptr0, float* %ptr1) {
203entry:
204  %0 = uitofp i32 %a to float
205  store float %0, float* %ptr1, align 8
206  %1 = fptoui float %0 to i32
207  store i32 %1, i32* %ptr0, align 8
208  ret void
209}
210
211
212; V8-LABEL:    test_uxtod_dtoux
213; V8:          call __floatundidf
214; V8:          call __fixunsdfdi
215
216; V9-LABEL:    test_uxtod_dtoux
217; V9:          call __floatundidf
218; V9:          call __fixunsdfdi
219
220; SPARC64-LABEL:    test_uxtod_dtoux
221; SPARC64-NOT:          call __floatundidf
222; SPARC64-NOT:          call __floatunsdfdi
223
224define void @test_uxtod_dtoux(i64 %a, i64* %ptr0, double* %ptr1) {
225entry:
226  %0 = uitofp i64 %a to double
227  store double %0, double* %ptr1, align 8
228  %1 = fptoui double %0 to i64
229  store i64 %1, i64* %ptr0, align 8
230  ret void
231}
232
233; V8-LABEL:    test_utod_dtou
234; V8-NOT:      fitod
235; V8:          fdtoi
236
237; V9-LABEL:    test_utod_dtou
238; V9-NOT:      fitod
239; V9:          fdtoi
240
241; SPARC64-LABEL:    test_utod_dtou
242; SPARC64-NOT:      fitod
243; SPARC64:          fdtoi
244
245; VIS3-64-LABEL:  test_utod_dtou
246; VIS3-64:        movxtod
247
248define void @test_utod_dtou(i32 %a, double %b, i32* %ptr0, double* %ptr1) {
249entry:
250  %0 = uitofp i32 %a to double
251  store double %0, double* %ptr1, align 8
252  %1 = fptoui double %b to i32
253  store i32 %1, i32* %ptr0, align 8
254  ret void
255}
256
257; V8-LABEL:    test_ustod
258; V8:          fitod
259
260; VIS3-LABEL:  test_ustod
261; VIS3:        movwtos
262
263define double @test_ustod(i16 zeroext) {
264  %2 = uitofp i16 %0 to double
265  ret double %2
266}
267
268; V8-LABEL:    test_ustos
269; V8:          fitos
270
271; VIS3-LABEL:  test_ustos
272; VIS3:        movwtos
273
274define float @test_ustos(i16 zeroext) {
275  %2 = uitofp i16 %0 to float
276  ret float %2
277}
278
279; check for movwtos used for bitcast
280;
281; VIS3-LABEL:  test_bitcast_utos
282; VIS3:movwtos
283
284define float @test_bitcast_utos(i32 ) {
285  %2 = bitcast i32 %0 to float
286  ret float %2
287}
288
289
290; check for movxtod used for bitcast
291;
292; VIS3-64-LABEL:  test_bitcast_uxtod
293; VIS3-64:movxtod
294
295define double @test_bitcast_uxtod(i64 ) {
296  %2 = bitcast i64 %0 to double
297  ret double %2
298}
299
300
301
302