Debian Codegraph @

llvm/test/CodeGen/PowerPC/fmf-propagation.ll

raw
1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; REQUIRES: asserts
3 ; RUN: llc < %s -mtriple=powerpc64le -debug-only=isel -o /dev/null 2>&1 | FileCheck %s --check-prefix=FMFDEBUG
4 ; RUN: llc < %s -mtriple=powerpc64le | FileCheck %s --check-prefix=FMF
5 ; RUN: llc < %s -mtriple=powerpc64le -debug-only=isel -o /dev/null 2>&1 -fp-contract=fast -enable-no-nans-fp-math | FileCheck %s --check-prefix=GLOBALDEBUG
6 ; RUN: llc < %s -mtriple=powerpc64le -fp-contract=fast -enable-no-nans-fp-math -enable-no-signed-zeros-fp-math | FileCheck %s --check-prefix=GLOBAL
7
8 ; Test FP transforms using instruction/node-level fast-math-flags.
9 ; We're also checking debug output to verify that FMF is propagated to the newly created nodes.
10 ; The run with the global unsafe param tests the pre-FMF behavior using regular instructions/nodes.
11
12 declare float @llvm.fma.f32(float, float, float)
13 declare float @llvm.sqrt.f32(float)
14
15 ; X * Y + Z --> fma(X, Y, Z)
16
17 ; contract bits in fmul is checked.
18
19 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_contract1:'
20 ; FMFDEBUG-NOT: fma contract {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
21 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_contract1:'
22
23 define float @fmul_fadd_contract1(float %x, float %y, float %z) {
24 ; FMF-LABEL: fmul_fadd_contract1:
25 ; FMF: # %bb.0:
26 ; FMF-NEXT: xsmulsp 0, 1, 2
27 ; FMF-NEXT: xsaddsp 1, 0, 3
28 ; FMF-NEXT: blr
29 ;
30 ; GLOBAL-LABEL: fmul_fadd_contract1:
31 ; GLOBAL: # %bb.0:
32 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
33 ; GLOBAL-NEXT: fmr 1, 3
34 ; GLOBAL-NEXT: blr
35 %mul = fmul float %x, %y
36 %add = fadd contract float %mul, %z
37 ret float %add
38 }
39
40 ; contract bits in fadd is also checked.
41
42 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_contract2:'
43 ; FMFDEBUG-NOT: fma contract {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
44 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_contract2:'
45
46 define float @fmul_fadd_contract2(float %x, float %y, float %z) {
47 ; FMF-LABEL: fmul_fadd_contract2:
48 ; FMF: # %bb.0:
49 ; FMF-NEXT: xsmulsp 0, 1, 2
50 ; FMF-NEXT: xsaddsp 1, 0, 3
51 ; FMF-NEXT: blr
52 ;
53 ; GLOBAL-LABEL: fmul_fadd_contract2:
54 ; GLOBAL: # %bb.0:
55 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
56 ; GLOBAL-NEXT: fmr 1, 3
57 ; GLOBAL-NEXT: blr
58 %mul = fmul contract float %x, %y
59 %add = fadd float %mul, %z
60 ret float %add
61 }
62
63 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_contract3:'
64 ; FMFDEBUG: fma contract {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
65 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_contract3:'
66
67 define float @fmul_fadd_contract3(float %x, float %y, float %z) {
68 ; FMF-LABEL: fmul_fadd_contract3:
69 ; FMF: # %bb.0:
70 ; FMF-NEXT: xsmaddasp 3, 1, 2
71 ; FMF-NEXT: fmr 1, 3
72 ; FMF-NEXT: blr
73 ;
74 ; GLOBAL-LABEL: fmul_fadd_contract3:
75 ; GLOBAL: # %bb.0:
76 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
77 ; GLOBAL-NEXT: fmr 1, 3
78 ; GLOBAL-NEXT: blr
79 %mul = fmul contract float %x, %y
80 %add = fadd contract float %mul, %z
81 ret float %add
82 }
83
84 ; Reassociation does NOT imply that FMA contraction is allowed.
85
86 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_reassoc1:'
87 ; FMFDEBUG-NOT: fma reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
88 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_reassoc1:'
89
90 define float @fmul_fadd_reassoc1(float %x, float %y, float %z) {
91 ; FMF-LABEL: fmul_fadd_reassoc1:
92 ; FMF: # %bb.0:
93 ; FMF-NEXT: xsmulsp 0, 1, 2
94 ; FMF-NEXT: xsaddsp 1, 0, 3
95 ; FMF-NEXT: blr
96 ;
97 ; GLOBAL-LABEL: fmul_fadd_reassoc1:
98 ; GLOBAL: # %bb.0:
99 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
100 ; GLOBAL-NEXT: fmr 1, 3
101 ; GLOBAL-NEXT: blr
102 %mul = fmul float %x, %y
103 %add = fadd reassoc float %mul, %z
104 ret float %add
105 }
106
107 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
108 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_reassoc2:'
109 ; FMFDEBUG-NOT: fma reassoc {{t[0-9]+}}, {{t[0-9]+}}
110 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_reassoc2:'
111
112 define float @fmul_fadd_reassoc2(float %x, float %y, float %z) {
113 ; FMF-LABEL: fmul_fadd_reassoc2:
114 ; FMF: # %bb.0:
115 ; FMF-NEXT: xsmulsp 0, 1, 2
116 ; FMF-NEXT: xsaddsp 1, 0, 3
117 ; FMF-NEXT: blr
118 ;
119 ; GLOBAL-LABEL: fmul_fadd_reassoc2:
120 ; GLOBAL: # %bb.0:
121 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
122 ; GLOBAL-NEXT: fmr 1, 3
123 ; GLOBAL-NEXT: blr
124 %mul = fmul reassoc float %x, %y
125 %add = fadd reassoc float %mul, %z
126 ret float %add
127 }
128
129 ; The fadd is now fully 'fast', but fmul is not yet.
130
131 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_fast1:'
132 ; FMFDEBUG-NOT: fma nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
133 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_fast1:'
134
135 define float @fmul_fadd_fast1(float %x, float %y, float %z) {
136 ; FMF-LABEL: fmul_fadd_fast1:
137 ; FMF: # %bb.0:
138 ; FMF-NEXT: xsmulsp 0, 1, 2
139 ; FMF-NEXT: xsaddsp 1, 0, 3
140 ; FMF-NEXT: blr
141 ;
142 ; GLOBAL-LABEL: fmul_fadd_fast1:
143 ; GLOBAL: # %bb.0:
144 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
145 ; GLOBAL-NEXT: fmr 1, 3
146 ; GLOBAL-NEXT: blr
147 %mul = fmul float %x, %y
148 %add = fadd fast float %mul, %z
149 ret float %add
150 }
151
152 ; This implies that contraction is allowed - the intermediate fmul result is now also flagged.
153
154 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_fast2:'
155 ; FMFDEBUG: fma nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
156 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_fast2:'
157
158 define float @fmul_fadd_fast2(float %x, float %y, float %z) {
159 ; FMF-LABEL: fmul_fadd_fast2:
160 ; FMF: # %bb.0:
161 ; FMF-NEXT: xsmaddasp 3, 1, 2
162 ; FMF-NEXT: fmr 1, 3
163 ; FMF-NEXT: blr
164 ;
165 ; GLOBAL-LABEL: fmul_fadd_fast2:
166 ; GLOBAL: # %bb.0:
167 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
168 ; GLOBAL-NEXT: fmr 1, 3
169 ; GLOBAL-NEXT: blr
170 %mul = fmul fast float %x, %y
171 %add = fadd fast float %mul, %z
172 ret float %add
173 }
174
175 ; fma(X, 7.0, X * 42.0) --> X * 49.0
176 ; This is the minimum FMF needed for this transform - the FMA allows reassociation.
177
178 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc1:'
179 ; FMFDEBUG: fmul reassoc {{t[0-9]+}},
180 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc1:'
181
182 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc1:'
183 ; GLOBALDEBUG: fmul reassoc {{t[0-9]+}}
184 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc1:'
185
186 define float @fmul_fma_reassoc1(float %x) {
187 ; FMF-LABEL: fmul_fma_reassoc1:
188 ; FMF: # %bb.0:
189 ; FMF-NEXT: addis 3, 2, .LCPI7_0@toc@ha
190 ; FMF-NEXT: lfs 0, .LCPI7_0@toc@l(3)
191 ; FMF-NEXT: xsmulsp 1, 1, 0
192 ; FMF-NEXT: blr
193 ;
194 ; GLOBAL-LABEL: fmul_fma_reassoc1:
195 ; GLOBAL: # %bb.0:
196 ; GLOBAL-NEXT: addis 3, 2, .LCPI7_0@toc@ha
197 ; GLOBAL-NEXT: lfs 0, .LCPI7_0@toc@l(3)
198 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
199 ; GLOBAL-NEXT: blr
200 %mul = fmul float %x, 42.0
201 %fma = call reassoc float @llvm.fma.f32(float %x, float 7.0, float %mul)
202 ret float %fma
203 }
204
205 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
206
207 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc2:'
208 ; FMFDEBUG: fmul reassoc {{t[0-9]+}}
209 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc2:'
210
211 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc2:'
212 ; GLOBALDEBUG: fmul reassoc {{t[0-9]+}}
213 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc2:'
214
215 define float @fmul_fma_reassoc2(float %x) {
216 ; FMF-LABEL: fmul_fma_reassoc2:
217 ; FMF: # %bb.0:
218 ; FMF-NEXT: addis 3, 2, .LCPI8_0@toc@ha
219 ; FMF-NEXT: lfs 0, .LCPI8_0@toc@l(3)
220 ; FMF-NEXT: xsmulsp 1, 1, 0
221 ; FMF-NEXT: blr
222 ;
223 ; GLOBAL-LABEL: fmul_fma_reassoc2:
224 ; GLOBAL: # %bb.0:
225 ; GLOBAL-NEXT: addis 3, 2, .LCPI8_0@toc@ha
226 ; GLOBAL-NEXT: lfs 0, .LCPI8_0@toc@l(3)
227 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
228 ; GLOBAL-NEXT: blr
229 %mul = fmul reassoc float %x, 42.0
230 %fma = call reassoc float @llvm.fma.f32(float %x, float 7.0, float %mul)
231 ret float %fma
232 }
233
234 ; The FMA is now fully 'fast'. This implies that reassociation is allowed.
235
236 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast1:'
237 ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
238 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast1:'
239
240 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast1:'
241 ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
242 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast1:'
243
244 define float @fmul_fma_fast1(float %x) {
245 ; FMF-LABEL: fmul_fma_fast1:
246 ; FMF: # %bb.0:
247 ; FMF-NEXT: addis 3, 2, .LCPI9_0@toc@ha
248 ; FMF-NEXT: lfs 0, .LCPI9_0@toc@l(3)
249 ; FMF-NEXT: xsmulsp 1, 1, 0
250 ; FMF-NEXT: blr
251 ;
252 ; GLOBAL-LABEL: fmul_fma_fast1:
253 ; GLOBAL: # %bb.0:
254 ; GLOBAL-NEXT: addis 3, 2, .LCPI9_0@toc@ha
255 ; GLOBAL-NEXT: lfs 0, .LCPI9_0@toc@l(3)
256 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
257 ; GLOBAL-NEXT: blr
258 %mul = fmul float %x, 42.0
259 %fma = call fast float @llvm.fma.f32(float %x, float 7.0, float %mul)
260 ret float %fma
261 }
262
263 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
264
265 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast2:'
266 ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
267 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast2:'
268
269 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast2:'
270 ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
271 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast2:'
272
273 define float @fmul_fma_fast2(float %x) {
274 ; FMF-LABEL: fmul_fma_fast2:
275 ; FMF: # %bb.0:
276 ; FMF-NEXT: addis 3, 2, .LCPI10_0@toc@ha
277 ; FMF-NEXT: lfs 0, .LCPI10_0@toc@l(3)
278 ; FMF-NEXT: xsmulsp 1, 1, 0
279 ; FMF-NEXT: blr
280 ;
281 ; GLOBAL-LABEL: fmul_fma_fast2:
282 ; GLOBAL: # %bb.0:
283 ; GLOBAL-NEXT: addis 3, 2, .LCPI10_0@toc@ha
284 ; GLOBAL-NEXT: lfs 0, .LCPI10_0@toc@l(3)
285 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
286 ; GLOBAL-NEXT: blr
287 %mul = fmul fast float %x, 42.0
288 %fma = call fast float @llvm.fma.f32(float %x, float 7.0, float %mul)
289 ret float %fma
290 }
291
292 ; Reduced precision for sqrt is allowed - should use estimate and NR iterations.
293
294 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn_ieee:'
295 ; FMFDEBUG: fmul ninf afn {{t[0-9]+}}
296 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn_ieee:'
297
298 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn_ieee:'
299 ; GLOBALDEBUG: fmul ninf afn {{t[0-9]+}}
300 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn_ieee:'
301
302 define float @sqrt_afn_ieee(float %x) #0 {
303 ; FMF-LABEL: sqrt_afn_ieee:
304 ; FMF: # %bb.0:
305 ; FMF-NEXT: addis 3, 2, .LCPI11_1@toc@ha
306 ; FMF-NEXT: xsabsdp 0, 1
307 ; FMF-NEXT: lfs 2, .LCPI11_1@toc@l(3)
308 ; FMF-NEXT: fcmpu 0, 0, 2
309 ; FMF-NEXT: xxlxor 0, 0, 0
310 ; FMF-NEXT: blt 0, .LBB11_2
311 ; FMF-NEXT: # %bb.1:
312 ; FMF-NEXT: xsrsqrtesp 2, 1
313 ; FMF-NEXT: addis 3, 2, .LCPI11_0@toc@ha
314 ; FMF-NEXT: vspltisw 2, -3
315 ; FMF-NEXT: lfs 0, .LCPI11_0@toc@l(3)
316 ; FMF-NEXT: xsmulsp 1, 1, 2
317 ; FMF-NEXT: xsmulsp 0, 1, 0
318 ; FMF-NEXT: xsmulsp 1, 1, 2
319 ; FMF-NEXT: xvcvsxwdp 2, 34
320 ; FMF-NEXT: xsaddsp 1, 1, 2
321 ; FMF-NEXT: xsmulsp 0, 0, 1
322 ; FMF-NEXT: .LBB11_2:
323 ; FMF-NEXT: fmr 1, 0
324 ; FMF-NEXT: blr
325 ;
326 ; GLOBAL-LABEL: sqrt_afn_ieee:
327 ; GLOBAL: # %bb.0:
328 ; GLOBAL-NEXT: xsrsqrtesp 0, 1
329 ; GLOBAL-NEXT: vspltisw 2, -3
330 ; GLOBAL-NEXT: addis 3, 2, .LCPI11_0@toc@ha
331 ; GLOBAL-NEXT: xvcvsxwdp 3, 34
332 ; GLOBAL-NEXT: xsmulsp 2, 1, 0
333 ; GLOBAL-NEXT: xsabsdp 1, 1
334 ; GLOBAL-NEXT: xsmaddasp 3, 2, 0
335 ; GLOBAL-NEXT: lfs 0, .LCPI11_0@toc@l(3)
336 ; GLOBAL-NEXT: addis 3, 2, .LCPI11_1@toc@ha
337 ; GLOBAL-NEXT: xsmulsp 0, 2, 0
338 ; GLOBAL-NEXT: lfs 2, .LCPI11_1@toc@l(3)
339 ; GLOBAL-NEXT: xssubsp 1, 1, 2
340 ; GLOBAL-NEXT: xxlxor 2, 2, 2
341 ; GLOBAL-NEXT: xsmulsp 0, 0, 3
342 ; GLOBAL-NEXT: fsel 1, 1, 0, 2
343 ; GLOBAL-NEXT: blr
344 %rt = call afn ninf float @llvm.sqrt.f32(float %x)
345 ret float %rt
346 }
347
348 define float @sqrt_afn_ieee_inf(float %x) #0 {
349 ; FMF-LABEL: sqrt_afn_ieee_inf:
350 ; FMF: # %bb.0:
351 ; FMF-NEXT: xssqrtsp 1, 1
352 ; FMF-NEXT: blr
353 ;
354 ; GLOBAL-LABEL: sqrt_afn_ieee_inf:
355 ; GLOBAL: # %bb.0:
356 ; GLOBAL-NEXT: xssqrtsp 1, 1
357 ; GLOBAL-NEXT: blr
358 %rt = call afn float @llvm.sqrt.f32(float %x)
359 ret float %rt
360 }
361
362 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn_preserve_sign:'
363 ; FMFDEBUG: fmul ninf afn {{t[0-9]+}}
364 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn_preserve_sign:'
365
366 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn_preserve_sign:'
367 ; GLOBALDEBUG: fmul ninf afn {{t[0-9]+}}
368 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn_preserve_sign:'
369
370 define float @sqrt_afn_preserve_sign(float %x) #1 {
371 ; FMF-LABEL: sqrt_afn_preserve_sign:
372 ; FMF: # %bb.0:
373 ; FMF-NEXT: xxlxor 0, 0, 0
374 ; FMF-NEXT: fcmpu 0, 1, 0
375 ; FMF-NEXT: beq 0, .LBB13_2
376 ; FMF-NEXT: # %bb.1:
377 ; FMF-NEXT: xsrsqrtesp 0, 1
378 ; FMF-NEXT: addis 3, 2, .LCPI13_0@toc@ha
379 ; FMF-NEXT: vspltisw 2, -3
380 ; FMF-NEXT: lfs 2, .LCPI13_0@toc@l(3)
381 ; FMF-NEXT: xsmulsp 1, 1, 0
382 ; FMF-NEXT: xsmulsp 2, 1, 2
383 ; FMF-NEXT: xsmulsp 0, 1, 0
384 ; FMF-NEXT: xvcvsxwdp 1, 34
385 ; FMF-NEXT: xsaddsp 0, 0, 1
386 ; FMF-NEXT: xsmulsp 0, 2, 0
387 ; FMF-NEXT: .LBB13_2:
388 ; FMF-NEXT: fmr 1, 0
389 ; FMF-NEXT: blr
390 ;
391 ; GLOBAL-LABEL: sqrt_afn_preserve_sign:
392 ; GLOBAL: # %bb.0:
393 ; GLOBAL-NEXT: xsrsqrtesp 0, 1
394 ; GLOBAL-NEXT: vspltisw 2, -3
395 ; GLOBAL-NEXT: addis 3, 2, .LCPI13_0@toc@ha
396 ; GLOBAL-NEXT: xvcvsxwdp 3, 34
397 ; GLOBAL-NEXT: xsmulsp 2, 1, 0
398 ; GLOBAL-NEXT: xsmaddasp 3, 2, 0
399 ; GLOBAL-NEXT: lfs 0, .LCPI13_0@toc@l(3)
400 ; GLOBAL-NEXT: xsmulsp 0, 2, 0
401 ; GLOBAL-NEXT: xxlxor 2, 2, 2
402 ; GLOBAL-NEXT: xsmulsp 0, 0, 3
403 ; GLOBAL-NEXT: fsel 2, 1, 2, 0
404 ; GLOBAL-NEXT: xsnegdp 1, 1
405 ; GLOBAL-NEXT: fsel 1, 1, 2, 0
406 ; GLOBAL-NEXT: blr
407 %rt = call afn ninf float @llvm.sqrt.f32(float %x)
408 ret float %rt
409 }
410
411 define float @sqrt_afn_preserve_sign_inf(float %x) #1 {
412 ; FMF-LABEL: sqrt_afn_preserve_sign_inf:
413 ; FMF: # %bb.0:
414 ; FMF-NEXT: xssqrtsp 1, 1
415 ; FMF-NEXT: blr
416 ;
417 ; GLOBAL-LABEL: sqrt_afn_preserve_sign_inf:
418 ; GLOBAL: # %bb.0:
419 ; GLOBAL-NEXT: xssqrtsp 1, 1
420 ; GLOBAL-NEXT: blr
421 %rt = call afn float @llvm.sqrt.f32(float %x)
422 ret float %rt
423 }
424
425 ; The call is now fully 'fast'. This implies that approximation is allowed.
426
427 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast_ieee:'
428 ; FMFDEBUG: fmul ninf contract afn reassoc {{t[0-9]+}}
429 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast_ieee:'
430
431 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast_ieee:'
432 ; GLOBALDEBUG: fmul ninf contract afn reassoc {{t[0-9]+}}
433 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast_ieee:'
434
435 define float @sqrt_fast_ieee(float %x) #0 {
436 ; FMF-LABEL: sqrt_fast_ieee:
437 ; FMF: # %bb.0:
438 ; FMF-NEXT: addis 3, 2, .LCPI15_1@toc@ha
439 ; FMF-NEXT: xsabsdp 0, 1
440 ; FMF-NEXT: lfs 2, .LCPI15_1@toc@l(3)
441 ; FMF-NEXT: fcmpu 0, 0, 2
442 ; FMF-NEXT: xxlxor 0, 0, 0
443 ; FMF-NEXT: blt 0, .LBB15_2
444 ; FMF-NEXT: # %bb.1:
445 ; FMF-NEXT: xsrsqrtesp 0, 1
446 ; FMF-NEXT: vspltisw 2, -3
447 ; FMF-NEXT: addis 3, 2, .LCPI15_0@toc@ha
448 ; FMF-NEXT: xvcvsxwdp 2, 34
449 ; FMF-NEXT: xsmulsp 1, 1, 0
450 ; FMF-NEXT: xsmaddasp 2, 1, 0
451 ; FMF-NEXT: lfs 0, .LCPI15_0@toc@l(3)
452 ; FMF-NEXT: xsmulsp 0, 1, 0
453 ; FMF-NEXT: xsmulsp 0, 0, 2
454 ; FMF-NEXT: .LBB15_2:
455 ; FMF-NEXT: fmr 1, 0
456 ; FMF-NEXT: blr
457 ;
458 ; GLOBAL-LABEL: sqrt_fast_ieee:
459 ; GLOBAL: # %bb.0:
460 ; GLOBAL-NEXT: xsrsqrtesp 0, 1
461 ; GLOBAL-NEXT: vspltisw 2, -3
462 ; GLOBAL-NEXT: addis 3, 2, .LCPI15_0@toc@ha
463 ; GLOBAL-NEXT: xvcvsxwdp 3, 34
464 ; GLOBAL-NEXT: xsmulsp 2, 1, 0
465 ; GLOBAL-NEXT: xsabsdp 1, 1
466 ; GLOBAL-NEXT: xsmaddasp 3, 2, 0
467 ; GLOBAL-NEXT: lfs 0, .LCPI15_0@toc@l(3)
468 ; GLOBAL-NEXT: addis 3, 2, .LCPI15_1@toc@ha
469 ; GLOBAL-NEXT: xsmulsp 0, 2, 0
470 ; GLOBAL-NEXT: lfs 2, .LCPI15_1@toc@l(3)
471 ; GLOBAL-NEXT: xssubsp 1, 1, 2
472 ; GLOBAL-NEXT: xxlxor 2, 2, 2
473 ; GLOBAL-NEXT: xsmulsp 0, 0, 3
474 ; GLOBAL-NEXT: fsel 1, 1, 0, 2
475 ; GLOBAL-NEXT: blr
476 %rt = call contract reassoc afn ninf float @llvm.sqrt.f32(float %x)
477 ret float %rt
478 }
479
480 ; The call is now fully 'fast'. This implies that approximation is allowed.
481
482 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast_preserve_sign:'
483 ; FMFDEBUG: fmul ninf contract afn reassoc {{t[0-9]+}}
484 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast_preserve_sign:'
485
486 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast_preserve_sign:'
487 ; GLOBALDEBUG: fmul ninf contract afn reassoc {{t[0-9]+}}
488 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast_preserve_sign:'
489
490 define float @sqrt_fast_preserve_sign(float %x) #1 {
491 ; FMF-LABEL: sqrt_fast_preserve_sign:
492 ; FMF: # %bb.0:
493 ; FMF-NEXT: xxlxor 0, 0, 0
494 ; FMF-NEXT: fcmpu 0, 1, 0
495 ; FMF-NEXT: beq 0, .LBB16_2
496 ; FMF-NEXT: # %bb.1:
497 ; FMF-NEXT: xsrsqrtesp 0, 1
498 ; FMF-NEXT: vspltisw 2, -3
499 ; FMF-NEXT: addis 3, 2, .LCPI16_0@toc@ha
500 ; FMF-NEXT: xvcvsxwdp 2, 34
501 ; FMF-NEXT: xsmulsp 1, 1, 0
502 ; FMF-NEXT: xsmaddasp 2, 1, 0
503 ; FMF-NEXT: lfs 0, .LCPI16_0@toc@l(3)
504 ; FMF-NEXT: xsmulsp 0, 1, 0
505 ; FMF-NEXT: xsmulsp 0, 0, 2
506 ; FMF-NEXT: .LBB16_2:
507 ; FMF-NEXT: fmr 1, 0
508 ; FMF-NEXT: blr
509 ;
510 ; GLOBAL-LABEL: sqrt_fast_preserve_sign:
511 ; GLOBAL: # %bb.0:
512 ; GLOBAL-NEXT: xsrsqrtesp 0, 1
513 ; GLOBAL-NEXT: vspltisw 2, -3
514 ; GLOBAL-NEXT: addis 3, 2, .LCPI16_0@toc@ha
515 ; GLOBAL-NEXT: xvcvsxwdp 3, 34
516 ; GLOBAL-NEXT: xsmulsp 2, 1, 0
517 ; GLOBAL-NEXT: xsmaddasp 3, 2, 0
518 ; GLOBAL-NEXT: lfs 0, .LCPI16_0@toc@l(3)
519 ; GLOBAL-NEXT: xsmulsp 0, 2, 0
520 ; GLOBAL-NEXT: xxlxor 2, 2, 2
521 ; GLOBAL-NEXT: xsmulsp 0, 0, 3
522 ; GLOBAL-NEXT: fsel 2, 1, 2, 0
523 ; GLOBAL-NEXT: xsnegdp 1, 1
524 ; GLOBAL-NEXT: fsel 1, 1, 2, 0
525 ; GLOBAL-NEXT: blr
526 %rt = call contract reassoc ninf afn float @llvm.sqrt.f32(float %x)
527 ret float %rt
528 }
529
530 ; fcmp can have fast-math-flags.
531
532 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:'
533 ; FMFDEBUG: select_cc nnan {{t[0-9]+}}
534 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:'
535
536 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:'
537 ; GLOBALDEBUG: select_cc nnan {{t[0-9]+}}
538 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:'
539
540 define double @fcmp_nnan(double %a, double %y, double %z) {
541 ; FMF-LABEL: fcmp_nnan:
542 ; FMF: # %bb.0:
543 ; FMF-NEXT: xxlxor 0, 0, 0
544 ; FMF-NEXT: xscmpudp 0, 1, 0
545 ; FMF-NEXT: blt 0, .LBB17_2
546 ; FMF-NEXT: # %bb.1:
547 ; FMF-NEXT: fmr 3, 2
548 ; FMF-NEXT: .LBB17_2:
549 ; FMF-NEXT: fmr 1, 3
550 ; FMF-NEXT: blr
551 ;
552 ; GLOBAL-LABEL: fcmp_nnan:
553 ; GLOBAL: # %bb.0:
554 ; GLOBAL-NEXT: xxlxor 0, 0, 0
555 ; GLOBAL-NEXT: xscmpudp 0, 1, 0
556 ; GLOBAL-NEXT: blt 0, .LBB17_2
557 ; GLOBAL-NEXT: # %bb.1:
558 ; GLOBAL-NEXT: fmr 3, 2
559 ; GLOBAL-NEXT: .LBB17_2:
560 ; GLOBAL-NEXT: fmr 1, 3
561 ; GLOBAL-NEXT: blr
562 %cmp = fcmp nnan ult double %a, 0.0
563 %z.y = select i1 %cmp, double %z, double %y
564 ret double %z.y
565 }
566
567 ; FP library calls can have fast-math-flags.
568
569 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'log2_approx:'
570 ; FMFDEBUG: ch,glue = PPCISD::CALL_NOP {{t[0-9]+}}, TargetGlobalAddress:i64<ptr @log2>
571 ; FMFDEBUG: ch,glue = callseq_end [[T15:t[0-9]+]], TargetConstant:i64<32>, TargetConstant:i64<0>, [[T15]]:1
572 ; FMFDEBUG: f64,ch,glue = CopyFromReg [[T16:t[0-9]+]], Register:f64 $f1, [[T16]]:1
573 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'log2_approx:'
574
575 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'log2_approx:'
576 ; GLOBALDEBUG: ch,glue = PPCISD::CALL_NOP {{t[0-9]+}}, TargetGlobalAddress:i64<ptr @log2>
577 ; GLOBALDEBUG: ch,glue = callseq_end [[T15:t[0-9]+]], TargetConstant:i64<32>, TargetConstant:i64<0>, [[T15]]:1
578 ; GLOBALDEBUG: f64,ch,glue = CopyFromReg [[T16:t[0-9]+]], Register:f64 $f1, [[T16]]:1
579 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'log2_approx:'
580
581 declare double @log2(double)
582 define double @log2_approx(double %x) nounwind {
583 ; FMF-LABEL: log2_approx:
584 ; FMF: # %bb.0:
585 ; FMF-NEXT: mflr 0
586 ; FMF-NEXT: stdu 1, -32(1)
587 ; FMF-NEXT: std 0, 48(1)
588 ; FMF-NEXT: bl log2
589 ; FMF-NEXT: nop
590 ; FMF-NEXT: addi 1, 1, 32
591 ; FMF-NEXT: ld 0, 16(1)
592 ; FMF-NEXT: mtlr 0
593 ; FMF-NEXT: blr
594 ;
595 ; GLOBAL-LABEL: log2_approx:
596 ; GLOBAL: # %bb.0:
597 ; GLOBAL-NEXT: mflr 0
598 ; GLOBAL-NEXT: stdu 1, -32(1)
599 ; GLOBAL-NEXT: std 0, 48(1)
600 ; GLOBAL-NEXT: bl log2
601 ; GLOBAL-NEXT: nop
602 ; GLOBAL-NEXT: addi 1, 1, 32
603 ; GLOBAL-NEXT: ld 0, 16(1)
604 ; GLOBAL-NEXT: mtlr 0
605 ; GLOBAL-NEXT: blr
606 %r = call afn double @log2(double %x)
607 ret double %r
608 }
609
610 ; -(X - Y) --> (Y - X)
611
612 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
613 ; FMFDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}}
614 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
615
616 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
617 ; GLOBALDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}}
618 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
619
620 define float @fneg_fsub_nozeros_1(float %x, float %y, float %z) {
621 ; FMF-LABEL: fneg_fsub_nozeros_1:
622 ; FMF: # %bb.0:
623 ; FMF-NEXT: xssubsp 1, 2, 1
624 ; FMF-NEXT: blr
625 ;
626 ; GLOBAL-LABEL: fneg_fsub_nozeros_1:
627 ; GLOBAL: # %bb.0:
628 ; GLOBAL-NEXT: xssubsp 1, 2, 1
629 ; GLOBAL-NEXT: blr
630 %neg = fsub float %x, %y
631 %add = fsub nsz float 0.0, %neg
632 ret float %add
633 }
634
635 attributes #0 = { "denormal-fp-math"="ieee,ieee" }
636 attributes #1 = { "denormal-fp-math"="preserve-sign,preserve-sign" }
637 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
638 ; FMFDEBUG: {{.*}}
639 ; GLOBALDEBUG: {{.*}}