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

           Summary: Missed data-dependence for (bogus?) reconstructed
                    array-refs
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: rgue...@gcc.gnu.org
            Target: i?86-*-*


We vectorize the following loop, ignoring dependences between c[i] and c[i-1].

unsigned int c[624];
void
bar (void)
{
  unsigned int i;
  for (i = 1; i < 624; ++i)
    /* Obfuscated c[i] = c[i-1] * 2.  */
    *(unsigned int *)((void *)c + (__SIZE_TYPE__)i * 4)
        = *(unsigned int *)((void *)c + ((__SIZE_TYPE__)i +
((__SIZE_TYPE__)-4)/4) * 4) * 2;
}

This is because we re-construct array-refs

<bb 3>:
  # i_17 = PHI <i_12(4), 1(2)>
  # ivtmp.8_21 = PHI <ivtmp.8_20(4), 623(2)>
  D.2689_3 = (long unsigned int) i_17;
  D.2692_7 = D.2689_3 + 1073741823;
  D.2695_10 = MEM[(unsigned int *)&c][D.2692_7]{lb: 0 sz: 4};
  D.2696_11 = D.2695_10 * 2;
  MEM[(unsigned int *)&c][D.2689_3]{lb: 0 sz: 4} = D.2696_11;

and the array index D.2692_7 is out of bounds (but of course the address
computation will make the access wrap into the correct place).

The middle-end happily performs such obfuscation via
fold_plusminus_mult_expr from (i*4 + -4U).
The array-refs are re-built by forwprop.

I'm not sure who is wrong here - bogus constrained interpretation of
array-refs by data dependence analysis or bogus construction of
constrained array-refs from pointer arithmetic.

Executable testcase, x86_64, -O3 -msse2 -m32:

unsigned int c[624];
void __attribute__((noinline))
bar (void)
{
  unsigned int i;
  /* Obfuscated c[i] = c[i-1] * 2.  */
  for (i = 1; i < 624; ++i)
    *(unsigned int *)((void *)c + (__SIZE_TYPE__)i * 4)
        = 2 * *(unsigned int *)((void *)c + ((__SIZE_TYPE__)i +
((__SIZE_TYPE__)-4)/4) * 4);
}
extern void abort (void);
int
main()
{
  unsigned int i, j;
  for (i = 0; i < 624; ++i)
    c[i] = 1;
  bar();
  j = 1;
  for (i = 0; i < 624; ++i)
    {
      if (c[i] != j)
        abort ();
      j = j * 2;
    }
  return 0;
}

Reply via email to