Local Common Subexpression Elimination

Local Common Strength Reduction

Local Constant Propagation and Folding

Algebraic Identities

10.1.3 Local Common Subexpression Elimination

Constants 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

... ...

T1 := 4 * I T1 := 4 * 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 := 2

... ...

T1 := 4 * I T1 := 8

Constant 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.