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 += 0
statements in the lines marked (1), (2) and (3) do nothing. The compiler can remove them. - The condition
0 == 0
is 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 == 0
toy == -1
. - The compiler can reduce the expression
(y + 1) - 1
toy
(assuming wraparound overflow semantics) - The expressions
y
andy+1
cannot 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:
“Through all opposition the personal benefits of the reform [dress] [bracketed word in original] have compensated; but had it been mainly sacrifice, the thought of working for the amelioration of women and the elevation of humanity would still have been the beacon-star guiding me on amid all discouragements.”
—Susan Pecker Fowler (18231911)
“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)
“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)