Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Simplify bounds checks for multi-dimensional array accesses #18064

Merged
merged 1 commit into from
Aug 23, 2016

Commits on Aug 19, 2016

  1. 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 JuliaLang#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.
    MatthiasJReisinger committed Aug 19, 2016
    Configuration menu
    Copy the full SHA
    9f531d9 View commit details
    Browse the repository at this point in the history