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

            Bug ID: 66718
           Summary: Non-invariant ADDR_EXPR not vectorized
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
                CC: mpolacek at gcc dot gnu.org, rguenth at gcc dot gnu.org
  Target Milestone: ---

E.g. on:
int *a[1024], b[1024];
struct S { int u, v, w, x; };
struct S c[1024];

void
f0 (void)
{
  for (int i = 0; i < 1024; i++)
    a[i] = &b[0];
}

void
f1 (void)
{
  for (int i = 0; i < 1024; i++)
    {
      int *p = &b[0];
      a[i] = p + i;
    }
}

void
f2 (int *p)
{
  for (int i = 0; i < 1024; i++)
    a[i] = &p[i];
}

void
f3 (void)
{
  for (int i = 0; i < 1024; i++)
    a[i] = &b[i];
}

void
f4 (void)
{
  int *p = &c[0].v;
  for (int i = 0; i < 1024; i++)
    a[i] = &p[4 * i];
}

void
f5 (void)
{
  for (int i = 0; i < 1024; i++)
    a[i] = &c[i].v;
}

with -O3 -mavx2 we vectorize only the loops where the address computation has
been lowered (f1, f2, f4) or is address of invariant (f0), but the vectorizer
is not able to vectorize ADDR_EXPR of non-invariant.

Richard thinks this would be best solved by lowering such ADDR_EXPR
assignments,
somewhere in between the last objsz pass and pre, maybe even before reassoc so
that it can optimize even that.

Reply via email to