https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113261

            Bug ID: 113261
           Summary: missing vectorization for dot_prod chain.
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liuhongt at gcc dot gnu.org
            Blocks: 53947
  Target Milestone: ---

int
foo (char* a, char* b, char* c, char* d)
{
    int sum = 0;
    for (int i = 0; i != 32; i++)
    {
        sum += (a[i] * b[i] + c[i] * d[i]);
    }
    return sum;
}


int
foo1 (char* a, char* b, char* c, char* d)
{
    int sum = 0;
    int sum1 = 0;
    for (int i = 0; i != 32; i++)
    {
        sum += a[i] * b[i]
        sum1 += c[i] * d[i];
    }
    return sum + sum1;
}

foo should be same as foo1, but it failed to be optimized to dot_prod_expr
since current vect_recog_dot_prod_pattern only recognize sum += a[i] * b[i];

I think it can be extend to recog dot_prod_expr chain, as long as they're only
used by the final sum reduction.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations

Reply via email to