Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-simd-14.c

raw
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-*-* } } } */
5
6 #ifndef main
7 #include "tree-vect.h"
8 #endif
9
10 #ifdef __FAST_MATH__
11 #define FLT_MIN_VALUE (-__FLT_MAX__)
12 #else
13 #define FLT_MIN_VALUE (-__builtin_inff ())
14 #endif
15
16 float r = 1.0f, a[1024], b[1024];
17
18 __attribute__((noipa)) void
19 foo (float *a, float *b)
20 {
21 #pragma omp simd reduction (inscan, *:r)
22 for (int i = 0; i < 1024; i++)
23 {
24 b[i] = r;
25 #pragma omp scan exclusive(r)
26 r *= a[i];
27 }
28 }
29
30 __attribute__((noipa)) float
31 bar (void)
32 {
33 float s = FLT_MIN_VALUE;
34 #pragma omp simd reduction (inscan, max:s)
35 for (int i = 0; i < 1024; i++)
36 {
37 b[i] = s;
38 #pragma omp scan exclusive(s)
39 s = s > a[i] ? s : a[i];
40 }
41 return s;
42 }
43
44 int
45 main ()
46 {
47 float s = 1.0f;
48 #ifndef main
49 check_vect ();
50 #endif
51 for (int i = 0; i < 1024; ++i)
52 {
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)
63 {
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;
71 }
72 b[i] = -19.0f;
73 asm ("" : "+g" (i));
74 }
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)
81 {
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;
89 }
90 if (bar () != 592.0f)
91 abort ();
92 s = FLT_MIN_VALUE;
93 #pragma GCC novector
94 for (int i = 0; i < 1024; ++i)
95 {
96 if (b[i] != s)
97 abort ();
98 if (s < a[i])
99 s = a[i];
100 }
101 return 0;
102 }