libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-avg-5.c
blob73dcb369c9ec63242f8967f6ec3ac26631407428
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)
21 int tmp1 = b[i] + BIAS;
22 int tmp2 = tmp1 + c[i];
23 a[i] = tmp2 >> 1;
27 #define BASE1 ((SIGNEDNESS int) -1 < 0 ? -126 : 4)
28 #define BASE2 ((SIGNEDNESS int) -1 < 0 ? -101 : 26)
30 int
31 main (void)
33 check_vect ();
35 SIGNEDNESS char a[N], b[N], c[N];
36 for (int i = 0; i < N; ++i)
38 b[i] = BASE1 + i * 5;
39 c[i] = BASE2 + i * 4;
40 asm volatile ("" ::: "memory");
42 f (a, b, c);
43 #pragma GCC novector
44 for (int i = 0; i < N; ++i)
45 if (a[i] != ((BASE1 + BASE2 + i * 9 + BIAS) >> 1))
46 __builtin_abort ();
47 return 0;
50 /* { dg-final { scan-tree-dump "vect_recog_average_pattern: detected" "vect" } } */
51 /* { dg-final { scan-tree-dump {\.AVG_FLOOR} "vect" { target vect_avg_qi } } } */
52 /* { dg-final { scan-tree-dump-not {vector\([^\n]*short} "optimized" { target vect_avg_qi } } } */
53 /* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" { target vect_avg_qi } } } */