https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64365
Bug ID: 64365 Summary: Predictive commoning after loop vectorization produces incorrect code. Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: congh at google dot com Compiling the following loop with -O3 on x86-64 produces incorrect code: void foo(int *in) { for (int i = 14; i >= 10; i--) { in[i - 8] -= in[i]; in[i - 5] += in[i] * 2; in[i - 4] += in[i]; } } The incorrect code appears starting from pcom pass. Note that after this loop is vectorized there exists read-after-write data dependence between the second and third statements in the loop. The correct way to get the vector from in[i - 4] in the third statement is reading the memory after the write from the second statement. However, in pcom pass, that vector is actually preloaded before the loop. I think pcom ignores the aliasing between the memory addresses of vector types (in this case MEM[&{in[i-3] : in[i-0]}] and MEM[&{in[i-5] : in[i-1]}].