The expression simplification optimization attempts to replace arithmetic expressions with simpler expressions. Additionally, the compiler also looks for operations in expressions that can be avoided completely without affecting the final outcome of the expression. This optimization reduces size and increases speed.
Controlling expression simplification explains how to control the optimization for expression simplification.
| 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 | There is no pragma to control this optimization. |
| command line | -opt level=1 , -opt level=2 , -opt level=3 , -opt level=4 |
For example, Before expression simplification contains a few assignments to some arithmetic expressions:
void func_from(int* result1, int* result2, int* result3, int* result4,
int x)
{
*result1 = x + 0;
*result2 = x * 2;
*result3 = x - x;
*result4 = 1 + x + 4;
}
After expression simplification shows source code that is equivalent to expression simplification. The compiler has modified these assignments to:
void func_to(int* result1, int* result2, int* result3, int* result4,
int x)
{
*result1 = x;
*result2 = x << 1;
*result3 = 0;
*result4 = 5 + x;
}