Encyclopedia > Constant propagation

  Article Content

Constant propagation

Constant propagation (cprop) is an optimization preformed by compilers. After cprop experssions that can be calculated at compiletime will be replaced by their value. 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;
 }

Easily be implemented on SSA form as published by Wegman and Zadeck in 1991.

Do not confuse constant propagation with constant folding, which is implemented in the front-end.

See also: Control flow graph, Compiler optimization



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Islandia, New York

... 18.8% of all households are made up of individuals and 2.3% have someone living alone who is 65 years of age or older. The average household size is 3.04 and the average ...

 
 
 
This page was created in 23.3 ms