1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
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 -enable-unsafe-fp-math -enable-no-nans-fp-math | FileCheck %s --check-prefix=GLOBALDEBUG
6 ; RUN: llc < %s -mtriple=powerpc64le -enable-unsafe-fp-math -enable-no-nans-fp-math -enable-no-signed-zeros-fp-math | FileCheck %s --check-prefix=GLOBAL
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.
12 declare float @llvm.fma.f32(float, float, float)
13 declare float @llvm.sqrt.f32(float)
15 ; X * Y + Z --> fma(X, Y, Z)
17 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_contract1:'
18 ; FMFDEBUG: fma contract {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
19 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_contract1:'
21 define float @fmul_fadd_contract1(float %x, float %y, float %z) {
22 ; FMF-LABEL: fmul_fadd_contract1:
24 ; FMF-NEXT: xsmaddasp 3, 1, 2
28 ; GLOBAL-LABEL: fmul_fadd_contract1:
30 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
31 ; GLOBAL-NEXT: fmr 1, 3
33 %mul = fmul float %x, %y
34 %add = fadd contract float %mul, %z
38 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
40 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_contract2:'
41 ; FMFDEBUG: fma contract {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
42 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_contract2:'
44 define float @fmul_fadd_contract2(float %x, float %y, float %z) {
45 ; FMF-LABEL: fmul_fadd_contract2:
47 ; FMF-NEXT: xsmaddasp 3, 1, 2
51 ; GLOBAL-LABEL: fmul_fadd_contract2:
53 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
54 ; GLOBAL-NEXT: fmr 1, 3
56 %mul = fmul contract float %x, %y
57 %add = fadd contract float %mul, %z
61 ; Reassociation implies that FMA contraction is allowed.
63 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_reassoc1:'
64 ; FMFDEBUG: fma reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
65 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_reassoc1:'
67 define float @fmul_fadd_reassoc1(float %x, float %y, float %z) {
68 ; FMF-LABEL: fmul_fadd_reassoc1:
70 ; FMF-NEXT: xsmaddasp 3, 1, 2
74 ; GLOBAL-LABEL: fmul_fadd_reassoc1:
76 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
77 ; GLOBAL-NEXT: fmr 1, 3
79 %mul = fmul float %x, %y
80 %add = fadd reassoc float %mul, %z
84 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
86 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_reassoc2:'
87 ; FMFDEBUG: fma reassoc {{t[0-9]+}}, {{t[0-9]+}}
88 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_reassoc2:'
90 define float @fmul_fadd_reassoc2(float %x, float %y, float %z) {
91 ; FMF-LABEL: fmul_fadd_reassoc2:
93 ; FMF-NEXT: xsmaddasp 3, 1, 2
97 ; GLOBAL-LABEL: fmul_fadd_reassoc2:
99 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
100 ; GLOBAL-NEXT: fmr 1, 3
102 %mul = fmul reassoc float %x, %y
103 %add = fadd reassoc float %mul, %z
107 ; The fadd is now fully 'fast'. This implies that contraction is allowed.
109 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_fast1:'
110 ; FMFDEBUG: fma nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
111 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_fast1:'
113 define float @fmul_fadd_fast1(float %x, float %y, float %z) {
114 ; FMF-LABEL: fmul_fadd_fast1:
116 ; FMF-NEXT: xsmaddasp 3, 1, 2
120 ; GLOBAL-LABEL: fmul_fadd_fast1:
122 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
123 ; GLOBAL-NEXT: fmr 1, 3
125 %mul = fmul fast float %x, %y
126 %add = fadd fast float %mul, %z
130 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
132 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_fast2:'
133 ; FMFDEBUG: fma nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}}
134 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_fast2:'
136 define float @fmul_fadd_fast2(float %x, float %y, float %z) {
137 ; FMF-LABEL: fmul_fadd_fast2:
139 ; FMF-NEXT: xsmaddasp 3, 1, 2
143 ; GLOBAL-LABEL: fmul_fadd_fast2:
145 ; GLOBAL-NEXT: xsmaddasp 3, 1, 2
146 ; GLOBAL-NEXT: fmr 1, 3
148 %mul = fmul fast float %x, %y
149 %add = fadd fast float %mul, %z
153 ; fma(X, 7.0, X * 42.0) --> X * 49.0
154 ; This is the minimum FMF needed for this transform - the FMA allows reassociation.
156 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc1:'
157 ; FMFDEBUG: fmul reassoc {{t[0-9]+}},
158 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc1:'
160 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc1:'
161 ; GLOBALDEBUG: fmul reassoc {{t[0-9]+}}
162 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc1:'
164 define float @fmul_fma_reassoc1(float %x) {
165 ; FMF-LABEL: fmul_fma_reassoc1:
167 ; FMF-NEXT: addis 3, 2, .LCPI6_0@toc@ha
168 ; FMF-NEXT: lfs 0, .LCPI6_0@toc@l(3)
169 ; FMF-NEXT: xsmulsp 1, 1, 0
172 ; GLOBAL-LABEL: fmul_fma_reassoc1:
174 ; GLOBAL-NEXT: addis 3, 2, .LCPI6_0@toc@ha
175 ; GLOBAL-NEXT: lfs 0, .LCPI6_0@toc@l(3)
176 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
178 %mul = fmul float %x, 42.0
179 %fma = call reassoc float @llvm.fma.f32(float %x, float 7.0, float %mul)
183 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
185 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc2:'
186 ; FMFDEBUG: fmul reassoc {{t[0-9]+}}
187 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc2:'
189 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc2:'
190 ; GLOBALDEBUG: fmul reassoc {{t[0-9]+}}
191 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc2:'
193 define float @fmul_fma_reassoc2(float %x) {
194 ; FMF-LABEL: fmul_fma_reassoc2:
196 ; FMF-NEXT: addis 3, 2, .LCPI7_0@toc@ha
197 ; FMF-NEXT: lfs 0, .LCPI7_0@toc@l(3)
198 ; FMF-NEXT: xsmulsp 1, 1, 0
201 ; GLOBAL-LABEL: fmul_fma_reassoc2:
203 ; GLOBAL-NEXT: addis 3, 2, .LCPI7_0@toc@ha
204 ; GLOBAL-NEXT: lfs 0, .LCPI7_0@toc@l(3)
205 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
207 %mul = fmul reassoc float %x, 42.0
208 %fma = call reassoc float @llvm.fma.f32(float %x, float 7.0, float %mul)
212 ; The FMA is now fully 'fast'. This implies that reassociation is allowed.
214 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast1:'
215 ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
216 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast1:'
218 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast1:'
219 ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
220 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast1:'
222 define float @fmul_fma_fast1(float %x) {
223 ; FMF-LABEL: fmul_fma_fast1:
225 ; FMF-NEXT: addis 3, 2, .LCPI8_0@toc@ha
226 ; FMF-NEXT: lfs 0, .LCPI8_0@toc@l(3)
227 ; FMF-NEXT: xsmulsp 1, 1, 0
230 ; GLOBAL-LABEL: fmul_fma_fast1:
232 ; GLOBAL-NEXT: addis 3, 2, .LCPI8_0@toc@ha
233 ; GLOBAL-NEXT: lfs 0, .LCPI8_0@toc@l(3)
234 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
236 %mul = fmul float %x, 42.0
237 %fma = call fast float @llvm.fma.f32(float %x, float 7.0, float %mul)
241 ; This shouldn't change anything - the intermediate fmul result is now also flagged.
243 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast2:'
244 ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
245 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast2:'
247 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast2:'
248 ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
249 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast2:'
251 define float @fmul_fma_fast2(float %x) {
252 ; FMF-LABEL: fmul_fma_fast2:
254 ; FMF-NEXT: addis 3, 2, .LCPI9_0@toc@ha
255 ; FMF-NEXT: lfs 0, .LCPI9_0@toc@l(3)
256 ; FMF-NEXT: xsmulsp 1, 1, 0
259 ; GLOBAL-LABEL: fmul_fma_fast2:
261 ; GLOBAL-NEXT: addis 3, 2, .LCPI9_0@toc@ha
262 ; GLOBAL-NEXT: lfs 0, .LCPI9_0@toc@l(3)
263 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
265 %mul = fmul fast float %x, 42.0
266 %fma = call fast float @llvm.fma.f32(float %x, float 7.0, float %mul)
270 ; Reduced precision for sqrt is allowed - should use estimate and NR iterations.
272 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn:'
273 ; FMFDEBUG: fmul afn {{t[0-9]+}}
274 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn:'
276 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn:'
277 ; GLOBALDEBUG: fmul afn {{t[0-9]+}}
278 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn:'
280 define float @sqrt_afn(float %x) {
281 ; FMF-LABEL: sqrt_afn:
283 ; FMF-NEXT: xxlxor 0, 0, 0
284 ; FMF-NEXT: fcmpu 0, 1, 0
285 ; FMF-NEXT: beq 0, .LBB10_2
287 ; FMF-NEXT: xsrsqrtesp 0, 1
288 ; FMF-NEXT: addis 3, 2, .LCPI10_0@toc@ha
289 ; FMF-NEXT: addis 4, 2, .LCPI10_1@toc@ha
290 ; FMF-NEXT: lfs 2, .LCPI10_0@toc@l(3)
291 ; FMF-NEXT: lfs 3, .LCPI10_1@toc@l(4)
292 ; FMF-NEXT: xsmulsp 1, 1, 0
293 ; FMF-NEXT: xsmulsp 0, 1, 0
294 ; FMF-NEXT: xsmulsp 1, 1, 2
295 ; FMF-NEXT: xsaddsp 0, 0, 3
296 ; FMF-NEXT: xsmulsp 0, 1, 0
297 ; FMF-NEXT: .LBB10_2:
301 ; GLOBAL-LABEL: sqrt_afn:
303 ; GLOBAL-NEXT: xxlxor 0, 0, 0
304 ; GLOBAL-NEXT: fcmpu 0, 1, 0
305 ; GLOBAL-NEXT: beq 0, .LBB10_2
306 ; GLOBAL-NEXT: # %bb.1:
307 ; GLOBAL-NEXT: xsrsqrtesp 0, 1
308 ; GLOBAL-NEXT: addis 3, 2, .LCPI10_0@toc@ha
309 ; GLOBAL-NEXT: addis 4, 2, .LCPI10_1@toc@ha
310 ; GLOBAL-NEXT: lfs 2, .LCPI10_0@toc@l(3)
311 ; GLOBAL-NEXT: lfs 3, .LCPI10_1@toc@l(4)
312 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
313 ; GLOBAL-NEXT: xsmaddasp 2, 1, 0
314 ; GLOBAL-NEXT: xsmulsp 0, 1, 3
315 ; GLOBAL-NEXT: xsmulsp 0, 0, 2
316 ; GLOBAL-NEXT: .LBB10_2:
317 ; GLOBAL-NEXT: fmr 1, 0
319 %rt = call afn float @llvm.sqrt.f32(float %x)
323 ; The call is now fully 'fast'. This implies that approximation is allowed.
325 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast:'
326 ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
327 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast:'
329 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast:'
330 ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}
331 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast:'
333 define float @sqrt_fast(float %x) {
334 ; FMF-LABEL: sqrt_fast:
336 ; FMF-NEXT: xxlxor 0, 0, 0
337 ; FMF-NEXT: fcmpu 0, 1, 0
338 ; FMF-NEXT: beq 0, .LBB11_2
340 ; FMF-NEXT: xsrsqrtesp 0, 1
341 ; FMF-NEXT: addis 3, 2, .LCPI11_0@toc@ha
342 ; FMF-NEXT: addis 4, 2, .LCPI11_1@toc@ha
343 ; FMF-NEXT: lfs 2, .LCPI11_0@toc@l(3)
344 ; FMF-NEXT: lfs 3, .LCPI11_1@toc@l(4)
345 ; FMF-NEXT: xsmulsp 1, 1, 0
346 ; FMF-NEXT: xsmaddasp 2, 1, 0
347 ; FMF-NEXT: xsmulsp 0, 1, 3
348 ; FMF-NEXT: xsmulsp 0, 0, 2
349 ; FMF-NEXT: .LBB11_2:
353 ; GLOBAL-LABEL: sqrt_fast:
355 ; GLOBAL-NEXT: xxlxor 0, 0, 0
356 ; GLOBAL-NEXT: fcmpu 0, 1, 0
357 ; GLOBAL-NEXT: beq 0, .LBB11_2
358 ; GLOBAL-NEXT: # %bb.1:
359 ; GLOBAL-NEXT: xsrsqrtesp 0, 1
360 ; GLOBAL-NEXT: addis 3, 2, .LCPI11_0@toc@ha
361 ; GLOBAL-NEXT: addis 4, 2, .LCPI11_1@toc@ha
362 ; GLOBAL-NEXT: lfs 2, .LCPI11_0@toc@l(3)
363 ; GLOBAL-NEXT: lfs 3, .LCPI11_1@toc@l(4)
364 ; GLOBAL-NEXT: xsmulsp 1, 1, 0
365 ; GLOBAL-NEXT: xsmaddasp 2, 1, 0
366 ; GLOBAL-NEXT: xsmulsp 0, 1, 3
367 ; GLOBAL-NEXT: xsmulsp 0, 0, 2
368 ; GLOBAL-NEXT: .LBB11_2:
369 ; GLOBAL-NEXT: fmr 1, 0
371 %rt = call fast float @llvm.sqrt.f32(float %x)
375 ; fcmp can have fast-math-flags.
377 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:'
378 ; FMFDEBUG: select_cc nnan {{t[0-9]+}}
379 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:'
381 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:'
382 ; GLOBALDEBUG: select_cc nnan {{t[0-9]+}}
383 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:'
385 define double @fcmp_nnan(double %a, double %y, double %z) {
386 ; FMF-LABEL: fcmp_nnan:
388 ; FMF-NEXT: xxlxor 0, 0, 0
389 ; FMF-NEXT: xscmpudp 0, 1, 0
390 ; FMF-NEXT: blt 0, .LBB12_2
393 ; FMF-NEXT: .LBB12_2:
397 ; GLOBAL-LABEL: fcmp_nnan:
399 ; GLOBAL-NEXT: xxlxor 0, 0, 0
400 ; GLOBAL-NEXT: xscmpudp 0, 1, 0
401 ; GLOBAL-NEXT: blt 0, .LBB12_2
402 ; GLOBAL-NEXT: # %bb.1:
403 ; GLOBAL-NEXT: fmr 3, 2
404 ; GLOBAL-NEXT: .LBB12_2:
405 ; GLOBAL-NEXT: fmr 1, 3
407 %cmp = fcmp nnan ult double %a, 0.0
408 %z.y = select i1 %cmp, double %z, double %y
412 ; FP library calls can have fast-math-flags.
414 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'log2_approx:'
415 ; FMFDEBUG: ch,glue = PPCISD::CALL_NOP t11, TargetGlobalAddress:i64<double (double)* @log2>
416 ; FMFDEBUG: ch,glue = callseq_end t15, TargetConstant:i64<32>, TargetConstant:i64<0>, t15:1
417 ; FMFDEBUG: f64,ch,glue = CopyFromReg afn t16, Register:f64 $f1, t16:1
418 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'log2_approx:'
420 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'log2_approx:'
421 ; GLOBALDEBUG: ch,glue = PPCISD::CALL_NOP t11, TargetGlobalAddress:i64<double (double)* @log2>
422 ; GLOBALDEBUG: ch,glue = callseq_end t15, TargetConstant:i64<32>, TargetConstant:i64<0>, t15:1
423 ; GLOBALDEBUG: f64,ch,glue = CopyFromReg afn t16, Register:f64 $f1, t16:1
424 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'log2_approx:'
426 declare double @log2(double)
427 define double @log2_approx(double %x) nounwind {
428 ; FMF-LABEL: log2_approx:
431 ; FMF-NEXT: std 0, 16(1)
432 ; FMF-NEXT: stdu 1, -32(1)
435 ; FMF-NEXT: addi 1, 1, 32
436 ; FMF-NEXT: ld 0, 16(1)
440 ; GLOBAL-LABEL: log2_approx:
442 ; GLOBAL-NEXT: mflr 0
443 ; GLOBAL-NEXT: std 0, 16(1)
444 ; GLOBAL-NEXT: stdu 1, -32(1)
445 ; GLOBAL-NEXT: bl log2
447 ; GLOBAL-NEXT: addi 1, 1, 32
448 ; GLOBAL-NEXT: ld 0, 16(1)
449 ; GLOBAL-NEXT: mtlr 0
451 %r = call afn double @log2(double %x)
455 ; -(X - Y) --> (Y - X)
457 ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
458 ; FMFDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}}
459 ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
461 ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
462 ; GLOBALDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}}
463 ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
465 define float @fneg_fsub_nozeros_1(float %x, float %y, float %z) {
466 ; FMF-LABEL: fneg_fsub_nozeros_1:
468 ; FMF-NEXT: xssubsp 1, 2, 1
471 ; GLOBAL-LABEL: fneg_fsub_nozeros_1:
473 ; GLOBAL-NEXT: xssubsp 1, 2, 1
475 %neg = fsub float %x, %y
476 %add = fsub nsz float 0.0, %neg