(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
autopar/
reduc-7.c
       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 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 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 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 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    int i;
      67  
      68    for (i=32; i<N; i++)
      69      {
      70        A[i]= 0x01;
      71        B[i]= 0x70;
      72        C[i]= 0xff;
      73      }
      74  
      75    testmin (A, 10, 1);
      76    testmin (B, 0x7f, 0x70);
      77    testmin (C, 0x7f, 0x09);
      78  
      79    testmax (A, 0, 0x7f);
      80    testmax (B, 0, 0x8f);
      81    testmax (C, 0, 0xff);
      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" 2 "parloops2" } } */
      89