libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-cond-reduc-in-order-2-signed-zero.c
blob155ce477103e00b99943de1ac052ca1f5c388b80
1 /* Make sure a -0 stays -0 when we perform a conditional reduction. */
2 /* { dg-require-effective-target vect_double } */
3 /* { dg-add-options ieee } */
4 /* { dg-additional-options "-std=gnu99 -fno-fast-math" } */
6 #include "tree-vect.h"
8 #include <math.h>
10 #define N (VECTOR_BITS * 17)
12 double __attribute__ ((noinline, noclone))
13 reduc_plus_double (double *restrict a, double init, int *cond, int n)
15 double res = init;
16 for (int i = 0; i < n; i++)
17 if (cond[i])
18 res += a[i];
19 return res;
22 double __attribute__ ((noinline, noclone, optimize ("0")))
23 reduc_plus_double_ref (double *restrict a, double init, int *cond, int n)
25 double res = init;
26 for (int i = 0; i < n; i++)
27 if (cond[i])
28 res += a[i];
29 return res;
32 double __attribute__ ((noinline, noclone))
33 reduc_minus_double (double *restrict a, double init, int *cond, int n)
35 double res = init;
36 for (int i = 0; i < n; i++)
37 if (cond[i])
38 res -= a[i];
39 return res;
42 double __attribute__ ((noinline, noclone, optimize ("0")))
43 reduc_minus_double_ref (double *restrict a, double init, int *cond, int n)
45 double res = init;
46 for (int i = 0; i < n; i++)
47 if (cond[i])
48 res -= a[i];
49 return res;
52 int __attribute__ ((optimize (1)))
53 main ()
55 int n = 19;
56 double a[N];
57 int cond1[N], cond2[N];
59 for (int i = 0; i < N; i++)
61 a[i] = (i * 0.1) * (i & 1 ? 1 : -1);
62 cond1[i] = 0;
63 cond2[i] = i & 4 ? 1 : 0;
64 asm volatile ("" ::: "memory");
67 double res1 = reduc_plus_double (a, -0.0, cond1, n);
68 double ref1 = reduc_plus_double_ref (a, -0.0, cond1, n);
69 double res2 = reduc_minus_double (a, -0.0, cond1, n);
70 double ref2 = reduc_minus_double_ref (a, -0.0, cond1, n);
71 double res3 = reduc_plus_double (a, -0.0, cond1, n);
72 double ref3 = reduc_plus_double_ref (a, -0.0, cond1, n);
73 double res4 = reduc_minus_double (a, -0.0, cond1, n);
74 double ref4 = reduc_minus_double_ref (a, -0.0, cond1, n);
76 if (res1 != ref1 || signbit (res1) != signbit (ref1))
77 __builtin_abort ();
78 if (res2 != ref2 || signbit (res2) != signbit (ref2))
79 __builtin_abort ();
80 if (res3 != ref3 || signbit (res3) != signbit (ref3))
81 __builtin_abort ();
82 if (res4 != ref4 || signbit (res4) != signbit (ref4))
83 __builtin_abort ();
85 res1 = reduc_plus_double (a, 0.0, cond1, n);
86 ref1 = reduc_plus_double_ref (a, 0.0, cond1, n);
87 res2 = reduc_minus_double (a, 0.0, cond1, n);
88 ref2 = reduc_minus_double_ref (a, 0.0, cond1, n);
89 res3 = reduc_plus_double (a, 0.0, cond1, n);
90 ref3 = reduc_plus_double_ref (a, 0.0, cond1, n);
91 res4 = reduc_minus_double (a, 0.0, cond1, n);
92 ref4 = reduc_minus_double_ref (a, 0.0, cond1, n);
94 if (res1 != ref1 || signbit (res1) != signbit (ref1))
95 __builtin_abort ();
96 if (res2 != ref2 || signbit (res2) != signbit (ref2))
97 __builtin_abort ();
98 if (res3 != ref3 || signbit (res3) != signbit (ref3))
99 __builtin_abort ();
100 if (res4 != ref4 || signbit (res4) != signbit (ref4))
101 __builtin_abort ();
103 res1 = reduc_plus_double (a, -0.0, cond2, n);
104 ref1 = reduc_plus_double_ref (a, -0.0, cond2, n);
105 res2 = reduc_minus_double (a, -0.0, cond2, n);
106 ref2 = reduc_minus_double_ref (a, -0.0, cond2, n);
107 res3 = reduc_plus_double (a, -0.0, cond2, n);
108 ref3 = reduc_plus_double_ref (a, -0.0, cond2, n);
109 res4 = reduc_minus_double (a, -0.0, cond2, n);
110 ref4 = reduc_minus_double_ref (a, -0.0, cond2, n);
112 if (res1 != ref1 || signbit (res1) != signbit (ref1))
113 __builtin_abort ();
114 if (res2 != ref2 || signbit (res2) != signbit (ref2))
115 __builtin_abort ();
116 if (res3 != ref3 || signbit (res3) != signbit (ref3))
117 __builtin_abort ();
118 if (res4 != ref4 || signbit (res4) != signbit (ref4))
119 __builtin_abort ();
121 res1 = reduc_plus_double (a, 0.0, cond2, n);
122 ref1 = reduc_plus_double_ref (a, 0.0, cond2, n);
123 res2 = reduc_minus_double (a, 0.0, cond2, n);
124 ref2 = reduc_minus_double_ref (a, 0.0, cond2, n);
125 res3 = reduc_plus_double (a, 0.0, cond2, n);
126 ref3 = reduc_plus_double_ref (a, 0.0, cond2, n);
127 res4 = reduc_minus_double (a, 0.0, cond2, n);
128 ref4 = reduc_minus_double_ref (a, 0.0, cond2, n);
130 if (res1 != ref1 || signbit (res1) != signbit (ref1))
131 __builtin_abort ();
132 if (res2 != ref2 || signbit (res2) != signbit (ref2))
133 __builtin_abort ();
134 if (res3 != ref3 || signbit (res3) != signbit (ref3))
135 __builtin_abort ();
136 if (res4 != ref4 || signbit (res4) != signbit (ref4))
137 __builtin_abort ();
139 return 0;