After cprop is carried out, expressions that really can be calculated at compiletime will be, and are replaced by their values. That is, known functions of known constants are constants, and are recognised as such.
Constant propagation is also able to change conditional branches to unconditional ones. The following code in C can be simplified using cprop:
int a(){ int b; int c; b=3; c=b*4; if(c>10){ c=c-10; } return c; }
A good compiler will reduce this to:
int a(){ return 2; }
Constant propagation can easily be implemented on SSA form as published by Wegman and Zadeck in 1991.
Constant propagation is not to be confused with constant folding, which is implemented in the front-end.
A more advanced form of constantpropagation known as sparse conditional constantpropagation may be utilized to simultaneously remove dead code and more accurately propagateconstants.
Constant folding can be done in a compiler's front end on the IR tree that represents the high-level source language, before it is translated into three-address code, or in the back end, as an adjunct to constantpropagation.
Constantpropagation can also cause conditional branches to simplify to one or more unconditional statements, when the conditional expression can be evaluated to true or false at compile time to determine the only possible outcome.