Re: Compiler optimization of division and remainder

Peter-Lawrence.Montgomery@cwi.nl (Peter L. Montgomery)
29 Jan 1996 00:30:44 -0500

          From comp.compilers

Related articles
Compiler optimization of division and remainder hbaker@netcom.com (1996-01-27)
Re: Compiler optimization of division and remainder d.sand@ix.netcom.com (1996-01-27)
Re: Compiler optimization of division and remainder augustss@cs.chalmers.se (1996-01-27)
Re: Compiler optimization of division and remainder richard@atheist.tamu.edu (1996-01-28)
Re: Compiler optimization of division and remainder prener@watson.ibm.com (1996-01-29)
Re: Compiler optimization of division and remainder hbaker@netcom.com (1996-01-29)
Re: Compiler optimization of division and remainder Peter-Lawrence.Montgomery@cwi.nl (1996-01-29)
Re: Compiler optimization of division and remainder johnmce@world.std.com (1996-01-29)
Re: Compiler optimization of division and remainder michael.williams@armltd.co.uk (1996-01-29)
Re: Compiler optimization of division and remainder jgj@ssd.hcsc.com (1996-01-29)
Re: Compiler optimization of division and remainder dave@occl-cam.demon.co.uk (Dave Lloyd) (1996-01-29)
Re: Compiler optimization of division and remainder dave@occl-cam.demon.co.uk (Dave Lloyd) (1996-02-02)
| List of all articles for this month |

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
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.