CPU independent optimization techniques
Last updated
Last updated
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!
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).
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.
It consists of making multiple iterations of the calculations in each iteration of the cycle.
Suitable for short cycles.
Replace a function call with the function code.
Suitable when small functions are called multiple times from a small number of locations.