1 /* { dg-do compile } */
2 /* { dg-options "-O2 -ftree-parallelize-loops=4 -fdump-tree-parloops2-details -fdump-tree-optimized" } */
3 
4 #include <stdlib.h>
5 
6 #define N 3200
7 
8 extern void abort (void);
9 typedef unsigned short T;
10 
11 __attribute__ ((noinline)) void
testmax(const T * c,T init,T result)12 testmax (const T *c, T init, T result)
13 {
14   T lc[N], accum = init;
15   int i;
16 
17   __builtin_memcpy (lc, c, sizeof(lc));
18 
19   for (i = 0; i < N; i++) {
20     accum = accum < lc[i] ? lc[i] : accum;
21   }
22 
23   if (accum != result)
24     abort ();
25 }
26 
27 __attribute__ ((noinline)) void
testmin(const T * c,T init,T result)28 testmin (const T *c, T init, T result)
29 {
30   T lc[N], accum = init;
31   int i;
32 
33   __builtin_memcpy (lc, c, sizeof(lc));
34 
35   for (i = 0; i < N; i++) {
36     accum = accum > lc[i] ? lc[i] : accum;
37   }
38 
39   if (accum != result)
40     abort ();
41 }
42 
main(void)43 int main (void)
44 {
45   static unsigned short A[N] = {
46     0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008,
47     0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010,
48     0x7000, 0x7100, 0x7200, 0x7300, 0x7400, 0x7500, 0x7600, 0x7700,
49     0x7ff8, 0x7ff9, 0x7ffa, 0x7ffb, 0x7ffc, 0x7ffd, 0x7ffe, 0x7fff
50   };
51 
52   static unsigned short B[N] = {
53     0x7000, 0x7100, 0x7200, 0x7300, 0x7400, 0x7500, 0x7600, 0x7700,
54     0x7ff8, 0x7ff9, 0x7ffa, 0x7ffb, 0x7ffc, 0x7ffd, 0x7ffe, 0x7fff,
55     0x8000, 0x8001, 0x8002, 0x8003, 0x8004, 0x8005, 0x8006, 0x8007,
56     0x8008, 0x8009, 0x800a, 0x800b, 0x800c, 0x800d, 0x800e, 0x800f
57   };
58 
59   static unsigned short C[N] = {
60     0xffff, 0xfffe, 0xfffd, 0xfffc, 0xfffb, 0xfffa, 0xfff9, 0xfff8,
61     0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010,
62     0x8000, 0x8001, 0x8002, 0x8003, 0x8004, 0x8005, 0x8006, 0x8007,
63     0x7000, 0x7100, 0x7200, 0x7300, 0x7400, 0x7500, 0x7600, 0x7700,
64   };
65 
66   int i;
67 
68   for (i=32; i<N; i++)
69     {
70       A[i]= 0x0001;
71       B[i]= 0x7000;
72       C[i]= 0xffff;
73     }
74 
75   testmin (A, 10, 1);
76   testmin (B, 0x7fff, 0x7000);
77   testmin (C, 0x7fff, 0x0009);
78 
79   testmax (A, 0, 0x7fff);
80   testmax (B, 0, 0x800f);
81   testmax (C, 0, 0xffff);
82 
83   return 0;
84 }
85 
86 
87 /* { dg-final { scan-tree-dump-times "Detected reduction" 2 "parloops2" } } */
88 /* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 3 "parloops2" } } */
89