Expression Simplification

Some expressions can be simplified by replacing them with an equivalent expression that is more efficient.

Example:

The code fragment below contains several examples of expressions that can be simplified.

void f (int i)
{
  a[0] = i + 0;
  a[1] = i * 0;
  a[2] = i - i;
  a[3] = 1 + i + 1;
}
  

Below is the code fragment after expression simplification.

void f (int i)
{
  a[0] = i;
  a[1] = 0;
  a[2] = 0;
  a[3] = 2 + i;
}
  

Notes:

Programmers generally do not write expressions like (i + 0) directly, but these expressions can be introduced after macro expansion, array index arithmetic expansion, and other optimizations.