[16/n] PR85694: Add detection of averaging operations
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-avg-1.c
bloba7bc7cc90963c8aa8e14d0960d57dc724486247f
1 /* { dg-require-effective-target vect_int } */
3 #include "tree-vect.h"
5 #define N 50
7 #ifndef SIGNEDNESS
8 #define SIGNEDNESS unsigned
9 #endif
10 #ifndef BIAS
11 #define BIAS 0
12 #endif
14 void __attribute__ ((noipa))
15 f (SIGNEDNESS char *restrict a, SIGNEDNESS char *restrict b,
16 SIGNEDNESS char *restrict c)
18 for (__INTPTR_TYPE__ i = 0; i < N; ++i)
19 a[i] = (b[i] + c[i] + BIAS) >> 1;
22 #define BASE1 ((SIGNEDNESS int) -1 < 0 ? -126 : 4)
23 #define BASE2 ((SIGNEDNESS int) -1 < 0 ? -101 : 26)
25 int
26 main (void)
28 check_vect ();
30 SIGNEDNESS char a[N], b[N], c[N];
31 for (int i = 0; i < N; ++i)
33 b[i] = BASE1 + i * 5;
34 c[i] = BASE2 + i * 4;
35 asm volatile ("" ::: "memory");
37 f (a, b, c);
38 for (int i = 0; i < N; ++i)
39 if (a[i] != ((BASE1 + BASE2 + i * 9 + BIAS) >> 1))
40 __builtin_abort ();
41 return 0;
44 /* { dg-final { scan-tree-dump "vect_recog_average_pattern: detected" "vect" } } */
45 /* { dg-final { scan-tree-dump {\.AVG_FLOOR} "vect" { target vect_avg_qi } } } */
46 /* { dg-final { scan-tree-dump-not {vector\([^\n]*short} "vect" { target vect_avg_qi } } } */
47 /* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" { target vect_avg_qi } } } */