Guard Elimination

We finished today the guard elimination pass, which is responsible for redundant null check and array bounds check elimination. Since all conditional branches appear as guards in our representation, the guard elimination pass is able to merge and simplify loop conditions and array bounds checks into the minimum amount of necessary checks. Consider the following code example:


int i = 0;
while (i < 5000) {
  a[i++] = 0;
  a[i++] = 0;
}

The resulting intermediate representation (IR) code has 6 implicit guards (two null checks, two lower bounds checks, and two upper bounds checks), and a 7th explicit guard representing the loop condition. The guard elimination pass reduces these to a single check.

Continue reading