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