optimization (was Re: volatile)

Barnacle Wes wes at obie.UUCP
Mon Apr 25 06:50:21 AEST 1988


In article <20065 at think.UUCP>, barmar at think.COM (Barry Margolin) writes:
> This is unreasonable, and probably rules out almost all optimizations
> but the simplest peephole optimizations, and even some of them.
> Consider the statements
> 
> 	a = b;
> 	a = b;
> 
> It doesn't take much of a flow analysis to determine that the second
> statement is redundant.  Most peephole optimizers will hack this.
> 
> But my main objection to your blanket statement above is that it
> requires code that ACCIDENTALLY works when unoptimized to continue
> working when optimized.

Aha!  But this code is not always redundant!  I have worked on a
system (admittedly a WEIRD system) that had a particular I/O device
with a 16-bit status register hung off an 8-bit bus.  You accessed the
register by two sucessive reads of the register address, getting the
high byte first and the low byte second.  Guess what?  We never used
any of the bits in the high byte!  So our code basically looked
something like:

	mdmstatus: byte @ address;
	status: word;

	status := word;		! discard first byte
	status := word;		! get second byte
	if (status AND H0020) .....

-- 
    /\              -  "Against Stupidity,  -    {backbones}!
   /\/\  .    /\    -  The Gods Themselves  -  utah-cs!uplherc!
  /    \/ \/\/  \   -   Contend in Vain."   -   sp7040!obie!
 / U i n T e c h \  -       Schiller        -        wes



More information about the Comp.lang.c mailing list