OSDN Git Service

90bbc9806c7bd65a47a07a78cbe7e605367c2adf
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / tree-ssa / reduc-7.c
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -ftree-parallelize-loops=4 -fdump-tree-parloops-details -fdump-tree-final_cleanup" } */
3
4 #include <stdlib.h>
5
6 #define N 32
7
8 extern void abort (void);
9 typedef unsigned char T;
10
11 __attribute__ ((noinline)) void
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
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
43 int main (void)
44
45   static unsigned char const A[N] = {
46     0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
47     0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
48     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
49     0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f
50   };
51
52   static unsigned char const B[N] = {
53     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
54     0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
55     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
56     0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f
57   };
58
59   static unsigned char const C[N] = {
60     0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
61     0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
62     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
63     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
64   };
65
66   
67   testmin (A, 10, 1);
68   testmin (B, 0x7f, 0x70);
69   testmin (C, 0x7f, 0x09);
70
71   testmax (A, 0, 0x7f);
72   testmax (B, 0, 0x8f);
73   testmax (C, 0, 0xff);
74
75   return 0;
76 }
77
78 /* { dg-final { scan-tree-dump-times "Detected reduction" 2 "parloops" } } */
79 /* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 2 "parloops" } } */
80 /* { dg-final { cleanup-tree-dump "parloops" } } */
81 /* { dg-final { cleanup-tree-dump "final_cleanup" } } */
82