https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102564
Bug ID: 102564 Summary: Missed loop vectorization with reduction and ptr load/store inside loop Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: david.bolvansky at gmail dot com Target Milestone: --- void test1(int *p, int *t, int N) { for (int i = 0; i != N; i++) *t += p[i]; } void test2(int *p, int *t, int N) { if (N > 1024) // hint, N is not small for (int i = 0; i != N; i++) *t += p[i]; } void test3(int *p, int *t, int N) { if (N > 1024) { // hint, N is not small int s = 0; for (int i = 0; i != N; i++) s += p[i]; *t += s; } } test3 is successfully vectorized with LLVM, GCC, ICC. Sadly, only ICC can catch test1 and test2. https://godbolt.org/z/PzoYd4eEK