http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57223

             Bug #: 57223
           Summary: Auto-vectorization fails for nested multiple loops
                    depending on type of array
    Classification: Unclassified
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: snagaval...@outlook.com


The second nested loop in the following code is not auto-vectorized if test_t
is a floating point type. 

void foo(test_t * d, int n)
{
  int i, j, k;
  for (k=0; k<n; ++k) {
    for (i=0; i<n; ++i) {
      test_t t;
      for (j=0; j<k; ++j) {
        t = d[i*n+k] + d[k*n+j];
        d[i*n+j] = (d[i*n+j] < t) ? d[i*n+j] : t;
      }
      j = k;
      t = d[i*n+k] + d[k*n+j];
      d[i*n+j] = (d[i*n+j] < t) ? d[i*n+j] : t;
      for (j=k+1; j<n; ++j) {
        t = d[i*n+k] + d[k*n+j];
        d[i*n+j] = (d[i*n+j] < t) ? d[i*n+j] : t;
      }
    }
  }
}

However, the following seems to be auto-vectorized for all types.

void foo(test_t * d, int n)
{
  int i, j, k;
  for (k=0; k<n; ++k) {
    for (i=0; i<n; ++i) {
      for (j=0; j<k; ++j) {
        test_t t = d[i*n+k] + d[k*n+j];
        d[i*n+j] = (d[i*n+j] < t) ? d[i*n+j] : t;
      }
      for (j=k; j<n; ++j) {
        test_t t = d[i*n+k] + d[k*n+j];
        d[i*n+j] = (d[i*n+j] < t) ? d[i*n+j] : t;
      }
    }
  }
}

Reply via email to