This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Swapping commutable binary expressions
- From: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- To: Geert Bosch <bosch at gnat dot com>
- Cc: Gábor Lóki <alga at rgai dot hu>, gcc-patches at gcc dot gnu dot org
- Date: 22 Mar 2003 00:44:57 +0100
- Subject: Re: Swapping commutable binary expressions
- References: <4353FA90-5BB3-11D7-9722-00039344BF4A@gnat.com>
Geert Bosch <bosch at gnat dot com> writes:
> This is a commonly used optimization in many compilers.
> Usually one evaluates the most complex operand first,
> to keep the number of temporaries required lowest.
>
> For example:
> a + (b + (c + (d + e)))
>
> should be expanded as (postfix notation)
> d e + c + b + a + (requires only one register)
> instead of
> a b c d e + + + +
I'm not quite convinced about that. Actually, I would expect something
like
(a + b) + (c + d) + e
to be fastest, since it can take better advantage of instruction
parallelism.
--
Falk