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!mhuxr!mhuxn!ihnp4!qantel!dual!lll-crg!gymble!umcp-cs!cvl!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 (with fix?) Message-ID: <5220@elsie.UUCP> Date: Thu, 12-Sep-85 15:22:50 EDT Article-I.D.: elsie.5220 Posted: Thu Sep 12 15:22:50 1985 Date-Received: Sun, 15-Sep-85 09:38:36 EDT References: <5216@elsie.UUCP> <1492@umcp-cs.UUCP> Organization: NIH-LEC, Bethesda, MD Lines: 59 Keywords: C optimizer Summary: A possible fix (with a tip of the hat to umcp-cs!chris) Index: src/lib/pcc/code.c Fix Description: The 4.?BSD C compiler and optimizer can fail to produce optimized code for expressions that appear just before a value-free "return". Repeat-By: Compile this source a la "cc -S -O": one(i, j, k) { i = j * k; dummy(); } two(i, j, k) { dummy(); i = j * k; } ...and note the differences in the code produced for the two functions. Fix: The fix involves changing two files. As usual, the trade secret status of the code involved precludes a clearer posting. The idea was suggested by umcp-cs!chris. Change the indicated line in "pcc/code.c": #ifdef OLDVERSION printf( " ret\n" ); #else if ((retstat & RETVAL) == 0) printf("\tret\t# return;\n"); else printf("\tret\n"); #endif ...and make this change to "c2/c21.c": #ifdef OLDVERSION if (p->subop==RET || p->subop==RSB) {uses[0]=p; regs[0][0]= -1; break;} #else if (p->subop == RET || p->subop == RSB) { if (p->code == 0 || !equstr(p->code, "# return;")) uses[0] = p; regs[0][0] = -1; break; } #endif Of course I'm no wizard, so you may want to await the verdict of other readers of net.bugs.4bsd before making this change. -- C is a Mel Blanc/Jack Benny trademark. -- UUCP: ..decvax!seismo!elsie!ado ARPA: elsie!ado@seismo.ARPA DEC, VAX and Elsie are Digital Equipment and Borden trademarks