(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
autopar/
reduc-6.c
       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 2558402
       9  
      10  
      11  __attribute__ ((noinline))
      12  int main1 (float x, float max_result)
      13  {
      14    int i;
      15    float b[N];
      16    float c[N];
      17    float diff = 2;
      18    float max = x;
      19    float min = 10;
      20  
      21    for (i=0; i<N; i++)
      22      {
      23        b[i] = i * 3;
      24        c[i] = i;
      25      }
      26    
      27    for (i = 0; i < N; i++) {
      28      diff += (b[i] - c[i]);
      29    }
      30  
      31    for (i = 0; i < N; i++) {
      32      max = max < c[i] ? c[i] : max;
      33    }
      34  
      35    for (i = 0; i < N; i++) {
      36      min = min > c[i] ? c[i] : min;
      37    }
      38  
      39    /* check results:  */
      40    if (diff != DIFF)
      41      abort ();
      42    if (max != max_result)
      43      abort ();
      44    if (min != 0)
      45      abort ();
      46  
      47    return 0;
      48  }
      49  
      50  int main (void)
      51  { 
      52    main1 (2000, 2000);
      53    main1 (0, 1599);
      54    return 0;
      55  }
      56  
      57  
      58  /* need -ffast-math to  parallelize these loops.  */
      59  /* { dg-final { scan-tree-dump-times "Detected reduction" 0 "parloops2" } } */
      60  /* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 1 "parloops2" } } */
      61  /* { dg-final { scan-tree-dump-times "FAILED: it is not a part of reduction" 3 "parloops2" } } */