fortran: Factor the evaluation of MINLOC/MAXLOC's BACK argument
[official-gcc.git] / libgomp / testsuite / libgomp.c / scan-23.c
blobe7681ad1c370eeeab8f2cd199f55e0094eb4151c
1 /* { dg-require-effective-target size32plus } */
2 /* Same as scan-9.c, instead of using { ... } it simply uses multiple
3 executable stmt before 'omp scan'. */
5 extern void abort (void);
6 int r, a[1024], b[1024], x, y, z;
8 __attribute__((noipa)) void
9 foo (int *a, int *b)
11 #pragma omp for reduction (inscan, +:r) lastprivate (conditional: z) firstprivate (x) private (y)
12 for (int i = 0; i < 1024; i++)
14 y = a[i];
15 r += y + x + 12;
16 #pragma omp scan inclusive(r)
17 b[i] = r;
18 if ((i & 1) == 0 && i < 937)
19 z = r;
23 __attribute__((noipa)) int
24 bar (void)
26 int s = 0;
27 #pragma omp parallel
28 #pragma omp for reduction (inscan, +:s) firstprivate (x) private (y) lastprivate (z)
29 for (int i = 0; i < 1024; i++)
31 y = 2 * a[i]; s += y; z = y;
32 #pragma omp scan inclusive(s)
33 y = s; b[i] = y + x + 12;
35 return s;
38 __attribute__((noipa)) void
39 baz (int *a, int *b)
41 #pragma omp parallel for reduction (inscan, +:r) firstprivate (x) lastprivate (x)
42 for (int i = 0; i < 1024; i++)
44 r += a[i] + x + 12; if (i == 1023) x = 29;
45 #pragma omp scan inclusive(r)
46 b[i] = r;
50 __attribute__((noipa)) int
51 qux (void)
53 int s = 0;
54 #pragma omp parallel for reduction (inscan, +:s) lastprivate (conditional: x, y)
55 for (int i = 0; i < 1024; i++)
57 s += 2 * a[i]; if ((a[i] & 1) == 1 && i < 825) x = a[i];
58 #pragma omp scan inclusive(s)
59 b[i] = s; if ((a[i] & 1) == 0 && i < 829) y = a[i];
61 return s;
64 int
65 main ()
67 int s = 0;
68 x = -12;
69 for (int i = 0; i < 1024; ++i)
71 a[i] = i;
72 b[i] = -1;
73 asm ("" : "+g" (i));
75 #pragma omp parallel
76 foo (a, b);
77 if (r != 1024 * 1023 / 2 || x != -12 || z != b[936])
78 abort ();
79 for (int i = 0; i < 1024; ++i)
81 s += i;
82 if (b[i] != s)
83 abort ();
84 else
85 b[i] = 25;
87 if (bar () != 1024 * 1023 || x != -12 || z != 2 * 1023)
88 abort ();
89 s = 0;
90 for (int i = 0; i < 1024; ++i)
92 s += 2 * i;
93 if (b[i] != s)
94 abort ();
95 else
96 b[i] = -1;
98 r = 0;
99 baz (a, b);
100 if (r != 1024 * 1023 / 2 || x != 29)
101 abort ();
102 s = 0;
103 for (int i = 0; i < 1024; ++i)
105 s += i;
106 if (b[i] != s)
107 abort ();
108 else
109 b[i] = -25;
111 if (qux () != 1024 * 1023 || x != 823 || y != 828)
112 abort ();
113 s = 0;
114 for (int i = 0; i < 1024; ++i)
116 s += 2 * i;
117 if (b[i] != s)
118 abort ();
120 return 0;