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