Must useless expressions be evaluated?

Steven M. Haflich smh at mit-eddie.UUCP
Sun Oct 16 00:38:46 AEST 1983


I am uneasy about any attempt to make a compiler smarter than a
programmer, but can offhand think of only a couple situations in which
it would not be safe to optimize out an unused computation.  In
particular, Unix autoconfiguration code can determine whether a device
exists by peeking at one of its addresses.  If a trap results, the
device doesn't exist.  How can a clever compiler determine whether an
arbitrary reference might have an expected side effect of a trap?

Some hardware provides for interrupt on certain data fetches, e.g., the
little-used status bit in the PDP11 FPU which causes interrupt when -0
is fetched.  The idea is that the hardware can detect reference to a
variable before it is first set.  (I don't know if Vaxen have a similar
frob.)  I could imagine situations where code might want to probe a
variable using this hardware feature, throwing away the fetched value,
in order that an interrupt not occur many levels deep in an evaluator.

Lastly, a demand-paged program which wants to *attempt* real-time
response to some input might try to touch the pages it expected to
reference (e.g. some big array) to increase the probabilty they will be
in physical memory when needed.

Observe, of course, that all these examples involve explicit or
implicit traps.  C is, after all, a system programming languare, often
likened to (ugh) assemble language, and one should be very careful
about disturbing the clear mapping from C instructions into machine
instructions.

	Steve Haflich
	MIT Experimental Music Studio



More information about the Comp.lang.c mailing list