GHINSU:   Expression simplification

- What is expression simplification?
- Example of expression simplification
- Uses of expression simplification

What is expression simplification?

Expression simplification is a code reduction technique that replaces an expression with its evaluated result. Of course, this is possible only when an expression contains only constant values.

Example of expression simplification

An example of expression simplification is given below. Consider the following segment of an original source program:
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.

Uses of expression simplification

Again one can argue that the example presented above is oversimplified. Good programmers would have evaluated the constant expression. And even if a good programmer left such an expression (to remind him/her how the result is produced), a good compiler would evaluate it.

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.

What next?

(o) Contents     (o) Constant propagation     (o) Statement simplification

This page is maintained by Nikos Papaspyrou.
Please, feel free to send your comments, thoughts or suggestions to

Last updated: Monday May 15 1995, 12:05 EET DST.