Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site sfmag.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!sfmag!mjs
From: mjs@sfmag.UUCP (M.J.Shannon)
Newsgroups: net.bugs.4bsd
Subject: Re: 4.?BSD C fails to optimize a function's last expression (with fix?)
Message-ID: <695@sfmag.UUCP>
Date: Sun, 15-Sep-85 09:33:29 EDT
Article-I.D.: sfmag.695
Posted: Sun Sep 15 09:33:29 1985
Date-Received: Sun, 15-Sep-85 23:50:35 EDT
References: <5216@elsie.UUCP> <1492@umcp-cs.UUCP> <5220@elsie.UUCP>
Organization: AT&T Information Systems, Summit, NJ
Lines: 49

> 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".
> 
> 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
> 
> 	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado@seismo.ARPA
> 	DEC, VAX and Elsie are Digital Equipment and Borden trademarks

You also have to deal with the case that the function may be returning a
double (which takes r0 & r1).  Once upon a time (in a galaxy far, far away)
I fixed this problem for the AT&T VAX compiler/optimizer.  I have no idea
of the current status of those fixes.  Oh, the return value may also be
a structure, but I don't recal the maximum size that will be returned in
registers.
-- 
	Marty Shannon
UUCP:	ihnp4!attunix!mjs
Phone:	+1 (201) 522 6063
Disclaimer: I speak for no one.