Dead Code Elimination

Code that is unreachable or that does not affect the program (e.g. dead stores) can be eliminated.

Example:

In the example below, the value assigned to i is never used, and the dead store can be eliminated. The first assignment to global is dead, and the third assignment to global is unreachable; both can be eliminated.

int global;
void f ()
{
  int i;
  i = 1;          /* dead store */
  global = 1;     /* dead store */
  global = 2;
  return;
  global = 3;     /* unreachable */
}
  

Below is the code fragment after dead code elimination.

int global;
void f ()
{
  global = 2;
  return;
}