3 Common subexpression elimination
7 The Common Subexpression Elimination optimization technique (CS)
8 tries to eliminate multiple computations of EM expressions
9 that yield the same result.
10 It places the result of one such computation
11 in a temporary variable,
12 and replaces the other computations by a reference
13 to this temporary variable.
14 The primary goal of this technique is to decrease
15 the execution time of the program,
16 but in general it will save space too.
18 As an example of the application of Common Subexpression Elimination,
19 consider the piece of program in Fig. 7.1(a).
23 x := a * b; TMP := a * b; x := a * b;
25 y := c + a * b; CODE y := x;
31 Fig. 7.1 Examples of Common Subexpression Elimination
33 If neither a nor b is changed in CODE,
34 the instructions can be replaced by those of Fig. 7.1(b),
35 which saves one multiplication,
36 but costs an extra store instruction.
37 If the value of x is not changed in CODE either,
38 the instructions can be replaced by those of Fig. 7.1(c).
40 the extra store is not needed.
42 In the following sections we will describe
43 which transformations are done
44 by CS and how this phase