Fix xfail for 32-bit hppa*-*-* in gcc.dg/pr84877.c
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / scan-12.C
blobee91157852013803035c7bd2068540fc2d409e95
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 } } }
7 extern "C" void abort ();
9 struct S {
10   inline S ();
11   inline ~S ();
12   inline S (const S &);
13   inline S & operator= (const S &);
14   int s;
17 S::S () : s (0)
21 S::~S ()
25 S::S (const S &x)
27   s = x.s;
30 S &
31 S::operator= (const S &x)
33   s = x.s;
34   return *this;
37 static inline void
38 ini (S &x)
40   x.s = 0;
43 S r, a[1024], b[1024];
45 #pragma omp declare reduction (+: S: omp_out.s += omp_in.s)
46 #pragma omp declare reduction (plus: S: omp_out.s += omp_in.s) initializer (ini (omp_priv))
48 __attribute__((noipa)) void
49 foo (S *a, S *b, S &r)
51   #pragma omp for simd reduction (inscan, +:r)
52   for (int i = 0; i < 1024; i++)
53     {
54       r.s += a[i].s;
55       #pragma omp scan inclusive(r)
56       b[i] = r;
57     }
60 __attribute__((noipa)) S
61 bar ()
63   S s;
64   #pragma omp parallel
65   #pragma omp for simd reduction (inscan, plus:s)
66   for (int i = 0; i < 1024; i++)
67     {
68       s.s += 2 * a[i].s;
69       #pragma omp scan inclusive(s)
70       b[i] = s;
71     }
72   return s;
75 __attribute__((noipa)) void
76 baz (S *a, S *b, S &r)
78   #pragma omp parallel for simd if (simd: 0) reduction (inscan, +:r)
79   for (int i = 0; i < 1024; i++)
80     {
81       r.s += a[i].s;
82       #pragma omp scan inclusive(r)
83       b[i] = r;
84     }
87 __attribute__((noipa)) S
88 qux ()
90   S s;
91   #pragma omp parallel for simd reduction (inscan, plus:s) simdlen(1)
92   for (int i = 0; i < 1024; i++)
93     {
94       s.s += 2 * a[i].s;
95       #pragma omp scan inclusive(s)
96       b[i] = s;
97     }
98   return s;
102 main ()
104   S s;
105   for (int i = 0; i < 1024; ++i)
106     {
107       a[i].s = i;
108       b[i].s = -1;
109       asm ("" : "+g" (i));
110     }
111   #pragma omp parallel
112   foo (a, b, r);
113   if (r.s != 1024 * 1023 / 2)
114     abort ();
115   for (int i = 0; i < 1024; ++i)
116     {
117       s.s += i;
118       if (b[i].s != s.s)
119         abort ();
120       else
121         b[i].s = 25;
122     }
123   if (bar ().s != 1024 * 1023)
124     abort ();
125   s.s = 0;
126   for (int i = 0; i < 1024; ++i)
127     {
128       s.s += 2 * i;
129       if (b[i].s != s.s)
130         abort ();
131     }
132   r.s = 0;
133   baz (a, b, r);
134   if (r.s != 1024 * 1023 / 2)
135     abort ();
136   s.s = 0;
137   for (int i = 0; i < 1024; ++i)
138     {
139       s.s += i;
140       if (b[i].s != s.s)
141         abort ();
142       else
143         b[i].s = 25;
144     }
145   if (qux ().s != 1024 * 1023)
146     abort ();
147   s.s = 0;
148   for (int i = 0; i < 1024; ++i)
149     {
150       s.s += 2 * i;
151       if (b[i].s != s.s)
152         abort ();
153     }