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  /* Deliberate use of signed >>.  */
       9  #define DEF_LOOP(SIGNEDNESS)			\
      10    void __attribute__ ((noipa))			\
      11    f_##SIGNEDNESS (SIGNEDNESS char *restrict a,	\
      12  		  SIGNEDNESS char *restrict b,	\
      13  		  SIGNEDNESS char c)		\
      14    {						\
      15      a[0] = (b[0] + c) >> 1;			\
      16      a[1] = (b[1] + c) >> 1;			\
      17      a[2] = (b[2] + c) >> 1;			\
      18      a[3] = (b[3] + c) >> 1;			\
      19      a[4] = (b[4] + c) >> 1;			\
      20      a[5] = (b[5] + c) >> 1;			\
      21      a[6] = (b[6] + c) >> 1;			\
      22      a[7] = (b[7] + c) >> 1;			\
      23      a[8] = (b[8] + c) >> 1;			\
      24      a[9] = (b[9] + c) >> 1;			\
      25      a[10] = (b[10] + c) >> 1;			\
      26      a[11] = (b[11] + c) >> 1;			\
      27      a[12] = (b[12] + c) >> 1;			\
      28      a[13] = (b[13] + c) >> 1;			\
      29      a[14] = (b[14] + c) >> 1;			\
      30      a[15] = (b[15] + c) >> 1;			\
      31    }
      32  
      33  DEF_LOOP (signed)
      34  DEF_LOOP (unsigned)
      35  
      36  #define N 16
      37  
      38  #define TEST_LOOP(SIGNEDNESS, BASE_B, C)		\
      39    {							\
      40      SIGNEDNESS char a[N], b[N], c[N];			\
      41      for (int i = 0; i < N; ++i)				\
      42        {							\
      43  	b[i] = BASE_B + i * 15;				\
      44  	asm volatile ("" ::: "memory");			\
      45        }							\
      46      f_##SIGNEDNESS (a, b, C);				\
      47      for (int i = 0; i < N; ++i)				\
      48        if (a[i] != (BASE_B + C + i * 15) >> 1)		\
      49  	__builtin_abort ();				\
      50    }
      51  
      52  int
      53  main (void)
      54  {
      55    check_vect ();
      56  
      57    TEST_LOOP (signed, -128, -120);
      58    TEST_LOOP (unsigned, 4, 250);
      59  
      60    return 0;
      61  }
      62  
      63  /* { dg-final { scan-tree-dump "demoting int to signed short" "slp2" { target { ! vect_widen_shift } } } } */
      64  /* { dg-final { scan-tree-dump "demoting int to unsigned short" "slp2" { target { ! vect_widen_shift } } } } */
      65  /* { dg-final { scan-tree-dump {\.AVG_FLOOR} "slp2" { target vect_avg_qi } } } */
      66  /* { dg-final { scan-tree-dump-times "optimized: basic block" 2 "slp2" { target vect_hw_misalign } } } */