Dead code

This is an old revision of this page, as edited by Dorchard (talk | contribs) at 22:38, 20 October 2008. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Dead code is a computer programming term for code in the source code of a program which is executed but whose result is never used in any other computation.[1] The execution of dead code wastes computation time as its results are never used. Dead code is not equivalent to unreachable code, which is code that can never be executed.

While the result of a dead computation may never be used the dead code may raise exceptions or affect some global state thus removal of such code may change the output of the program and should not be performed. Compiler optimizations are typically conservative in their approach to dead code removal if there is any ambiguity as to whether removal of the dead code will affect the program output.

Example

int f (int x, int y)
{
	int z = x + y;
	return x * y;
}

In the above example the definition of z is never used and is thus dead code and can be removed.

Analysis

Dead code elimination is a form of compiler optimization in which dead code is removed from a program. Dead code analysis can be performed using live variable analysis, a form of

Dead code is a computer programming term for code in the source code of a program which is executed but whose result is never used in any other computation.[2] The execution of dead code wastes computation time as its results are never used. Dead code is not equivalent to unreachable code, which is code that can never be executed.

While the result of a dead computation may never be used the dead code may raise exceptions or affect some global state thus removal of such code may change the output of the program and should not be performed. Compiler optimizations are typically conservative in their approach to dead code removal if there is any ambiguity as to whether removal of the dead code will affect the program output.

Example

int f (int x, int y)
{
	int z = x + y;
	return x * y;
}

In the above example the definition of z is never used and is thus dead code and can be removed.

Analysis

Dead code elimination is a form of compiler optimization in which dead code is removed from a program. Dead code analysis can be performed using live variable analysis, a form of static code analysis and data flow analysis. This is in contrast to unreachable code analysis which is based on control flow analysis.

The dead code elimination technique is in the same class of optimizations as unreachable code elimination and redundant code elimination.

See also

References

The dead code elimination technique is in the same class of optimizations as unreachable code elimination and redundant code elimination.

See also

References

  • Appel, A. W. 1998 Modern Compiler Implementation in Java. Cambridge University Press.