PR rtl-optimization/77919
[official-gcc.git] / libgomp / testsuite / libgomp.c / taskloop-4.c
bloba69be19c9c21ed5be2f011f7fdfbd50b76b60d40
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fopenmp" } */
4 int u[64], v;
6 __attribute__((noinline, noclone)) int
7 test (int a, int b, int c, int d, void (*fn) (int, int, int, int),
8 int *num_tasks, int *min_iters, int *max_iters)
10 int i, t = 0;
11 __builtin_memset (u, 0, sizeof u);
12 v = 0;
13 fn (a, b, c, d);
14 *min_iters = 0;
15 *max_iters = 0;
16 *num_tasks = v;
17 if (v)
19 *min_iters = u[0];
20 *max_iters = u[0];
21 t = u[0];
22 for (i = 1; i < v; i++)
24 if (*min_iters > u[i])
25 *min_iters = u[i];
26 if (*max_iters < u[i])
27 *max_iters = u[i];
28 t += u[i];
31 return t;
34 void
35 grainsize (int a, int b, int c, int d)
37 int i, j = 0, k = 0;
38 #pragma omp taskloop firstprivate (j, k) grainsize(d)
39 for (i = a; i < b; i += c)
41 if (j == 0)
43 #pragma omp atomic capture
44 k = v++;
45 if (k >= 64)
46 __builtin_abort ();
48 u[k] = ++j;
52 void
53 num_tasks (int a, int b, int c, int d)
55 int i, j = 0, k = 0;
56 #pragma omp taskloop firstprivate (j, k) num_tasks(d)
57 for (i = a; i < b; i += c)
59 if (j == 0)
61 #pragma omp atomic capture
62 k = v++;
63 if (k >= 64)
64 __builtin_abort ();
66 u[k] = ++j;
70 int
71 main ()
73 #pragma omp parallel
74 #pragma omp single
76 int min_iters, max_iters, ntasks;
77 /* If grainsize is present, # of task loop iters is >= grainsize && < 2 * grainsize,
78 unless # of loop iterations is smaller than grainsize. */
79 if (test (0, 79, 1, 17, grainsize, &ntasks, &min_iters, &max_iters) != 79
80 || min_iters < 17 || max_iters >= 17 * 2)
81 __builtin_abort ();
82 if (test (-49, 2541, 7, 28, grainsize, &ntasks, &min_iters, &max_iters) != 370
83 || min_iters < 28 || max_iters >= 28 * 2)
84 __builtin_abort ();
85 if (test (7, 21, 2, 15, grainsize, &ntasks, &min_iters, &max_iters) != 7
86 || ntasks != 1 || min_iters != 7 || max_iters != 7)
87 __builtin_abort ();
88 /* If num_tasks is present, # of task loop iters is min (# of loop iters, num_tasks). */
89 if (test (-51, 2500, 48, 9, num_tasks, &ntasks, &min_iters, &max_iters) != 54
90 || ntasks != 9)
91 __builtin_abort ();
92 if (test (0, 25, 2, 17, num_tasks, &ntasks, &min_iters, &max_iters) != 13
93 || ntasks != 13)
94 __builtin_abort ();
96 return 0;