| 1 |
// { dg-require-effective-target size32plus } |
| 2 |
|
| 3 |
extern "C" void abort (); |
| 4 |
int r, a[1024], b[1024], q; |
| 5 |
|
| 6 |
__attribute__((noipa)) void |
| 7 |
foo (int *a, int *b, int &r) |
| 8 |
{ |
| 9 |
#pragma omp for reduction (inscan, +:r) nowait |
| 10 |
for (int i = 0; i < 1024; i++) |
| 11 |
{ |
| 12 |
r += a[i]; |
| 13 |
#pragma omp scan inclusive(r) |
| 14 |
b[i] = r; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
__attribute__((noipa)) int |
| 19 |
bar (void) |
| 20 |
{ |
| 21 |
int &s = q; |
| 22 |
q = 0; |
| 23 |
#pragma omp parallel |
| 24 |
#pragma omp for reduction (inscan, +:s) nowait |
| 25 |
for (int i = 0; i < 1024; i++) |
| 26 |
{ |
| 27 |
s += 2 * a[i]; |
| 28 |
#pragma omp scan inclusive(s) |
| 29 |
b[i] = s; |
| 30 |
} |
| 31 |
return s; |
| 32 |
} |
| 33 |
|
| 34 |
__attribute__((noipa)) void |
| 35 |
baz (int *a, int *b, int &r) |
| 36 |
{ |
| 37 |
#pragma omp parallel for reduction (inscan, +:r) |
| 38 |
for (int i = 0; i < 1024; i++) |
| 39 |
{ |
| 40 |
r += a[i]; |
| 41 |
#pragma omp scan inclusive(r) |
| 42 |
b[i] = r; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
__attribute__((noipa)) int |
| 47 |
qux (void) |
| 48 |
{ |
| 49 |
int &s = q; |
| 50 |
q = 0; |
| 51 |
#pragma omp parallel for reduction (inscan, +:s) |
| 52 |
for (int i = 0; i < 1024; i++) |
| 53 |
{ |
| 54 |
s += 2 * a[i]; |
| 55 |
#pragma omp scan inclusive(s) |
| 56 |
b[i] = s; |
| 57 |
} |
| 58 |
return s; |
| 59 |
} |
| 60 |
|
| 61 |
int |
| 62 |
main () |
| 63 |
{ |
| 64 |
int s = 0; |
| 65 |
for (int i = 0; i < 1024; ++i) |
| 66 |
{ |
| 67 |
a[i] = i; |
| 68 |
b[i] = -1; |
| 69 |
asm ("" : "+g" (i)); |
| 70 |
} |
| 71 |
#pragma omp parallel |
| 72 |
foo (a, b, r); |
| 73 |
if (r != 1024 * 1023 / 2) |
| 74 |
abort (); |
| 75 |
for (int i = 0; i < 1024; ++i) |
| 76 |
{ |
| 77 |
s += i; |
| 78 |
if (b[i] != s) |
| 79 |
abort (); |
| 80 |
else |
| 81 |
b[i] = 25; |
| 82 |
} |
| 83 |
if (bar () != 1024 * 1023) |
| 84 |
abort (); |
| 85 |
s = 0; |
| 86 |
for (int i = 0; i < 1024; ++i) |
| 87 |
{ |
| 88 |
s += 2 * i; |
| 89 |
if (b[i] != s) |
| 90 |
abort (); |
| 91 |
else |
| 92 |
b[i] = -1; |
| 93 |
} |
| 94 |
r = 0; |
| 95 |
baz (a, b, r); |
| 96 |
if (r != 1024 * 1023 / 2) |
| 97 |
abort (); |
| 98 |
s = 0; |
| 99 |
for (int i = 0; i < 1024; ++i) |
| 100 |
{ |
| 101 |
s += i; |
| 102 |
if (b[i] != s) |
| 103 |
abort (); |
| 104 |
else |
| 105 |
b[i] = -25; |
| 106 |
} |
| 107 |
if (qux () != 1024 * 1023) |
| 108 |
abort (); |
| 109 |
s = 0; |
| 110 |
for (int i = 0; i < 1024; ++i) |
| 111 |
{ |
| 112 |
s += 2 * i; |
| 113 |
if (b[i] != s) |
| 114 |
abort (); |
| 115 |
} |
| 116 |
} |