Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site elsie.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!elsie!ado From: ado@elsie.UUCP (Arthur David Olson) Newsgroups: net.bugs.4bsd Subject: 4.?BSD C fails to optimize a function's last expression--who has fix? Message-ID: <5216@elsie.UUCP> Date: Thu, 5-Sep-85 18:13:53 EDT Article-I.D.: elsie.5216 Posted: Thu Sep 5 18:13:53 1985 Date-Received: Sat, 7-Sep-85 05:58:35 EDT Organization: NIH-LEC, Bethesda, MD Lines: 30 Keywords: C optimizer 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