2018-05-17 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / fma4-fma.c
blob5db6e19d6b0c49b86aaeaeb029ce41b73c54aa5f
1 /* Test that the compiler properly optimizes floating point multiply
2 and add instructions into vfmaddss, vfmsubss, vfnmaddss,
3 vfnmsubss on FMA4 systems. */
5 /* { dg-do compile { target { ! ia32 } } } */
6 /* { dg-options "-O2 -mfma4 -mno-fma" } */
8 extern void exit (int);
10 float
11 flt_mul_add (float a, float b, float c)
13 return (a * b) + c;
16 double
17 dbl_mul_add (double a, double b, double c)
19 return (a * b) + c;
22 float
23 flt_mul_sub (float a, float b, float c)
25 return (a * b) - c;
28 double
29 dbl_mul_sub (double a, double b, double c)
31 return (a * b) - c;
34 float
35 flt_neg_mul_add (float a, float b, float c)
37 return (-(a * b)) + c;
40 double
41 dbl_neg_mul_add (double a, double b, double c)
43 return (-(a * b)) + c;
46 float
47 flt_neg_mul_sub (float a, float b, float c)
49 return (-(a * b)) - c;
52 double
53 dbl_neg_mul_sub (double a, double b, double c)
55 return (-(a * b)) - c;
58 float f[10] = { 2, 3, 4 };
59 double d[10] = { 2, 3, 4 };
61 int main ()
63 f[3] = flt_mul_add (f[0], f[1], f[2]);
64 f[4] = flt_mul_sub (f[0], f[1], f[2]);
65 f[5] = flt_neg_mul_add (f[0], f[1], f[2]);
66 f[6] = flt_neg_mul_sub (f[0], f[1], f[2]);
68 d[3] = dbl_mul_add (d[0], d[1], d[2]);
69 d[4] = dbl_mul_sub (d[0], d[1], d[2]);
70 d[5] = dbl_neg_mul_add (d[0], d[1], d[2]);
71 d[6] = dbl_neg_mul_sub (d[0], d[1], d[2]);
72 exit (0);
75 /* { dg-final { scan-assembler "vfmaddss" } } */
76 /* { dg-final { scan-assembler "vfmaddsd" } } */
77 /* { dg-final { scan-assembler "vfmsubss" } } */
78 /* { dg-final { scan-assembler "vfmsubsd" } } */
79 /* { dg-final { scan-assembler "vfnmaddss" } } */
80 /* { dg-final { scan-assembler "vfnmaddsd" } } */
81 /* { dg-final { scan-assembler "vfnmsubss" } } */
82 /* { dg-final { scan-assembler "vfnmsubsd" } } */