There are three optimizations that are frequently applied after other optimizations are run. These are cleanup transforms that simplify the internal representation. That they exist, frees the other, more complex optimizations, from caring about the neatness of their own transforms — they can be profligate with resources.
These optimizations are:
- Value Propagation, a more generalized version of Constant Propagation
- Constant Folding, evaluations with constant operands
- Dead Code Elimination, removing unneeded code
Recall that in Intermediate Representation I discussed SSA form and Basic Blocks.
Any one of these optimizations creates new opportunities for the others to do something. Generally one might run these all together, or in a repeat-until-no-change loop.