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.
The following table explains how to control the optimization for expression simplification.
| Turn control this option from here... | use this setting |
|---|---|
| CodeWarrior IDE | Choose Level 1, Level 2, Level 3, or Level 4 in the Optimization Level settings 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, the following listing 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; }
The following listing 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; }