|
10.1.3 Local Common Subexpression EliminationConstants are produced, not only by the programmer, but also by the compiler. The programmer may initialize a variable to be 1, using this as both the loop counter and as an array index. Then, in allocating space for the array, the compiler may multiply such elements by 4 to indicate that they are to use four bytes of storage.
EXAMPLE 3 Local constant propagation
I := 2 I := 2 A related optimization computes constant expressions at compile-time rather than generating code to perform the optimization.
EXAMPLE 4 Local constant folding
I := 2 I := 2Constant folding is sometimes called constant computation. It can require a little more alertness on the part of the compiler, as shown in Example 5.
EXAMPLE 5 Local constant folding
I := 2 * I I := 8 * I (no reference to I) I := 4 * I Here, I has been modified twice.
|