https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49782
--- Comment #3 from Michael Matz <matz at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #2)
> The vectorizer just does not try to ask - it only analyzes dependences of
> the innermost loop where a[j] has invariant address.
Nit: a[i] is the invariant one in the inner loop.
> loop distribution does, and there we hit
>
> (compute_affine_dependence
> ref_a: a[i_17], stmt_a: _1 = a[i_17];
> ref_b: a[j_16], stmt_b: a[j_16] = _2;
> (analyze_overlapping_iterations
> (chrec_a = {0, +, 1}<nw>_1)
> (chrec_b = {0, +, 1}_2)
> (analyze_miv_subscript
> (analyze_subscript_affine_affine
> (overlaps_a = [0 + 1 * x_1])
> (overlaps_b = [0 + 1 * x_1]))
> )
> (overlap_iterations_a = [0 + 1 * x_1])
> (overlap_iterations_b = [0 + 1 * x_1]))
> (Dependence relation cannot be represented by distance vector.)
> )
> consider run-time aliasing test between a[i_17] and a[j_16]
Well, that's correct. There's no distance vector that describes this
dependence. For instance for the read-after-write dependences (from a[j] to
a[i]), we have dependences at iterations (i,j) = (0,0) to (1,0)
(in fact to (*,0)), and from (1,1) to (0,1) (again, actually to (*,1)).
So distances (1,0) and (-1,0). Overall there are forward and backward refs
at each dimension for some iterations, and hence the classic dependence
descriptor is (*,*).
So, considering this as a two-nest there are no sensible classic distances
that can describe this.
In isolation the inner loop has complicated depencences as well: there are
read-after-write dependences from iterations (I) to (I+n), and write-after-read
deps from (n<I) to (I), so also not describable by a classic distance (that
always happens when some access is invariant in the considered nest but does
overlap a different, but variant, access).
I'm not quite sure what this bug is about, which optimization is missed?
(do note that the return value a[0] does depend on all other a[*] eventually)