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

            Bug ID: 112736
           Summary: vectorizer is introducing out of bounds memory access
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
  Target Milestone: ---

The following function (from gcc.dg/torture/pr68379.c)

  int a, b[3], c[3][5];

  void
  fn1 ()
  {
    int e;
    for (a = 2; a >= 0; a--)
      for (e = 0; e < 4; e++)
        c[a][e] = b[a];
  }

generates out of bound memory access (where the three movdqu instructions read
1, 2, and 3 elements before b) when compiled as -O3 for x86_64:

  fn1:
    movdqu  b-4(%rip), %xmm1
    movdqu  b-8(%rip), %xmm2
    movl    $-1, a(%rip)
    movdqu  b-12(%rip), %xmm3
    pshufd  $255, %xmm1, %xmm0
    movups  %xmm0, c+40(%rip)
    pshufd  $255, %xmm2, %xmm0
    movups  %xmm0, c+20(%rip)
    pshufd  $255, %xmm3, %xmm0
    movaps  %xmm0, c(%rip)
    ret

The vector operations were introduced by the "vect" pass.

Reply via email to