Benefits
Inline expansion itself is an optimization, since it eliminates overhead from calls, but it is much more important as an enabling transformation. That is, once the compiler expands a function body in the context of its call site—often with arguments that may be fixed constants -- it may be able to do a variety of transformations that were not possible before. For example, a conditional branch may turn out to be always true or always false at this particular call site. This in turn may enable dead code elimination, loop-invariant code motion, or induction variable elimination.
In the C example in the previous section, optimization opportunities abound. The compiler may follow this sequence of steps:
- The
temp += 0statements in the lines marked (1), (2) and (3) do nothing. The compiler can remove them. - The condition
0 == 0is always true, so the compiler can replace the line marked (2) with the consequent,temp += 0(which does nothing). - The compiler can rewrite the condition
y+1 == 0toy == -1. - The compiler can reduce the expression
(y + 1) - 1toy(assuming wraparound overflow semantics) - The expressions
yandy+1cannot both equal zero. This lets the compiler eliminate one test.
The new function looks like:
int f(int y) { if (y == 0) return y; /* or return 0 */ else if (y == -1) return y - 1; /* or return -2 */ else return y + y - 1; }Read more about this topic: Inline Expansion
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)
“It is with benefits as with injuries in this respect, that we do not so much weigh the accidental good or evil they do us, as that which they were designed to do us.That is, we consider no part of them so much as their intention.”
—Laurence Sterne (17131768)
“Unfortunately, we cannot rely solely on employers seeing that it is in their self-interest to change the workplace. Since the benefits of family-friendly policies are long-term, they may not be immediately visible or quantifiable; companies tend to look for success in the bottom line. On a deeper level, we are asking those in power to change the rules by which they themselves succeeded and with which they identify.”
—Anne C. Weisberg (20th century)