From: | Peter-Lawrence.Montgomery@cwi.nl (Peter L. Montgomery) |
Newsgroups: | comp.compilers |
Date: | 29 Jan 1996 00:30:44 -0500 |
Organization: | CWI, Amsterdam |
References: | 96-01-088 |
Keywords: | arithmetic, optimize |
hbaker@netcom.com (Henry G. Baker) writes:
>[an alleged optimization computes a/b and a%b with a single divide if both
>appear in a program]
>I can imagine how such an optimization would be done, but I can't
>imagine many other places -- except for possibly keeping track of a
>shifted out carry bit in a shift operation, or gathering both the high
>order and low order bits of a double-precision integer multiplication
>-- where such an optimization would be used.
Some other places where two expressions should be evaluated together:
a) The maximum and minimum of the same two arguments.
[P.s. If your system has #define max(x, y) ((x) > (y) : (x) : (y))
in a header file, then the definition of min(x, y) should
be ((x) > (y) ? (y) : (x)) to facilitate recognition
of the common subexpression (x) > (y) and allow the optimizer
to generate one if-then-else.]
b) The sine and cosine of the same argument. If sin(theta)
and cos(theta) generate library calls, then any basic block
referencing both functions should instead call a routine
which evaluates both functions while doing common
calculations such as range reduction only once.
c) When there are two relationals on the same two operands.
For example, the code
if (x > y) {
...
} else if (x < y) {
...
}
should generate only one compare, whatever the types of x and y.
--
Peter L. Montgomery pmontgom@cwi.nl San Rafael, California
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.