1  /* { dg-require-effective-target vect_int } */
       2  
       3  #include "tree-vect.h"
       4  #ifndef SIGNEDNESS
       5  #define SIGNEDNESS signed
       6  #endif
       7  #ifndef BIAS
       8  #define BIAS 0
       9  #endif
      10  
      11  #define HRS(x) ((((x) >> (15 - BIAS)) + BIAS) >> BIAS)
      12  
      13  void __attribute__ ((noipa))
      14  f (SIGNEDNESS short *restrict a, SIGNEDNESS short *restrict b,
      15     SIGNEDNESS short *restrict c, __INTPTR_TYPE__ n)
      16  {
      17    for (__INTPTR_TYPE__ i = 0; i < n; ++i)
      18      a[i] = HRS((SIGNEDNESS int) b[i] * (SIGNEDNESS int) c[i]);
      19  }
      20  
      21  #define N 50
      22  #define BASE1 ((SIGNEDNESS int) -1 < 0 ? -126 : 4)
      23  #define BASE2 ((SIGNEDNESS int) -1 < 0 ? -101 : 26)
      24  #define CONST1 0x01AB
      25  #define CONST2 0x01CD
      26  
      27  int
      28  main (void)
      29  {
      30    check_vect ();
      31  
      32    SIGNEDNESS short a[N], b[N], c[N];
      33    for (int i = 0; i < N; ++i)
      34      {
      35        b[i] = BASE1 + i * CONST1;
      36        c[i] = BASE2 + i * CONST2;
      37        asm volatile ("" ::: "memory");
      38      }
      39    f (a, b, c, N);
      40    for (int i = 0; i < N; ++i)
      41      if (a[i] != HRS(BASE1 * BASE2 + i * i * (CONST1 * CONST2)
      42  		    + i * (BASE1 * CONST2 + BASE2 * CONST1)))
      43        __builtin_abort ();
      44    return 0;
      45  }
      46  
      47  /* { dg-final { scan-tree-dump "vect_recog_mulhs_pattern: detected" "vect" } } */
      48  /* { dg-final { scan-tree-dump {\.MULHS} "vect" { target vect_mulhrs_hi } } } */
      49  /* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" { target vect_mulhrs_hi } } } */