
Translating JVM Code to MIPS Code 225
loop, the expression a[i] is invariant; that is, it is a loop invariant expression. We deal with
these in the next section.
And as we shall see below, there is still much to be gained from common sub-expression
elimination when it comes to dealing with Java arrays.
Lifting Loop Invariant Code
Loop invariant expressions can be lifted out of the loop and computed in the predecessor
block to the loop header.
For example, consider the j-- code for summing the two matrices from the previous
section
5
.
int i = 0;
while (i <= 999) {
int j = 0;
while (j <= 999) {
c[ i ][ j ] = a [ i ][j ] + b [ i ][ j ];
j = j + 1;;
}
i = i + 1