the testcase is extracted from coremark cat test.c void matrix_add_const(unsigned int N, short *A, short val) { unsigned int i, j; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { A[i * N + j] += val; } } } gcc failed to vectorize it since there could be wrap for i*N + j, but we can do multi-versioning for it? llvm seems does that. https://godbolt.org/z/Er44ffTE3
Yes, as I said in some other PRs the SCEV framework would need to be extended to track 'assumptions' under which its result would be valid, much like niter analysis does. Currently it simply gives up here. Of course 'assumptions' would need support from quite some mid-stream infrastructure and some way to carry it since currently a SCEV is a tree expression. Thus it's quite some work to do this. The mid-stream users is mostly data dependence analysis. There's effective duplicates of this bug.