Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-simd-9.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 int r, a[1024], b[1024];
11
12 #pragma omp declare reduction (foo: int: omp_out += omp_in) initializer (omp_priv = 0)
13
14 __attribute__((noipa)) void
15 foo (int *a, int *b)
16 {
17 #pragma omp simd reduction (inscan, foo:r)
18 for (int i = 0; i < 1024; i++)
19 {
20 r += a[i];
21 #pragma omp scan inclusive(r)
22 b[i] = r;
23 }
24 }
25
26 __attribute__((noipa)) int
27 bar (void)
28 {
29 int s = 0;
30 #pragma omp simd reduction (inscan, foo:s)
31 for (int i = 0; i < 1024; i++)
32 {
33 s += 2 * a[i];
34 #pragma omp scan inclusive(s)
35 b[i] = s;
36 }
37 return s;
38 }
39
40 __attribute__((noipa)) void
41 baz (int *a, int *b)
42 {
43 #pragma omp simd reduction (inscan, foo:r) if (simd: 0)
44 for (int i = 0; i < 1024; i++)
45 {
46 r += a[i];
47 #pragma omp scan inclusive(r)
48 b[i] = r;
49 }
50 }
51
52 __attribute__((noipa)) int
53 qux (void)
54 {
55 int s = 0;
56 #pragma omp simd reduction (inscan, foo:s) simdlen (1)
57 for (int i = 0; i < 1024; i++)
58 {
59 s += 2 * a[i];
60 #pragma omp scan inclusive(s)
61 b[i] = s;
62 }
63 return s;
64 }
65
66 int
67 main ()
68 {
69 int s = 0;
70 #ifndef main
71 check_vect ();
72 #endif
73 for (int i = 0; i < 1024; ++i)
74 {
75 a[i] = i;
76 b[i] = -1;
77 asm ("" : "+g" (i));
78 }
79 foo (a, b);
80 if (r != 1024 * 1023 / 2)
81 abort ();
82 #pragma GCC novector
83 for (int i = 0; i < 1024; ++i)
84 {
85 s += i;
86 if (b[i] != s)
87 abort ();
88 else
89 b[i] = 25;
90 }
91 if (bar () != 1024 * 1023)
92 abort ();
93 s = 0;
94 #pragma GCC novector
95 for (int i = 0; i < 1024; ++i)
96 {
97 s += 2 * i;
98 if (b[i] != s)
99 abort ();
100 else
101 b[i] = -1;
102 }
103 r = 0;
104 baz (a, b);
105 if (r != 1024 * 1023 / 2)
106 abort ();
107 s = 0;
108 #pragma GCC novector
109 for (int i = 0; i < 1024; ++i)
110 {
111 s += i;
112 if (b[i] != s)
113 abort ();
114 else
115 b[i] = -25;
116 }
117 if (qux () != 1024 * 1023)
118 abort ();
119 s = 0;
120 #pragma GCC novector
121 for (int i = 0; i < 1024; ++i)
122 {
123 s += 2 * i;
124 if (b[i] != s)
125 abort ();
126 }
127 return 0;
128 }