[comp.unix.wizards] C optimizer

mouse@mcgill-vision.UUCP (der Mouse) (03/07/89)

In article <1028@frog.UUCP>, john@frog.UUCP (John Woods) writes:
> In article <3121@ficc.uu.net>, peter@ficc.uu.net (Peter da Silva) writes:
>> Can anyone think of any pure system calls? ioctl(fd, TCGETA, tbuf)?

This really belongs in an OS-specific group.

Let's see....I just ran through the table of syscalls on this system
and getpagesize() and getdtablesize() are the only really pure syscalls
I see there.

> I think that if
> 	(getpid() != getpid())
> ever evaluated to 1, I would be severely astonished.

Signal handlers aside, that's not the point.  If I write

int pid1;
int pid2;

pid1 = getpid();
runinchild();
pid2 = getpid();

then I don't want the compiler to decide that it can rewrite the second
one to "pid2 = pid1;" because getpid() is pure - presumably
runinchild() will fork.

Here's a quick test: a function is pure if it can be replaced with a
memo-function wrapper without changing the semantics.  This is not true
of getpid() or sync(), to pick two examples that are tempting.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

davidsen@steinmetz.ge.com (William E. Davidsen Jr) (03/09/89)

Our old Heneywell system had a FORTRAN optimizer which would pass over
the source code and emit restructured source code with global
optimizations performed. The main thing it did was pull things out of
loops, I believe, but I haven't used it in ten years or so.

Question: has anyone done a similar thing for C? It seems like a
reasonable thing to do, given all of the non-optimizing and peephole
optimizing compilers in the world.

Yes, I know you can do a better job with a builtin optimizer in the
compiler, that's NOT the question.
-- 
	bill davidsen		(wedu@ge-crd.arpa)
  {uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me