1/* PR tree-optimization/58392 */
2/* { dg-do run } */
3/* { dg-options "-O2" } */
4/* { dg-additional-options "-msse2" { target sse2_runtime } } */
5/* { dg-additional-options "-mavx" { target avx_runtime } } */
6
7extern void abort (void);
8int d[32 * 32];
9
10__attribute__((noinline, noclone)) int
11foo (int a, int b)
12{
13  int j, c = 0;
14  #pragma omp parallel for reduction(+: c)
15    for (j = 0; j < a; j += 32)
16      {
17	int l;
18	#pragma omp simd reduction(+: c)
19	  for (l = 0; l < b; ++l)
20	    c += d[j + l];
21      }
22  return c;
23}
24
25__attribute__((noinline, noclone)) int
26bar (int a)
27{
28  int j, c = 0;
29  #pragma omp parallel for simd reduction(+: c)
30    for (j = 0; j < a; ++j)
31      c += d[j];
32  return c;
33}
34
35__attribute__((noinline)) static int
36baz (int a)
37{
38  int j, c = 0;
39  #pragma omp simd reduction(+: c)
40    for (j = 0; j < a; ++j)
41      c += d[j];
42  return c;
43}
44
45int
46main ()
47{
48  int i;
49  for (i = 0; i < 32 * 32; i++)
50    d[i] = (i & 31);
51  if (foo (32 * 32, 32) != (31 * 32 / 2) * 32)
52    abort ();
53  if (bar (32 * 32) != (31 * 32 / 2) * 32)
54    abort ();
55  if (baz (32 * 32) != (31 * 32 / 2) * 32)
56    abort ();
57  return 0;
58}
59