* config/i386/i386.c (ix86_legitimize_address): Declare
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / simd-7.C
blob5a6f4cef7c1c94cc78981fd664481fca6bfd5967
1 // { dg-do run }
2 // { dg-options "-O2" }
3 // { dg-additional-options "-msse2" { target sse2_runtime } }
4 // { dg-additional-options "-mavx" { target avx_runtime } }
6 extern "C" void abort ();
7 int a[1024] __attribute__((aligned (32))) = { 1 };
8 struct S
10   int s;
11   S () : s (0) {}
12   S (int x) : s (x) {}
13   ~S () {}
15 #pragma omp declare reduction (+:S:omp_out.s += omp_in.s) \
16                     initializer (omp_priv (0))
17 #pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) \
18                     initializer (omp_priv (0))
19 #pragma omp declare reduction (foo:int:omp_out += omp_in) \
20                     initializer (omp_priv = 0)
22 __attribute__((noinline, noclone)) S
23 foo (S s)
25   int i, v = 0, &u = v;
26   S t;
27   #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u) \
28                    safelen(1)
29   for (i = 0; i < 1024; i++)
30     {
31       int x = a[i];
32       s.s += x;
33       t.s += x;
34       u += x;
35     }
36   if (t.s != s.s || u != s.s)
37     abort ();
38   return t;
41 __attribute__((noinline, noclone)) int
42 bar (S &s, S &t)
44   int i, v = 0, &u = v;
45   #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u) \
46                    safelen(1)
47   for (i = 0; i < 1024; i++)
48     {
49       int x = a[i];
50       s.s += x;
51       t.s += x;
52       u += x;
53     }
54   if (t.s != s.s || u != s.s)
55     abort ();
56   return s.s;
59 int
60 main ()
62   int i;
63   for (i = 0; i < 1024; i++)
64     a[i] = (i & 31) + (i / 128);
65   S q;
66   int s = foo (q).s;
67   if (s != 19456)
68     abort ();
69   S r, v;
70   if (bar (r, v) != s)
71     abort ();