x = 7;
y = 2 * 7;
z = f (7, y);
We notice that the right-hand side of the assignment in the second line
is an expression containing only constant values. The result of this
expression is constant and has the value 2 * 7 = 14.
The expression can therefore be substituted by the constant value
14. The reduced source program is the following:
x = 7;
y = 14;
z = f (7, y);
The same can be applied to more complex expressions, containing
arithmetic, bitwise, relational or logical operations.
It is not coincidental that we used as an example the reduced program from our previous example on constant propagation. When constant values replace instances of variables, it is very probable that some expressions will only contain constant values. These expressions can be evaluated.
Furthermore, expression simplification yields new constant values. In the example given above, the variable y is now known to have the constant value 14. This value can be propagated in the third line of the example. Thus, we notice a dynamic cooperation between constant propagation and expression simplification: the one is created but also creates the other.
This page is maintained by Nikos Papaspyrou.
Last updated: Monday May 15 1995, 12:05 EET DST.