ANSII C, optimization, and "hardware registers"

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Wed Oct 17 09:41:44 AEST 1984


> Well, imagine my surprise when the code generated only did:
> 	1.  loaded the ST_START value into CPU register (byte value actually)
> 	2.  placed the CPU register value into memory (word value)
> 	3.  Did not generate a test instruction, cause the ST_START and
> 		ST_DONE value were identical.
> 
> Now here is the question:
> 1.  Was this legal code generation?
> 2.  Note that this compiler did "simple" optimizations as part of the code
> 	generation. Is this legal?

Step 2 of the generated code was sloppy but legal... incomplete optimization.

Optimizations certainly are legal, but your C compiler needs an escape
to avoid the sort of over-optimization you have described.  Frequently
this is done by testing for references that can be seen at compile time
to be possible "I/O page" addresses and skip optimizations for them.
The given example would not have been detected under this test since the
CSR variable was loaded at run-time, not compile-time.

The ANSI C committee was supposed to be considering this issue; the
BLISS-style "volatile" type modifier was mentioned as one possibility.
(This tells the compiler not to optimize any expression containing
the variable so flagged.)  I don't know the outcome of the discussions.



More information about the Comp.lang.c mailing list