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

Zhiyang Chen <jeffchen006 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jeffchen006 at gmail dot com

--- Comment #1 from Zhiyang Chen <jeffchen006 at gmail dot com> ---
The same problem on x86-64 with plain C and plain -O3 (no target flags):

int printf(const char *, ...);
void *calloc(unsigned long, unsigned long);
struct C { float f0, f1; int i, j; };
int x = 1;
int main(void) {
  char *b = (char *)calloc(10, 16) + 16;
  for (int k = 0; k < (x & 3) + 1; k++) {
    *(long *)(b + 16 * (2 - k)) = *(long *)(b + 16 * 3);
    *(struct C *)(b + 16 * (5 + k)) = (struct C){ 0, 0, 0, 0 };
    *(long *)(b + 16 * (3 + k)) = 3;
  }
  printf("%d\n", b[16]);
}

$ gcc -O2 t.c && ./a.out
3
$ gcc -O3 t.c && ./a.out
0

Expected 3: k runs 0 and 1; at k = 0 the loop stores 3 at b + 48, and at
k = 1 the load of b + 48 must see it. 14.3 is correct; 15.2, 16.2 and trunk
are wrong. -fno-tree-loop-vectorize gives 3. gcc -Wall -Wextra gives no
warnings; -fno-strict-aliasing -fwrapv does not change the output.

-fdump-tree-vect-details shows the same mechanism as in this PR:

  vectorization factor = 1
  no need for alias check between MEM[(long int *)_1 + 64B] and MEM[(long int
*)_5] when VF is 1
  hoisting out of the vectorized loop: _6 = MEM[(long int *)_1 + 64B];

The alias check between the invariant load and the long store is dropped
under the VF == 1 rule, and vectorizable_load then hoists the VMAT_INVARIANT
load into the preheader, although the store in iteration 0 writes the address
that iteration 1 reads.

The same mechanism is in PR128753 (x86-64); the original test here also
fails on x86-64 (at -O2 and -O3).

Reply via email to