[comp.bugs.sys5] DMD C optimizer bug fixes

gwyn@brl-smoke.UUCP (04/11/87)

More bug fixes and improvements for 5620 DMD 1.3 (M32) SGS optim:

*** $DMDSGS/sgs/mac/common/ofc/optim/optim.c	Fri Apr 10 09:49:58 1987
--- $DMDSGS/sgs/mac/common/ofc/optim/optim.c	Sat Apr 11 15:54:36 1987
***************
*** 114,114
! #define FLAG(L, LFLAG)	case 'L': LFLAG = -1; continue;
--- 114,114 -----
! #define FLAG(L, LFLAG)	case 'L': LFLAG = -1; continue;	/* DAG -- WARNING: Reiserism */
***************
*** 119,119
! 			    CC, fnum, npass)
--- 119,119 -----
! 			    CC, fnum, npass)		/* DAG -- WARNING: Reiserism */
***************
*** 447,447
^	 * that prinst() will convert "jbr NULL" back to "ret";
--- 447,448 -----
^	 * that prinst() will convert "jbr NULL" back to "ret";
+ 	DAG -- 3B version doesn't do this; is it really a problem?
***************
*** 576,576
! 	   same(pi, pj) == true; length++) {
--- 577,577 -----
! 	   same(pi, pj); length++) {	/* DAG -- removed redundant == true */

*** $DMDSGS/sgs/mac/common/ofc/optim/optim.h	Mon Feb  9 06:10:30 1987
--- $DMDSGS/sgs/mac/common/ofc/optim/optim.h	Sat Apr 11 15:57:32 1987
***************
*** 130,130
! #define COPY(str, len)	((len) != 0 ? memcpy(getspace(len), str, (int)(len)) : str)
--- 130,130 -----
! #define COPY(str, len)	((len) != 0 ? memcpy(getspace(len), str, (int)(len)) : (str))	/* DAG -- added parens */

*** $DMDSGS/sgs/mac/3b/ofc/optim/defs	Fri Apr 10 23:59:59 1987
--- $DMDSGS/sgs/mac/3b/ofc/optim/defs	Sat Apr 11 15:57:32 1987
***************
*** 183,189
! # define islabel(p) (p != NULL && (p->op == LABEL || p->op == HLABEL))
! # define ishl(p) (p->opcode[0] != '.' || p->op == HLABEL)
! # define isuncbr(p) (JMP <= p->op && p->op <= SWITCHT)
! # define iscbr(p) (p->op >= JZ && p->op <= JGEU)
! # define isbr(p) (p->op >= JMP && p->op <= JBS && p->op != CALL)
  # ifdef N3B
! # define ishb(p) (p->op == RET)
--- 183,190 -----
+ /* DAG -- added parens in following macro bodies: */
! # define islabel(p) ((p) != NULL && ((p)->op == LABEL || (p)->op == HLABEL))
! # define ishl(p) ((p)->opcode[0] != '.' || (p)->op == HLABEL)
! # define isuncbr(p) (JMP <= (p)->op && (p)->op <= SWITCHT)
! # define iscbr(p) ((p)->op >= JZ && (p)->op <= JGEU)
! # define isbr(p) ((p)->op >= JMP && (p)->op <= JBS && (p)->op != CALL)
  # ifdef N3B
! # define ishb(p) ((p)->op == RET)
***************
*** 193,197
! # define isrev(p) (p->op >= JZ && p->op <= JBS)
! # define isret(p) (p->op == RET)
! # define iscompare(p) (p->op == CMPW || p->op == CMPB || p->op == CMPH)
! # define setlab(p) (p->op = LABEL)
! # define setbr(p,l) {p->op = JMP; p->opcode = "jmp"; p->op1 = l;}
--- 194,198 -----
! # define isrev(p) ((p)->op >= JZ && (p)->op <= JBS)
! # define isret(p) ((p)->op == RET)
! # define iscompare(p) ((p)->op == CMPW || (p)->op == CMPB || (p)->op == CMPH)
! # define setlab(p) ((p)->op = LABEL)
! # define setbr(p,l) {(p)->op = JMP; (p)->opcode = "jmp"; (p)->op1 = (l);}

*** $DMDSGS/sgs/mac/3b/ofc/optim/local.c	Fri Apr 10 23:59:59 1987
--- $DMDSGS/sgs/mac/3b/ofc/optim/local.c	Sat Apr 11 15:57:32 1987
***************
*** 544,544
! 		lineno = lineno * 10 + *str - '0';
--- 544,544 -----
! 		lineno = lineno * 10 + (*str - '0');	/* DAG -- added parens */
***************
*** 598,599
	if( stmpfile == NULL )
		stmpfile = tmpopen();
--- 598,601 -----
	if( stmpfile == NULL )
		stmpfile = tmpopen();
+ 	if( stmpfile == NULL )
+ 		FATAL("can't open temp file\n");	/* DAG -- added safety check */

*** $DMDSGS/sgs/mac/3b/ofc/optim/w2opt.c	Fri Apr 10 23:59:59 1987
--- $DMDSGS/sgs/mac/3b/ofc/optim/w2opt.c	Sat Apr 11 15:57:32 1987
***************
*** 165,165
	&&  strcmp(dst(pf),pl->op1) == 0
--- 165,166 -----
+ 	&&  dst(pf)	/* DAG -- bug fix (added safety check) */
	&&  strcmp(dst(pf),pl->op1) == 0
***************
*** 512,512
--- 513,513 -----
! 	f = ( isdead(reg,pl) || strcmp(dst(pl),reg) == 0 );
---
! 	f = ( isdead(reg,pl) || dst(pl) && strcmp(dst(pl),reg) == 0 );	/* DAG -- bug fix (added safety check) */
***************
*** 1210,1210
--- 1211,1211 -----
! 	    (cop1 == ADDW2 || cop2 == SUBW2)
---
! 	    (cop1 == ADDW2 || cop1 == SUBW2)	/* DAG -- bug fix (second cop1 was cop2) */

*** $DMDSGS/sgs/mac/3b/ofc/optim/w3opt.c	Fri Apr 10 23:59:59 1987
--- $DMDSGS/sgs/mac/3b/ofc/optim/w3opt.c	Sat Apr 11 15:57:32 1987
***************
*** 106,106
	&&  strcmp(dst(pf),pm->op1) == 0
--- 106,107 -----
+ 	&&  dst(pf)	/* DAG -- bug fix (added safety check) */
	&&  strcmp(dst(pf),pm->op1) == 0