Merge from mainline
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-reduc-dot-u16.c
blob03db7e0b6a6c55908706b53fc0b33ec53e42c7e4
1 /* { dg-require-effective-target vect_int } */
3 #include <stdarg.h>
4 #include "tree-vect.h"
6 #define N 64
8 #define DOT1 43680
9 #define DOT2 43680
11 unsigned short X[N] __attribute__ ((__aligned__(16)));
12 unsigned short Y[N] __attribute__ ((__aligned__(16)));
14 /* short->short->int dot product.
15 Not detected as a dot-product pattern.
16 Not vectorized due to presence of type-conversions. */
17 unsigned int
18 foo1(int len) {
19 int i;
20 unsigned int result = 0;
21 unsigned short prod;
23 for (i=0; i<len; i++) {
24 prod = X[i] * Y[i];
25 result += prod;
27 return result;
30 /* short->int->int dot product.
31 Currently not detected as a dot-product pattern: the multiplication
32 promotes the ushorts to int, and then the product is promoted to unsigned
33 int for the addition. Which results in an int->unsigned int cast, which
34 since no bits are modified in the cast should be trivially vectorizable. */
35 unsigned int
36 foo2(int len) {
37 int i;
38 unsigned int result = 0;
40 for (i=0; i<len; i++) {
41 result += (X[i] * Y[i]);
43 return result;
47 int main (void)
49 unsigned int dot1, dot2;
50 int i;
52 check_vect ();
54 for (i=0; i<N; i++) {
55 X[i] = i;
56 Y[i] = 64-i;
59 dot1 = foo1 (N);
60 if (dot1 != DOT1)
61 abort ();
63 dot2 = foo2 (N);
64 if (dot2 != DOT2)
65 abort ();
67 return 0;
70 /* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 1 "vect" { xfail *-*-* } } } */
72 /* Once the dot-product pattern is detected in the second loop, we expect
73 that loop to be vectorized on vect_udot_hi targets (targets that support
74 dot-product of unsigned shorts). */
75 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { xfail *-*-* } } } */
77 /* { dg-final { cleanup-tree-dump "vect" } } */