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