Benefits
Loop-invariant code which has been hoisted out of a loop is executed less often, providing a speedup. Another effect of this transformation is allowing constants to be stored in registers and not having to calculate the address and access the memory (or cache line) at each iteration.
However, if too many variables are created, there will be high register pressure, especially on processors with few registers, like the 32-bit x86. If the compiler runs out of registers, some variables will be spilled. To counteract this, the inverse optimization can be performed, rematerialization.
Read more about this topic: Loop-invariant Code Motion
Famous quotes containing the word benefits:
“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)
“While greedy good-doers, beneficent beasts of prey,
Swarm over their lives enforcing benefits ...”
—Robert Frost (18741963)
“I do seriously believe that if we can measure among the States the benefits resulting from the preservation of the Union, the rebellious States have the larger share. It destroyed an institution that was their destruction. It opened the way for a commercial life that, if they will only embrace it and face the light, means to them a development that shall rival the best attainments of the greatest of our States.”
—Benjamin Harrison (18331901)