1 /* { dg-require-effective-target scalar_all_fma } */
2 /* { dg-additional-options "-fdump-tree-optimized -ffp-contract=fast" } */
3 
4 #include "tree-vect.h"
5 
6 #define N (VECTOR_BITS * 11 / 64 + 3)
7 
8 #define DEF(INV)					\
9   void __attribute__ ((noipa))				\
10   f_##INV (double *restrict a, double *restrict b,	\
11 	   double *restrict c, double *restrict d)	\
12   {							\
13     for (int i = 0; i < N; ++i)				\
14       {							\
15 	double mb = (INV & 1 ? -b[i] : b[i]);		\
16 	double mc = c[i];				\
17 	double md = (INV & 2 ? -d[i] : d[i]);		\
18 	a[i] = b[i] < 10 ? mb * mc + md : 10.0;		\
19       }							\
20   }
21 
22 #define TEST(INV)					\
23   {							\
24     f_##INV (a, b, c, d);				\
25     for (int i = 0; i < N; ++i)				\
26       {							\
27 	double mb = (INV & 1 ? -b[i] : b[i]);		\
28 	double mc = c[i];				\
29 	double md = (INV & 2 ? -d[i] : d[i]);		\
30 	double fma = __builtin_fma (mb, mc, md);	\
31 	if (a[i] != (i % 17 < 10 ? fma : 10.0))		\
32 	  __builtin_abort ();				\
33 	asm volatile ("" ::: "memory");			\
34       }							\
35   }
36 
37 #define FOR_EACH_INV(T) \
38   T (0) T (1) T (2) T (3)
39 
FOR_EACH_INV(DEF)40 FOR_EACH_INV (DEF)
41 
42 int
43 main (void)
44 {
45   double a[N], b[N], c[N], d[N];
46   for (int i = 0; i < N; ++i)
47     {
48       b[i] = i % 17;
49       c[i] = i % 9 + 11;
50       d[i] = i % 13 + 14;
51       asm volatile ("" ::: "memory");
52     }
53   FOR_EACH_INV (TEST)
54   return 0;
55 }
56 
57 /* { dg-final { scan-tree-dump-times { = \.COND_FMA } 1 "optimized" { target vect_double_cond_arith } } } */
58 /* { dg-final { scan-tree-dump-times { = \.COND_FMS } 1 "optimized" { target vect_double_cond_arith } } } */
59 /* { dg-final { scan-tree-dump-times { = \.COND_FNMA } 1 "optimized" { target vect_double_cond_arith } } } */
60 /* { dg-final { scan-tree-dump-times { = \.COND_FNMS } 1 "optimized" { target vect_double_cond_arith } } } */
61