aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-8.c
blob: 0443c9d1ab98aacaa197bf4ac0c587bf1b26d986 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* { dg-do run } */
/* { dg-additional-options "-O2 -fvect-cost-model=cheap -fdump-tree-vect-details" } */
/* { dg-additional-options "-mavx" { target avx_runtime } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 3 "vect" { target avx_runtime } } } */

int v, x;

__attribute__((noipa)) int
foo (int *a)
{
  #pragma omp parallel for simd lastprivate (conditional: x) schedule(simd: static)
  for (int i = 0; i < 128; i++)
    if (a[i])
      x = a[i];
  return x;
}

__attribute__((noipa)) int
bar (int *a, int *b)
{
  #pragma omp parallel
  #pragma omp for simd lastprivate (conditional: x, v) schedule(static, 16)
  for (int i = 16; i < 128; ++i)
    {
      if (a[i])
	x = a[i];
      if (b[i])
	v = b[i] + 10;
    }
  return x;
}

__attribute__((noipa)) int
baz (int *a)
{
  #pragma omp parallel for simd lastprivate (conditional: x) schedule(simd: dynamic, 16)
  for (int i = 0; i < 128; i++)
    if (a[i])
      x = a[i] + 5;
  return x;
}

int
main ()
{
  int a[128], b[128], i;
  for (i = 0; i < 128; i++)
    {
      a[i] = ((i % 11) == 2) ? i + 10 : 0;
      asm volatile ("" : "+g" (i));
      b[i] = ((i % 13) == 5) ? i * 2 : 0;
    }
  if (foo (a) != 133)
    __builtin_abort ();
  if (bar (b, a) != 244 || v != 143)
    __builtin_abort ();
  if (baz (b) != 249)
    __builtin_abort ();
  return 0;
}