Optimisation: What is Bounds-Checking Elimination

Bounds-Checking Elimination is the process of removing redundant or unneeded bounds checking from array accesses.

Whenever you read or write from an array there should be a bounds check to ensure that you are in a legal and assigned area of memory. If you were to read from an array, permute the value and write back this would cause two bounds checks to take place - one for the read and one for the write. The simplest form of bounds checking elimination is to remove the second bounds check. If you are working under the assumption that the memory cannot be unassigned during the permutation process then the address that read from should still be value as an address to write back to.

This technique can be applied to more complex cases where the range of access indices is known and the array being accessed is contiguous. In these situations it possible to verify that all accesses will be within a valid range at the start and then all accesses within that code will not need to be bounds tested.

The more complex the memory access pattern the more difficult this optimisation becomes for it be applied in a guaranteed safe manner.