CPU independent optimization techniques

Elimination of common sub-expressions.

Formally, the occurrence of an expression ”E” is called a common sub-expression if ”E” was previously calculated and the values of the variables in ”E” have not changed since the last calculation of ”E”.

The benefit is obvious: less code to run!

Elimination of “dead code”

If a certain set of instructions is not executed under any circumstances, it is called “dead code” and can be removed.

E.g. replacing the “if” with “#ifdef” allows the compiler to remove debug code at the pre-processing stage (no memory and CPU wasted).

Induction and force reduction variables

An “X” variable is called an “L” cycle induction variable if each time “X” is changed in cycle “L”, it is increased or decreased by a constant value.

  • When there are two or more induction variables in a cycle, it may be possible to remove one of them.

  • Sometimes it is also possible to reduce its “strength”, i.e., its cost of execution.

  • Benefits: lower and/or less costly computations.

Cycle expansion

It consists of making multiple iterations of the calculations in each iteration of the cycle.

Benefits

reduction of overhead due to the cycle

Problems

increased amount of memory

Suitable for short cycles.

Example

Function inlining

Replace a function call with the function code.

Benefits

reduced overhead associated with calling a function.

Problems

(possible) increased code size.

Suitable when small functions are called multiple times from a small number of locations.

Example

Last updated