Dead Code Elimination

In compiler theory, Dead code elimination is a technique used to reduce program size by removing code which can never be executed. Consider the following example written in C.
  void foo()  {    int a = 24;    int b = 25;    int c;    c = a << 2;    return;    b = 24;  } 
The variable b is assigned a value after a return statement, which makes it impossible to get to. That is, since code execution is linear, and there is no conditional expression wrapping the return statement, any code after the return statement cannot possibly be executed. (This would not be the case if there were a label after the return statement, which opens the possibility of there being a jump that places execution after the return statement.) Furthermore, if we elimate that assignment, than we can see that the variable b is never used at all, except for its declaration and inital assignment. Depending on the aggressiveness of the optimizer, the variable b might be eliminated entirely from the generated code. Also, even though some calculations are performed in the function, their values are not stored in locations accessible outside the scope of this function. Furthermore, the function does not return a value. Thus, it can be said that the function has no side effects and returns no value, and thus does no work. In that case, a highly aggressive optimizer might reduce this function to nothing more than a return call, or even eliminate it entirely. Most advanced compilers have options to activate dead code elimination, sometimes at varying levels. A lower level might only remove instructions which cannot be executed. A higher level might also not reserve space for unused variables. Yet a higher level might determine instructions or functions that serve no purpose and eliminate them. A common use of dead code elimination is as an alternative to optional code inclusion via a preprocessor. Consider the following code.
  int main() {    int a = 5;    int b = 6;    int c;    c = a * (b >> 1);    if (0) {   /* DEBUG */      printf("%d\n", c);    }    return c;  } 
Because the expression 0 will always evaluate to false, the code inside the if statement can never be executed, and dead code elimination would remove it entirely from the optimized program. This technique is common in debugging to optionally activate blocks of code; using an optimizer with dead code elimination eliminates the need for using a preprocessor to perform the same task.

 

<< PreviousWord BrowserNext >>
spanking the monkey
taihape
list of national poetries
interstate 370
brucie
gumboot day
changi naval base
interstate 670
history of gdansk
honorary degree
peters
white birch
list of people by name: baa baj
john sutherland
interstate 470
stroke order
hugh sykes davies
barotrauma
white faced heron
commission stasi
batemans bay, new south wales
fs richelieu (1935 1967)
building material
rheydt
blue1
vladimir kuts
asahi, yamagata (nishimurayama)
asahi, yamagata (higashitagawa)
tax court of canada
tax court of canada act
eric laithwaite
social cognition
electroacoustic
georg elser
contraindication
landsgemeinde
specials (album)
e.b. ford
fuengirola
butadiene
teresa of leon
uscgc eagle
derek parra
lorraine hansberry