libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-avg-1.c
blob052903762c94a2265b5be192bc6ab4efbe262ecb
1 /* { dg-require-effective-target vect_int } */
2 /* { dg-additional-options "-fdump-tree-optimized" } */
4 #include "tree-vect.h"
6 #define N 50
8 #ifndef SIGNEDNESS
9 #define SIGNEDNESS unsigned
10 #endif
11 #ifndef BIAS
12 #define BIAS 0
13 #endif
15 void __attribute__ ((noipa))
16 f (SIGNEDNESS char *restrict a, SIGNEDNESS char *restrict b,
17 SIGNEDNESS char *restrict c)
19 for (__INTPTR_TYPE__ i = 0; i < N; ++i)
20 a[i] = (b[i] + c[i] + BIAS) >> 1;
23 #define BASE1 ((SIGNEDNESS int) -1 < 0 ? -126 : 4)
24 #define BASE2 ((SIGNEDNESS int) -1 < 0 ? -101 : 26)
26 int
27 main (void)
29 check_vect ();
31 SIGNEDNESS char a[N], b[N], c[N];
32 for (int i = 0; i < N; ++i)
34 b[i] = BASE1 + i * 5;
35 c[i] = BASE2 + i * 4;
36 asm volatile ("" ::: "memory");
38 f (a, b, c);
39 #pragma GCC novector
40 for (int i = 0; i < N; ++i)
41 if (a[i] != ((BASE1 + BASE2 + i * 9 + BIAS) >> 1))
42 __builtin_abort ();
43 return 0;
46 /* { dg-final { scan-tree-dump "vect_recog_average_pattern: detected" "vect" } } */
47 /* { dg-final { scan-tree-dump {\.AVG_FLOOR} "vect" { target vect_avg_qi } } } */
48 /* { dg-final { scan-tree-dump-not {vector\([^\n]*short} "optimized" { target vect_avg_qi } } } */
49 /* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" { target vect_avg_qi } } } */