(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
vect/
vect-simd-12.c
       1  /* { dg-require-effective-target size32plus } */
       2  /* { dg-additional-options "-fopenmp-simd" } */
       3  /* { dg-additional-options "-mavx" { target avx_runtime } } */
       4  /* { dg-final { scan-tree-dump-times "vectorized \[1-3] loops" 2 "vect" { target i?86-*-* x86_64-*-* } } } */
       5  
       6  #ifndef main
       7  #include "tree-vect.h"
       8  #endif
       9  
      10  int r, a[1024], b[1024];
      11  
      12  __attribute__((noipa)) void
      13  foo (int *a, int *b)
      14  {
      15    #pragma omp simd reduction (inscan, +:r)
      16    for (int i = 0; i < 1024; i++)
      17      {
      18        b[i] = r;
      19        #pragma omp scan exclusive(r)
      20        r += a[i];
      21      }
      22  }
      23  
      24  __attribute__((noipa)) int
      25  bar (void)
      26  {
      27    int s = 0;
      28    #pragma omp simd reduction (inscan, +:s)
      29    for (int i = 0; i < 1024; i++)
      30      {
      31        b[i] = s;
      32        #pragma omp scan exclusive(s)
      33        s += 2 * a[i];
      34      }
      35    return s;
      36  }
      37  
      38  __attribute__((noipa)) void
      39  baz (int *a, int *b)
      40  {
      41    #pragma omp simd reduction (inscan, +:r) if (simd: 0)
      42    for (int i = 0; i < 1024; i++)
      43      {
      44        b[i] = r;
      45        #pragma omp scan exclusive(r)
      46        r += a[i];
      47      }
      48  }
      49  
      50  __attribute__((noipa)) int
      51  qux (void)
      52  {
      53    int s = 0;
      54    #pragma omp simd reduction (inscan, +:s) simdlen (1)
      55    for (int i = 0; i < 1024; i++)
      56      {
      57        b[i] = s;
      58        #pragma omp scan exclusive(s)
      59        s += 2 * a[i];
      60      }
      61    return s;
      62  }
      63  
      64  int
      65  main ()
      66  {
      67    int s = 0;
      68  #ifndef main
      69    check_vect ();
      70  #endif
      71    for (int i = 0; i < 1024; ++i)
      72      {
      73        a[i] = i;
      74        b[i] = -1;
      75        asm ("" : "+g" (i));
      76      }
      77    foo (a, b);
      78    if (r != 1024 * 1023 / 2)
      79      abort ();
      80    for (int i = 0; i < 1024; ++i)
      81      {
      82        if (b[i] != s)
      83  	abort ();
      84        else
      85  	b[i] = 25;
      86        s += i;
      87      }
      88    if (bar () != 1024 * 1023)
      89      abort ();
      90    s = 0;
      91    for (int i = 0; i < 1024; ++i)
      92      {
      93        if (b[i] != s)
      94  	abort ();
      95        else
      96  	b[i] = -1;
      97        s += 2 * i;
      98      }
      99    r = 0;
     100    baz (a, b);
     101    if (r != 1024 * 1023 / 2)
     102      abort ();
     103    s = 0;
     104    for (int i = 0; i < 1024; ++i)
     105      {
     106        if (b[i] != s)
     107  	abort ();
     108        else
     109  	b[i] = -25;
     110        s += i;
     111      }
     112    if (qux () != 1024 * 1023)
     113      abort ();
     114    s = 0;
     115    for (int i = 0; i < 1024; ++i)
     116      {
     117        if (b[i] != s)
     118  	abort ();
     119        s += 2 * i;
     120      }
     121    return 0;
     122  }