| 1 |
// { dg-require-effective-target size32plus } |
| 2 |
// { dg-additional-options "-O2 -fopenmp -fdump-tree-vect-details" } |
| 3 |
// { dg-additional-options "-msse2" { target sse2_runtime } } |
| 4 |
// { dg-additional-options "-mavx" { target avx_runtime } } |
| 5 |
// { dg-final { scan-tree-dump-times "vectorized \[2-6] loops" 2 "vect" { target sse2_runtime } } } |
| 6 |
|
| 7 |
extern "C" void abort (); |
| 8 |
int r, a[1024], b[1024], q; |
| 9 |
|
| 10 |
#pragma omp declare reduction (foo: int: omp_out += omp_in) initializer (omp_priv = 0) |
| 11 |
|
| 12 |
__attribute__((noipa)) void |
| 13 |
foo (int *a, int *b, int &r) |
| 14 |
{ |
| 15 |
#pragma omp for simd reduction (inscan, foo:r) |
| 16 |
for (int i = 0; i < 1024; i++) |
| 17 |
{ |
| 18 |
r += a[i]; |
| 19 |
#pragma omp scan inclusive(r) |
| 20 |
b[i] = r; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
__attribute__((noipa)) int |
| 25 |
bar (void) |
| 26 |
{ |
| 27 |
int &s = q; |
| 28 |
q = 0; |
| 29 |
#pragma omp parallel |
| 30 |
#pragma omp for simd reduction (inscan, foo:s) if (0) |
| 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, int &r) |
| 42 |
{ |
| 43 |
#pragma omp parallel for simd simdlen (1) reduction (inscan, foo:r) |
| 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 = q; |
| 56 |
q = 0; |
| 57 |
#pragma omp parallel for simd reduction (inscan, foo:s) |
| 58 |
for (int i = 0; i < 1024; i++) |
| 59 |
{ |
| 60 |
s += 2 * a[i]; |
| 61 |
#pragma omp scan inclusive(s) |
| 62 |
b[i] = s; |
| 63 |
} |
| 64 |
return s; |
| 65 |
} |
| 66 |
|
| 67 |
int |
| 68 |
main () |
| 69 |
{ |
| 70 |
int s = 0; |
| 71 |
for (int i = 0; i < 1024; ++i) |
| 72 |
{ |
| 73 |
a[i] = i; |
| 74 |
b[i] = -1; |
| 75 |
asm ("" : "+g" (i)); |
| 76 |
} |
| 77 |
#pragma omp parallel |
| 78 |
foo (a, b, r); |
| 79 |
if (r != 1024 * 1023 / 2) |
| 80 |
abort (); |
| 81 |
for (int i = 0; i < 1024; ++i) |
| 82 |
{ |
| 83 |
s += i; |
| 84 |
if (b[i] != s) |
| 85 |
abort (); |
| 86 |
else |
| 87 |
b[i] = 25; |
| 88 |
} |
| 89 |
if (bar () != 1024 * 1023) |
| 90 |
abort (); |
| 91 |
s = 0; |
| 92 |
for (int i = 0; i < 1024; ++i) |
| 93 |
{ |
| 94 |
s += 2 * i; |
| 95 |
if (b[i] != s) |
| 96 |
abort (); |
| 97 |
else |
| 98 |
b[i] = -1; |
| 99 |
} |
| 100 |
r = 0; |
| 101 |
baz (a, b, r); |
| 102 |
if (r != 1024 * 1023 / 2) |
| 103 |
abort (); |
| 104 |
s = 0; |
| 105 |
for (int i = 0; i < 1024; ++i) |
| 106 |
{ |
| 107 |
s += i; |
| 108 |
if (b[i] != s) |
| 109 |
abort (); |
| 110 |
else |
| 111 |
b[i] = -25; |
| 112 |
} |
| 113 |
if (qux () != 1024 * 1023) |
| 114 |
abort (); |
| 115 |
s = 0; |
| 116 |
for (int i = 0; i < 1024; ++i) |
| 117 |
{ |
| 118 |
s += 2 * i; |
| 119 |
if (b[i] != s) |
| 120 |
abort (); |
| 121 |
} |
| 122 |
return 0; |
| 123 |
} |