In common subexpression elimination, the compiler finds code containing repeated subexpressions and produces modified code in which the subexpressions are evaluated only once. Subexpression elimination is usually done with temporary variables as shown in the following example:
a = b + c * d;
x = c * d / y;
The preceding two lines contain the common subexpression c * d. This code can be modified to evaluate c * d only once; the result is placed in a temporary variable (usually a register):
tmp = c * d;
a = b + tmp;
x = tmp / y;