(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
vect/
vect-over-widen-9.c
       1  /* { dg-require-effective-target vect_int } */
       2  /* { dg-require-effective-target vect_shift } */
       3  /* { dg-require-effective-target vect_pack_trunc } */
       4  /* { dg-require-effective-target vect_unpack } */
       5  
       6  #include "tree-vect.h"
       7  
       8  #ifndef SIGNEDNESS
       9  #define SIGNEDNESS signed
      10  #define BASE_B -128
      11  #define BASE_C -100
      12  #endif
      13  
      14  #define N 50
      15  
      16  /* Both range analysis and backward propagation from the truncation show
      17     that these calculations can be done in SIGNEDNESS short.  */
      18  void __attribute__ ((noipa))
      19  f (SIGNEDNESS char *restrict a, SIGNEDNESS char *restrict b,
      20     SIGNEDNESS char *restrict c)
      21  {
      22    for (int i = 0; i < N; ++i)
      23      {
      24        /* Deliberate use of signed >>.  */
      25        int res = b[i] + c[i];
      26        a[i] = (res + (res >> 1)) >> 2;
      27      }
      28  }
      29  
      30  int
      31  main (void)
      32  {
      33    check_vect ();
      34  
      35    SIGNEDNESS char a[N], b[N], c[N];
      36    for (int i = 0; i < N; ++i)
      37      {
      38        b[i] = BASE_B + i * 5;
      39        c[i] = BASE_C + i * 4;
      40        asm volatile ("" ::: "memory");
      41      }
      42    f (a, b, c);
      43    for (int i = 0; i < N; ++i)
      44      {
      45        int res = BASE_B + BASE_C + i * 9;
      46        if (a[i] != ((res + (res >> 1)) >> 2))
      47  	__builtin_abort ();
      48      }
      49  
      50    return 0;
      51  }
      52  
      53  /* { dg-final { scan-tree-dump {Splitting statement} "vect" } } */
      54  /* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern: detected:[^\n]* \+ } "vect" } } */
      55  /* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern: detected:[^\n]* >> 1} "vect" } } */
      56  /* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern: detected:[^\n]* >> 2} "vect" } } */
      57  /* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern: detected:[^\n]* \(signed char\)} "vect" } } */
      58  /* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
      59  /* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */