libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-simd-14.c
blobc8a38f85ad4f29c9bbc664a368e23254effdd976
1 /* { dg-require-effective-target size32plus } */
2 /* { dg-additional-options "-fopenmp-simd" } */
3 /* { dg-additional-options "-mavx" { target avx_runtime } } */
4 /* { dg-final { scan-tree-dump-times "vectorized \[1-3] loops" 2 "vect" { target i?86-*-* x86_64-*-* } } } */
6 #ifndef main
7 #include "tree-vect.h"
8 #endif
10 #ifdef __FAST_MATH__
11 #define FLT_MIN_VALUE (-__FLT_MAX__)
12 #else
13 #define FLT_MIN_VALUE (-__builtin_inff ())
14 #endif
16 float r = 1.0f, a[1024], b[1024];
18 __attribute__((noipa)) void
19 foo (float *a, float *b)
21 #pragma omp simd reduction (inscan, *:r)
22 for (int i = 0; i < 1024; i++)
24 b[i] = r;
25 #pragma omp scan exclusive(r)
26 r *= a[i];
30 __attribute__((noipa)) float
31 bar (void)
33 float s = FLT_MIN_VALUE;
34 #pragma omp simd reduction (inscan, max:s)
35 for (int i = 0; i < 1024; i++)
37 b[i] = s;
38 #pragma omp scan exclusive(s)
39 s = s > a[i] ? s : a[i];
41 return s;
44 int
45 main ()
47 float s = 1.0f;
48 #ifndef main
49 check_vect ();
50 #endif
51 for (int i = 0; i < 1024; ++i)
53 if (i < 80)
54 a[i] = (i & 1) ? 0.25f : 0.5f;
55 else if (i < 200)
56 a[i] = (i % 3) == 0 ? 2.0f : (i % 3) == 1 ? 4.0f : 1.0f;
57 else if (i < 280)
58 a[i] = (i & 1) ? 0.25f : 0.5f;
59 else if (i < 380)
60 a[i] = (i % 3) == 0 ? 2.0f : (i % 3) == 1 ? 4.0f : 1.0f;
61 else
62 switch (i % 6)
64 case 0: a[i] = 0.25f; break;
65 case 1: a[i] = 2.0f; break;
66 case 2: a[i] = -1.0f; break;
67 case 3: a[i] = -4.0f; break;
68 case 4: a[i] = 0.5f; break;
69 case 5: a[i] = 1.0f; break;
70 default: a[i] = 0.0f; break;
72 b[i] = -19.0f;
73 asm ("" : "+g" (i));
75 foo (a, b);
76 if (r * 16384.0f != 0.125f)
77 abort ();
78 float m = -175.25f;
79 #pragma GCC novector
80 for (int i = 0; i < 1024; ++i)
82 if (b[i] != s)
83 abort ();
84 else
85 b[i] = -231.75f;
86 s *= a[i];
87 a[i] = m - ((i % 3) == 1 ? 2.0f : (i % 3) == 2 ? 4.0f : 0.0f);
88 m += 0.75f;
90 if (bar () != 592.0f)
91 abort ();
92 s = FLT_MIN_VALUE;
93 #pragma GCC novector
94 for (int i = 0; i < 1024; ++i)
96 if (b[i] != s)
97 abort ();
98 if (s < a[i])
99 s = a[i];
101 return 0;