Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/vect/simd-6.cc @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 // { dg-require-effective-target size32plus } | |
2 // { dg-additional-options "-fopenmp-simd" } | |
3 // { dg-additional-options "-mavx" { target avx_runtime } } | |
4 // { dg-final { scan-tree-dump-times "vectorized \[1-3] loops" 2 "vect" { target i?86-*-* x86_64-*-* } } } | |
5 | |
6 #include "../../gcc.dg/vect/tree-vect.h" | |
7 | |
8 template <typename T> | |
9 struct S { | |
10 inline S (); | |
11 inline ~S (); | |
12 inline S (const S &); | |
13 inline S & operator= (const S &); | |
14 T s; | |
15 }; | |
16 | |
17 template <typename T> | |
18 S<T>::S () : s (0) | |
19 { | |
20 } | |
21 | |
22 template <typename T> | |
23 S<T>::~S () | |
24 { | |
25 } | |
26 | |
27 template <typename T> | |
28 S<T>::S (const S &x) | |
29 { | |
30 s = x.s; | |
31 } | |
32 | |
33 template <typename T> | |
34 S<T> & | |
35 S<T>::operator= (const S &x) | |
36 { | |
37 s = x.s; | |
38 return *this; | |
39 } | |
40 | |
41 template <typename T> | |
42 static inline void | |
43 ini (S<T> &x) | |
44 { | |
45 x.s = 0; | |
46 } | |
47 | |
48 S<int> r, a[1024], b[1024]; | |
49 | |
50 #pragma omp declare reduction (+: S<int>: omp_out.s += omp_in.s) | |
51 #pragma omp declare reduction (plus: S<int>: omp_out.s += omp_in.s) initializer (ini (omp_priv)) | |
52 | |
53 template <typename T> | |
54 __attribute__((noipa)) void | |
55 foo (S<T> *a, S<T> *b) | |
56 { | |
57 #pragma omp simd reduction (inscan, +:r) | |
58 for (int i = 0; i < 1024; i++) | |
59 { | |
60 b[i] = r; | |
61 #pragma omp scan exclusive(r) | |
62 r.s += a[i].s; | |
63 } | |
64 } | |
65 | |
66 template <typename T> | |
67 __attribute__((noipa)) S<T> | |
68 bar (void) | |
69 { | |
70 S<T> s; | |
71 #pragma omp simd reduction (inscan, plus:s) | |
72 for (int i = 0; i < 1024; i++) | |
73 { | |
74 b[i] = s; | |
75 #pragma omp scan exclusive(s) | |
76 s.s += 2 * a[i].s; | |
77 } | |
78 return S<T> (s); | |
79 } | |
80 | |
81 __attribute__((noipa)) void | |
82 baz (S<int> *a, S<int> *b) | |
83 { | |
84 #pragma omp simd reduction (inscan, +:r) simdlen(1) | |
85 for (int i = 0; i < 1024; i++) | |
86 { | |
87 b[i] = r; | |
88 #pragma omp scan exclusive(r) | |
89 r.s += a[i].s; | |
90 } | |
91 } | |
92 | |
93 __attribute__((noipa)) S<int> | |
94 qux (void) | |
95 { | |
96 S<int> s; | |
97 #pragma omp simd if (0) reduction (inscan, plus:s) | |
98 for (int i = 0; i < 1024; i++) | |
99 { | |
100 b[i] = s; | |
101 #pragma omp scan exclusive(s) | |
102 s.s += 2 * a[i].s; | |
103 } | |
104 return S<int> (s); | |
105 } | |
106 | |
107 int | |
108 main () | |
109 { | |
110 S<int> s; | |
111 check_vect (); | |
112 for (int i = 0; i < 1024; ++i) | |
113 { | |
114 a[i].s = i; | |
115 b[i].s = -1; | |
116 asm ("" : "+g" (i)); | |
117 } | |
118 foo (a, b); | |
119 if (r.s != 1024 * 1023 / 2) | |
120 abort (); | |
121 for (int i = 0; i < 1024; ++i) | |
122 { | |
123 if (b[i].s != s.s) | |
124 abort (); | |
125 else | |
126 b[i].s = 25; | |
127 s.s += i; | |
128 } | |
129 if (bar<int> ().s != 1024 * 1023) | |
130 abort (); | |
131 s.s = 0; | |
132 for (int i = 0; i < 1024; ++i) | |
133 { | |
134 if (b[i].s != s.s) | |
135 abort (); | |
136 s.s += 2 * i; | |
137 } | |
138 r.s = 0; | |
139 baz (a, b); | |
140 if (r.s != 1024 * 1023 / 2) | |
141 abort (); | |
142 s.s = 0; | |
143 for (int i = 0; i < 1024; ++i) | |
144 { | |
145 if (b[i].s != s.s) | |
146 abort (); | |
147 else | |
148 b[i].s = 25; | |
149 s.s += i; | |
150 } | |
151 if (qux ().s != 1024 * 1023) | |
152 abort (); | |
153 s.s = 0; | |
154 for (int i = 0; i < 1024; ++i) | |
155 { | |
156 if (b[i].s != s.s) | |
157 abort (); | |
158 s.s += 2 * i; | |
159 } | |
160 return 0; | |
161 } |