(more) missed optimizations in pcc

Chris Torek chris at umcp-cs.UUCP
Wed Nov 21 15:12:19 AEST 1984


(Here we go again...)

Index: lib/pcc/local.c 4.2BSD Fix

Description:
	The Vax compiler generates a call to ``urem'' to perform
	unsigned mod (%) operations, even in cases where the result
	is guaranteed to be the same as the result of a mask.  For
	example, ``unsigned u; int i; i = u % 8;'' is such an
	expression.

Repeat-By:
	Examine the compiler output for mod with unsigned LHS.

Fix:
	The same as last time, but with an additional check to ensure
	that the LHS is an unsigned type.

RCS file: RCS/local.c,v
retrieving revision 1.1
diff -c1 -r1.1 local.c
*** /tmp/,RCSt1006868	Tue Nov 20 23:42:52 1984
--- local.c	Tue Nov 20 23:42:32 1984
***************
*** 151,152
  
  	case FLD:

--- 151,163 -----
  
+ 	case MOD:
+ 	case ASG MOD:
+ 		/* convert %(const power of two) to &(mask) */
+ 		/* mod by one is done elsewhere */
+ 		if( ISUNSIGNED(p->in.left->in.type) &&
+ 		    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:

I guess that's the best that can be done, short of using ?: . . . .
-- 
(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