Dead Code Elimination

The dead code elimination optimization removes expressions that are not accessible or are not referred to. This optimization reduces size and increases execution speed.

Controlling dead code elimination explains how to control the optimization for dead code elimination.

Table 1. Controlling dead code elimination
Turn control this option from here... use this setting
CodeWarrior IDE Choose an Optimization Level value (1,2,3,4) from the Properties > C/C++ Build > Settings > Tool Settings > PowerPC Compiler > Optimization panel.
source code #pragma opt_dead_code on | off | reset
command line -opt [no]deadcode

In Before dead code elimination , the call to func1() will never execute because the if statement that it is associated with will never be true. Consequently, the compiler can safely eliminate the call to func1() , as shown in After dead code elimination .

Figure 1. Before dead code elimination
void func_from(void)
{
    if (0)
    {
        func1();
    }
    func2();
}
Figure 2. After dead code elimination
void func_to(void)
{
    func2();
}