Auto-vectorization of dot-product

Ira Rosen IRAR@il.ibm.com
Mon Mar 31 05:49:00 GMT 2008



gcc-help-owner@gcc.gnu.org wrote on 30/03/2008 15:01:59:

> Hi,
>
> I have a simple implementation of a dot-product:
>
> inline double dot(int dim,
>                   double const * __restrict x,
>                   double const * __restrict y)
> {
>    double sum = 0.0;
>    for (int i = 0; i < dim; ++i) {
>       sum += x[i] * y[i];
>    }
>    return sum;
> }
>
> Although the Auto-vectorization site
> http://gcc.gnu.org/projects/tree-ssa/vectorization.html mentions that GCC

> supports auto-vectorization of the dot-product, I get the following
> information from GCC 4.3
>
> dot.C:63: note: not vectorized: unsupported use in stmt.
>
> Other simpler loops get vectorized.
>
> What could be wrong?

The types. To vectorize dot-product the vectorizer looks for a specific
pattern. Here is how it is explained in tree-vect-patterns.c:

   Try to find the following pattern:

     type x_t, y_t;
     TYPE1 prod;
     TYPE2 sum = init;
   loop:
     sum_0 = phi <init, sum_1>
     S1  x_t = ...
     S2  y_t = ...
     S3  x_T = (TYPE1) x_t;
     S4  y_T = (TYPE1) y_t;
     S5  prod = x_T * y_T;;
     [S6  prod = (TYPE2) prod;  #optional]
     S7  sum_1 = prod + sum_0;

   where 'TYPE1' is exactly double the size of type 'type', and 'TYPE2' is
the
   same size of 'TYPE1' or bigger. This is a special case of a reduction
   computation.


You are welcome to open a missed-optimization PR in GCC Bugzilla.

Ira

>
> Christoph



More information about the Gcc-help mailing list