Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-simd-10.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 r *= a[i];
25 #pragma omp scan inclusive(r)
26 b[i] = r;
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 s = s > a[i] ? s : a[i];
38 #pragma omp scan inclusive(s)
39 b[i] = s;
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 s *= a[i];
83 if (b[i] != s)
84 abort ();
85 else
86 {
87 a[i] = m - ((i % 3) == 1 ? 2.0f : (i % 3) == 2 ? 4.0f : 0.0f);
88 b[i] = -231.75f;
89 m += 0.75f;
90 }
91 }
92 if (bar () != 592.0f)
93 abort ();
94 s = FLT_MIN_VALUE;
95 #pragma GCC novector
96 for (int i = 0; i < 1024; ++i)
97 {
98 if (s < a[i])
99 s = a[i];
100 if (b[i] != s)
101 abort ();
102 }
103 return 0;
104 }