| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-additional-options "-msse2" { target sse2_runtime } } */ |
| 3 |
/* { dg-additional-options "-mavx" { target avx_runtime } } */ |
| 4 |
|
| 5 |
extern void abort (); |
| 6 |
int a[32][32] __attribute__((aligned (32))) = { { 1 } }; |
| 7 |
struct S { int s; }; |
| 8 |
#pragma omp declare reduction (+:struct S:omp_out.s += omp_in.s) |
| 9 |
#pragma omp declare reduction (foo:struct S:omp_out.s += omp_in.s) |
| 10 |
#pragma omp declare reduction (foo:int:omp_out += omp_in) |
| 11 |
|
| 12 |
__attribute__((noinline, noclone)) int |
| 13 |
foo (void) |
| 14 |
{ |
| 15 |
int i, j, u = 0; |
| 16 |
struct S s, t; |
| 17 |
s.s = 0; t.s = 0; |
| 18 |
#pragma omp simd aligned(a : 32) lastprivate (i, j) reduction(+:s) reduction(foo:t, u) collapse(2) |
| 19 |
for (i = 0; i < 32; i++) |
| 20 |
for (j = 0; j < 32; j++) |
| 21 |
{ |
| 22 |
int *q = &i; |
| 23 |
int *r = &j; |
| 24 |
int x = a[i][j]; |
| 25 |
s.s += x; |
| 26 |
t.s += x; |
| 27 |
u += x; |
| 28 |
} |
| 29 |
if (t.s != s.s || u != s.s || i != 32 || j != 32) |
| 30 |
abort (); |
| 31 |
return s.s; |
| 32 |
} |
| 33 |
|
| 34 |
__attribute__((noinline, noclone)) int |
| 35 |
bar (void) |
| 36 |
{ |
| 37 |
int i, j, u = 0; |
| 38 |
struct S s, t; |
| 39 |
s.s = 0; t.s = 0; |
| 40 |
#pragma omp simd aligned(a:32)reduction(+:s)reduction(foo:t,u)collapse(2) |
| 41 |
for (i = 0; i < 32; i++) |
| 42 |
for (j = 0; j < 32; j++) |
| 43 |
{ |
| 44 |
int *q = &i; |
| 45 |
int *r = &j; |
| 46 |
int x = a[i][j]; |
| 47 |
s.s += x; |
| 48 |
t.s += x; |
| 49 |
u += x; |
| 50 |
} |
| 51 |
if (t.s != s.s || u != s.s || i != 32 || j != 32) |
| 52 |
abort (); |
| 53 |
return s.s; |
| 54 |
} |
| 55 |
|
| 56 |
int |
| 57 |
main () |
| 58 |
{ |
| 59 |
int i, j; |
| 60 |
for (i = 0; i < 32; i++) |
| 61 |
for (j = 0; j < 32; j++) |
| 62 |
a[i][j] = j + (i / 4); |
| 63 |
int s = foo (); |
| 64 |
if (s != 19456) |
| 65 |
abort (); |
| 66 |
if (bar () != 19456) |
| 67 |
abort (); |
| 68 |
return 0; |
| 69 |
} |