Benefits
The benefits of performing CSE are great enough that it is a commonly used optimization.
In simple cases like in the example above, programmers may manually eliminate the duplicate expressions while writing the code. The greatest source of CSEs are intermediate code sequences generated by the compiler, such as for array indexing calculations, where it is not possible for the developer to manually intervene. In some cases language features may create many duplicate expressions. For instance, C macros, where macro expansions may result in common subexpressions not apparent in the original source code.
Compilers need to be judicious about the number of temporaries created to hold values. An excessive number of temporary values creates register pressure possibly resulting in spilling registers to memory, which may take longer than simply recomputing an arithmetic result when it is needed.
Read more about this topic: Common Subexpression Elimination
Famous quotes containing the word benefits:
“One of the benefits of a college education is, to show the boy its little avail.”
—Ralph Waldo Emerson (18031882)
“It is too late in the century for women who have received the benefits of co-education in schools and colleges, and who bear their full share in the worlds work, not to care who make the laws, who expound and who administer them.”
—J. Ellen Foster (18401910)
“When your parents are in political life, you arent normal. Everybody talks about the benefits, but I dont know what the benefits are.... But Id rather have that kind of mother than an overweight housewife.”
—Katherine Berman Mariano (b. 1957)