Optimising AND and OR

Robert Firth firth at sei.cmu.edu
Wed Feb 17 00:25:43 AEST 1988


In article <2303 at umd5.umd.edu> chris at trantor.umd.edu (Chris Torek) writes:

>Without further supporting evidence, I will claim that any optimiser
>could convert
>
>	a = 0 & f();
>
>into
>
>	(void) f(), a = 0

You now have supporting evidence.  I just compiled

	a := 0 & f()

on my old familiar BCPL/Vax compiler, and got out

	BSBW F
	CLRL A

Done by a fairly trivial peephole optimiser, in two steps:

(a) if the operation is commutative, put any constant operand on the right

(b) if the operation is logical-and, and the right operand is zero, the
    result is zero so flush the left operand (naturally that is only one
    of several possible patterns this step will look for)

Your second example needed to be changed, but

	a := f() | <all-ones>

indeed reduces to

	BSBW F
	MCOML #0, A

Hope this helps

----

PS: the stupid program at my site for some reason won't let me post
    followups.  They get bounced back with mailer messages that are (to
    me) incomprehensible.  Is anyone able to offer advice?  It all worked
    in 1987.



More information about the Comp.lang.c mailing list