You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify bounds checks for multi-dimensional array accesses
This simplifies the array bounds check code that is emitted for
multi-dimensional array accesses that use "regular" indexing, i.e.
accesses of the form `A[i1,i2,...,iN]` to some `N`-dimensional array
`A`.
For example, with this change, the access `A[i,j,k]` to an array
with the three dimensions `m`, `n` and `o` now leads to bounds checks
that correspond to the following pseudo code:
```
if (i >= m)
out_of_bounds_error();
else if (j >= n)
out_of_bounds_error();
else if (k >= o)
out_of_bounds_error();
```
So far, the following more complicated bounds checks would have been
emitted:
```
if (i >= m)
out_of_bounds_error();
else if (j >= n)
out_of_bounds_error();
else if (((k * n + j) * m + i) >= m * n * o)
out_of_bounds_error();
```
Julia also allows one-dimensional and "partial" linear indexing
(see #14770), i.e. the number of indices used to access an array does
not have to match the actual number of dimensions of the accessed array.
For this case we still have use this old scheme.
One motivation for this change was the following: expressions like
`((k * n + j) * m + i)` are non-affine and Polly would not be able
to analyze them. This change therefore also facilitates Polly's bounds
check elimination logic, which would hoist such checks out of loops
or may remove them entirely where possible.
0 commit comments