| 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 signed 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 __attribute__((optimize ("-ftree-parallelize-loops=0"))) |
| 44 |
main (void) |
| 45 |
{ |
| 46 |
static signed char A[N] = { |
| 47 |
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 48 |
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
| 49 |
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, |
| 50 |
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f |
| 51 |
}; |
| 52 |
|
| 53 |
static signed char B[N] = { |
| 54 |
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, |
| 55 |
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, |
| 56 |
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 57 |
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f |
| 58 |
}; |
| 59 |
|
| 60 |
static signed char C[N] = { |
| 61 |
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, |
| 62 |
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
| 63 |
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 64 |
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, |
| 65 |
}; |
| 66 |
|
| 67 |
int i; |
| 68 |
|
| 69 |
for (i=32; i<N; i++) |
| 70 |
{ |
| 71 |
A[i]= 0x01; |
| 72 |
B[i]= 0x70; |
| 73 |
C[i]= 0xff; |
| 74 |
} |
| 75 |
|
| 76 |
testmin (A, 0, 0); |
| 77 |
testmin (B, 0, 0x80); |
| 78 |
testmin (C, 0, 0x80); |
| 79 |
|
| 80 |
testmax (A, 0, 0x7f); |
| 81 |
testmax (B, 0, 0x7f); |
| 82 |
testmax (C, 0, 0x77); |
| 83 |
|
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
/* { dg-final { scan-tree-dump-times "Detected reduction" 2 "parloops2" } } */ |
| 89 |
/* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 2 "parloops2" } } */ |