ado@elsie.UUCP (Arthur David Olson) (09/06/85)
Today's quiz: which of these two functions results in more
code after they've been run through the 4.?BSD optimizer:
one(i, j, k) two(i, j, k)
{ {
i = j * k; dummy();
dummy(); i = j * k;
} }
The answer: you get more code out of "two". Here are the results:
_one:.word L12 _two:.word L18
mull3 12(ap),8(ap),4(ap) calls $0,_dummy
calls $0,_dummy mull3 12(ap),8(ap),r0
ret movl r0,4(ap)
ret
And here's the explanation: in the second case, the optimizer sees that
something's been put in register zero and then there's a return, so
the optimizer figures that the thing put in register zero is a return value
(rather than a temporary value, as it is in this instance) and decides it
had best be left alone.
Has anybody out there figured out how to get better results in situations such
as this?
--
Bugs is a Warner Brothers trademark.
--
UUCP: ..decvax!seismo!elsie!ado ARPA: elsie!ado@seismo.ARPA
DEC, VAX and Elsie are Digital Equipment and Borden trademarks
chris@umcp-cs.UUCP (Chris Torek) (09/06/85)
Probably the simplest way to fix this would be to get some aid from the compiler. The compiler knows when an expression is complete and the value no longer needed; if it dumped a comment into the assembly file, c2 could pick that up and know that r0 was no longer "live". Of course, the *best* way to fix it would probably be to use a real optimizing compiler.... -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland