Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]` where `A` denotes an `N`-dimensional array. For example, with this change, the access `A[i,j,k]` to `A::{Int,m,n,o}` now leads to bounds checking code that corresponds 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 check 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.
- Loading branch information