| 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 |
|
| 9 |
template <typename T> |
| 10 |
struct S { |
| 11 |
inline S (); |
| 12 |
inline ~S (); |
| 13 |
inline S (const S &); |
| 14 |
inline S & operator= (const S &); |
| 15 |
T s; |
| 16 |
}; |
| 17 |
|
| 18 |
template <typename T> |
| 19 |
S<T>::S () : s (0) |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 23 |
template <typename T> |
| 24 |
S<T>::~S () |
| 25 |
{ |
| 26 |
} |
| 27 |
|
| 28 |
template <typename T> |
| 29 |
S<T>::S (const S &x) |
| 30 |
{ |
| 31 |
s = x.s; |
| 32 |
} |
| 33 |
|
| 34 |
template <typename T> |
| 35 |
S<T> & |
| 36 |
S<T>::operator= (const S &x) |
| 37 |
{ |
| 38 |
s = x.s; |
| 39 |
return *this; |
| 40 |
} |
| 41 |
|
| 42 |
template <typename T> |
| 43 |
static inline void |
| 44 |
ini (S<T> &x) |
| 45 |
{ |
| 46 |
x.s = 0; |
| 47 |
} |
| 48 |
|
| 49 |
S<int> r, a[1024], b[1024]; |
| 50 |
|
| 51 |
#pragma omp declare reduction (+: S<int>: omp_out.s += omp_in.s) |
| 52 |
#pragma omp declare reduction (plus: S<int>: omp_out.s += omp_in.s) initializer (ini (omp_priv)) |
| 53 |
|
| 54 |
template <typename T> |
| 55 |
__attribute__((noipa)) void |
| 56 |
foo (S<T> *a, S<T> *b) |
| 57 |
{ |
| 58 |
#pragma omp for simd if (0) reduction (inscan, +:r) |
| 59 |
for (int i = 0; i < 1024; i++) |
| 60 |
{ |
| 61 |
b[i] = r; |
| 62 |
#pragma omp scan exclusive(r) |
| 63 |
r.s += a[i].s; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
template <typename T> |
| 68 |
__attribute__((noipa)) S<T> |
| 69 |
bar (void) |
| 70 |
{ |
| 71 |
S<T> s; |
| 72 |
#pragma omp parallel |
| 73 |
#pragma omp for simd reduction (inscan, plus:s) |
| 74 |
for (int i = 0; i < 1024; i++) |
| 75 |
{ |
| 76 |
b[i] = s; |
| 77 |
#pragma omp scan exclusive(s) |
| 78 |
s.s += 2 * a[i].s; |
| 79 |
} |
| 80 |
return S<T> (s); |
| 81 |
} |
| 82 |
|
| 83 |
__attribute__((noipa)) void |
| 84 |
baz (S<int> *a, S<int> *b) |
| 85 |
{ |
| 86 |
#pragma omp parallel for simd reduction (inscan, +:r) |
| 87 |
for (int i = 0; i < 1024; i++) |
| 88 |
{ |
| 89 |
b[i] = r; |
| 90 |
#pragma omp scan exclusive(r) |
| 91 |
r.s += a[i].s; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
__attribute__((noipa)) S<int> |
| 96 |
qux (void) |
| 97 |
{ |
| 98 |
S<int> s; |
| 99 |
#pragma omp parallel for simd simdlen(1) reduction (inscan, plus:s) |
| 100 |
for (int i = 0; i < 1024; i++) |
| 101 |
{ |
| 102 |
b[i] = s; |
| 103 |
#pragma omp scan exclusive(s) |
| 104 |
s.s += 2 * a[i].s; |
| 105 |
} |
| 106 |
return S<int> (s); |
| 107 |
} |
| 108 |
|
| 109 |
int |
| 110 |
main () |
| 111 |
{ |
| 112 |
S<int> s; |
| 113 |
for (int i = 0; i < 1024; ++i) |
| 114 |
{ |
| 115 |
a[i].s = i; |
| 116 |
b[i].s = -1; |
| 117 |
asm ("" : "+g" (i)); |
| 118 |
} |
| 119 |
#pragma omp parallel |
| 120 |
foo (a, b); |
| 121 |
if (r.s != 1024 * 1023 / 2) |
| 122 |
abort (); |
| 123 |
for (int i = 0; i < 1024; ++i) |
| 124 |
{ |
| 125 |
if (b[i].s != s.s) |
| 126 |
abort (); |
| 127 |
else |
| 128 |
b[i].s = 25; |
| 129 |
s.s += i; |
| 130 |
} |
| 131 |
if (bar<int> ().s != 1024 * 1023) |
| 132 |
abort (); |
| 133 |
s.s = 0; |
| 134 |
for (int i = 0; i < 1024; ++i) |
| 135 |
{ |
| 136 |
if (b[i].s != s.s) |
| 137 |
abort (); |
| 138 |
s.s += 2 * i; |
| 139 |
} |
| 140 |
r.s = 0; |
| 141 |
baz (a, b); |
| 142 |
if (r.s != 1024 * 1023 / 2) |
| 143 |
abort (); |
| 144 |
s.s = 0; |
| 145 |
for (int i = 0; i < 1024; ++i) |
| 146 |
{ |
| 147 |
if (b[i].s != s.s) |
| 148 |
abort (); |
| 149 |
else |
| 150 |
b[i].s = 25; |
| 151 |
s.s += i; |
| 152 |
} |
| 153 |
if (qux ().s != 1024 * 1023) |
| 154 |
abort (); |
| 155 |
s.s = 0; |
| 156 |
for (int i = 0; i < 1024; ++i) |
| 157 |
{ |
| 158 |
if (b[i].s != s.s) |
| 159 |
abort (); |
| 160 |
s.s += 2 * i; |
| 161 |
} |
| 162 |
} |