We present an extension of field analysis (see [4]) called related field an
alysis which is a general technique for proving relationships between two o
r more fields of an object. We demonstrate the feasibility and applicabilit
y of related field analysis by applying it to the problem of removing array
bounds checks. For array bounds check removal, we define a pair of related
fields to be an integer field and an array field for which the integer fie
ld has a known relationship to the length of the array. This related field
information can then be used to remove array bounds checks from accesses to
the array field. Our results show that related field analysis can remove a
n average of 50% of the dynamic array bounds checks on-a wide range of appl
ications.
We describe the implementation of related field analysis in the Swift optim
izing compiler for Java, as well as the optimizations that exploit the resu
lts of related field analysis.