(more) missed optimizations in pcc

Chris Torek chris at umcp-cs.UUCP
Sun Nov 18 22:34:03 AEST 1984


Index: lib/pcc/local.c 4.2 Fix

Description:
	The machine dependent expression optimizer doesn't handle
	"%" or "%=" by the constants which are powers of two.  These
	can be done more simply as "&" or "&=".

Repeat-By:
	Feed the following through /lib/ccom; look at the assembly:

		f () {
			register i,j;

			i = j % 3;	/* ok */
			i = j % 4;	/* kinda the long way */
			j %= 3;		/* as above */
			j %= 4;
			i = j % 1;	/* check that previous fix still
					   works */
			j %= 1;
		}

Fix:
	The following changes to local.c make it notice powers of two
	that are greater than 1 and turn the % or %= to an & or &=.

RCS file: RCS/local.c,v
retrieving revision 1.1
diff -c1 -r1.1 local.c
*** /tmp/,RCSt1008635	Sun Nov 18 07:14:20 1984
--- local.c	Sun Nov 18 07:13:55 1984
***************
*** 151,152
  
  	case FLD:

--- 151,162 -----
  
+ 	case MOD:
+ 	case ASG MOD:
+ 		/* convert %(const power of two) to &(mask) */
+ 		/* mod by one is done elsewhere */
+ 		if( nncon( p->in.right ) && ispow2( p->in.right->tn.lval )>0 ){
+ 			p->in.op = p->in.op==MOD ? AND : ASG AND;
+ 			p->in.right->tn.lval--;
+ 		}
+ 		break;
+ 
  	case FLD:
-- 
(This line accidently left nonblank.)

In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



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