(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
vect/
vect-simd-8.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        r += a[i];
      19        #pragma omp scan inclusive(r)
      20        b[i] = r;
      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        s += 2 * a[i];
      32        #pragma omp scan inclusive(s)
      33        b[i] = s;
      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        r += a[i];
      45        #pragma omp scan inclusive(r)
      46        b[i] = r;
      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        s += 2 * a[i];
      58        #pragma omp scan inclusive(s)
      59        b[i] = s;
      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        s += i;
      83        if (b[i] != s)
      84  	abort ();
      85        else
      86  	b[i] = 25;
      87      }
      88    if (bar () != 1024 * 1023)
      89      abort ();
      90    s = 0;
      91    for (int i = 0; i < 1024; ++i)
      92      {
      93        s += 2 * i;
      94        if (b[i] != s)
      95  	abort ();
      96        else
      97  	b[i] = -1;
      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        s += i;
     107        if (b[i] != s)
     108  	abort ();
     109        else
     110  	b[i] = -25;
     111      }
     112    if (qux () != 1024 * 1023)
     113      abort ();
     114    s = 0;
     115    for (int i = 0; i < 1024; ++i)
     116      {
     117        s += 2 * i;
     118        if (b[i] != s)
     119  	abort ();
     120      }
     121    return 0;
     122  }