[4bsd-f77 #36] f77 fix for COMMON needs to be extended to EQUIVALENCE

4.2 BSD f77 bug reports 4bsd-f77 at utah-cs.UUCP
Thu Aug 30 09:09:37 AEST 1984


From: Donn Seeley <donn at utah-cs.arpa>

Subject: The f77 fix for COMMON needs to be extended to EQUIVALENCE
Index:	usr.bin/f77/src/f77pass1/optcse.c 4.2BSD

Description:
	The fix given in 4bsd-f77 #18 (<163 at sdchema.UUCP>, titled
	'Revision to common subexpression bug fix in f77') is incomplete
	-- the same problems that occur with common subexpressions and
	COMMON variables also occur with EQUIVALENCEd variables.  This
	bug was observed and fixed by Jerry Berkman at UC Berkeley.

Repeat-By:
	Compile the following program (from Jerry Berkman) with the
	optimizer on:

	----------------------------------------------------------------
	c		sees common subexp where none exists
	      double precision   a0,a1, b0,b1, z0(2),z1(2)
	      double complex     a(2), za0,za1
	      equivalence        (za0,z0(1)),(za1,z1(1)),
	     1                   (a0,z0(1)),(b0,z0(2)), (a1,z1(1)),(b1,z1(2))
		data a/ (1.0d0,2.0d0),      (12.2d0,14.8d0)/
	c
	         za0 = a(1)
	         za1 = a(2)
	         a(1) = dcmplx(a0+a1,b0+b1)
	         a(2) = dcmplx(a0-a1,b0-b1)
		print *, a(1), a(2)
	      end
	----------------------------------------------------------------

	When run, this program prints the following:

	----------------------------------------------------------------
	  (   13.200000000000,   13.200000000000)
	  (  -11.200000000000,  -11.200000000000)
	----------------------------------------------------------------

	But it's supposed to print:

	----------------------------------------------------------------
	  (   13.200000000000,   16.800000000000)
	  (  -11.200000000000,  -12.800000000000)
	----------------------------------------------------------------

Fix:
	The problem is exactly the same as the problem with COMMON
	variables and CSE, except applied to EQUIVALENCEd variables; so
	I will skip the usual tedious explanation and simply present
	the fix.  This fix applies to the routine samebase() in
	f77pass1/optcse.c and must be applied AFTER the earlier fix:

	----------------------------------------------------------------
	*** /tmp/,RCSt1024965	Sun Aug 19 23:41:08 1984
	--- optcse.c	Sat Aug  4 20:39:58 1984
	***************
	*** 404,409
		    case TADDR :  
			if (ep1->addrblock.vstg == ep2->addrblock.vstg) {
			    switch(ep1->addrblock.vstg) {
				case STGCOMMON:
				    if (ep1->addrblock.memno == ep2->addrblock.memno &&
					ISCONST(ep1->addrblock.memoffset) &&

	--- 409,415 -----
		    case TADDR :  
			if (ep1->addrblock.vstg == ep2->addrblock.vstg) {
			    switch(ep1->addrblock.vstg) {
	+ 			case STGEQUIV:
				case STGCOMMON:
				    if (ep1->addrblock.memno == ep2->addrblock.memno &&
					ISCONST(ep1->addrblock.memoffset) &&
	----------------------------------------------------------------

Donn Seeley    University of Utah CS Dept    donn at utah-cs.arpa
40 46' 6"N 111 50' 34"W    (801) 581-5668    decvax!utah-cs!donn



More information about the Comp.bugs.4bsd.ucb-fixes mailing list