libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-fmax-3.c
blob58e74e22ac4d83ef97af714bbac7849bfd89d9c0
1 /* { dg-require-effective-target vect_float } */
3 #include "tree-vect.h"
5 void __attribute__((noipa))
6 test (double x0, double x1, double *restrict res, double *restrict ptr, int n)
8 for (int i = 0; i < n; i += 2)
10 x0 = __builtin_fmax (x0, ptr[i + 0]);
11 x1 = __builtin_fmax (x1, ptr[i + 1]);
13 res[0] = x0;
14 res[1] = x1;
17 #define N 128
18 #define HALF (N / 2)
20 int
21 main (void)
23 check_vect ();
25 double res[2], a[N];
27 for (int i = 0; i < N; i += 2)
29 a[i] = i < HALF ? i : HALF;
30 a[i + 1] = i / 8;
33 test (-1, -1, res, a, 2);
34 if (res[0] != 0 || res[1] != 0)
35 __builtin_abort ();
37 test (-1, -1, res, a, 6);
38 if (res[0] != 4 || res[1] != 0)
39 __builtin_abort ();
41 test (-1, -1, res, a, 8);
42 if (res[0] != 6 || res[1] != 0)
43 __builtin_abort ();
45 test (-1, -1, res, a, 10);
46 if (res[0] != 8 || res[1] != 1)
47 __builtin_abort ();
49 test (-1, -1, res, a, HALF - 2);
50 if (res[0] != HALF - 4 || res[1] != HALF / 8 - 1)
51 __builtin_abort ();
53 test (-1, -1, res, a, HALF);
54 if (res[0] != HALF - 2 || res[1] != HALF / 8 - 1)
55 __builtin_abort ();
57 test (-1, -1, res, a, HALF + 2);
58 if (res[0] != HALF || res[1] != HALF / 8)
59 __builtin_abort ();
61 test (-1, -1, res, a, HALF + 8);
62 if (res[0] != HALF || res[1] != HALF / 8)
63 __builtin_abort ();
65 test (-1, -1, res, a, HALF + 10);
66 if (res[0] != HALF || res[1] != HALF / 8 + 1)
67 __builtin_abort ();
69 test (-1, -1, res, a, N);
70 if (res[0] != HALF || res[1] != N / 8 - 1)
71 __builtin_abort ();
73 test (HALF + 1, -1, res, a, N);
74 if (res[0] != HALF + 1 || res[1] != N / 8 - 1)
75 __builtin_abort ();
77 test (HALF + 1, N, res, a, N);
78 if (res[0] != HALF + 1 || res[1] != N)
79 __builtin_abort ();
81 return 0;
84 /* { dg-final { scan-tree-dump "Detected reduction" "vect" } } */
85 /* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target vect_max_reduc } } } */