1 /* { dg-do compile } */
2 /* { dg-options "-O2 -ftree-parallelize-loops=4 -fdump-tree-parloops2-details -fdump-tree-optimized" } */
3 
4 #include <stdarg.h>
5 #include <stdlib.h>
6 
7 #define N 1600
8 #define DIFF 242
9 
10 unsigned short ub[N] = {1,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
11 unsigned short uc[N] = {1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
12 
13 __attribute__ ((noinline)) void
main1(unsigned short x,unsigned short max_result,unsigned short min_result)14 main1 (unsigned short x, unsigned short max_result, unsigned short min_result)
15 {
16   int i;
17   unsigned short udiff = 2;
18   unsigned short umax = x;
19   unsigned short umin = x;
20 
21   for (i = 0; i < N; i++) {
22     udiff += (unsigned short)(ub[i] - uc[i]);
23   }
24 
25   for (i = 0; i < N; i++) {
26     umax = umax < uc[i] ? uc[i] : umax;
27   }
28 
29   for (i = 0; i < N; i++) {
30     umin = umin > uc[i] ? uc[i] : umin;
31   }
32 
33   /* check results:  */
34   if (udiff != DIFF)
35     abort ();
36   if (umax != max_result)
37     abort ();
38   if (umin != min_result)
39     abort ();
40 }
41 
42  __attribute__((noinline))
init_arrays()43  void init_arrays ()
44  {
45    int i;
46 
47    for (i=16; i<N; i++)
48      {
49        ub[i] = 1;
50        uc[i] = 1;
51      }
52 }
53 
main(void)54 int main (void)
55 {
56   init_arrays();
57   main1 (100, 100, 1);
58   main1 (0, 15, 0);
59   return 0;
60 }
61 
62 /* { dg-final { scan-tree-dump-times "Detected reduction" 3 "parloops2" } } */
63 /* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 4 "parloops2" } } */
64 
65