PR tree-optimization/84740
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-reduc-sad.c
blob2d8bc7c86014f17e3c89c98a9ff3dfef6b0b275e
1 /* { dg-require-effective-target vect_usad_char } */
3 #include <stdarg.h>
4 #include "tree-vect.h"
6 #define N 64
7 #define SAD N*N/2
9 unsigned char X[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__)));
10 unsigned char Y[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__)));
11 int abs (int);
13 /* Sum of absolute differences between arrays of unsigned char types.
14 Detected as a sad pattern.
15 Vectorized on targets that support sad for unsigned chars. */
17 __attribute__ ((noinline)) int
18 foo (int len)
20 int i;
21 int result = 0;
23 for (i = 0; i < len; i++)
24 result += abs (X[i] - Y[i]);
26 return result;
30 int
31 main (void)
33 int i;
34 int sad;
36 check_vect ();
38 for (i = 0; i < N; i++)
40 X[i] = i;
41 Y[i] = N - i;
42 __asm__ volatile ("");
45 sad = foo (N);
46 if (sad != SAD)
47 abort ();
49 return 0;
52 /* { dg-final { scan-tree-dump-times "vect_recog_sad_pattern: detected" 1 "vect" } } */
53 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */