This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Peephole x86 multiplications by 3, 5 and 9
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: roger at eyesopen dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 03 May 2004 03:32:16 -0400 (EDT)
- Subject: Re: [PATCH] Peephole x86 multiplications by 3, 5 and 9
- References: <Pine.LNX.4.44.0405021600550.18208-100000@www.eyesopen.com>
Hi Roger,
> GCC decomposes integer multiplications with a constant operand into
> a sequence of add and shift operations, if the constant is visible
> during RTL expansion. However, propagation of constants by the RTL
> optimizers can result with explicit multiplication instructions with
> immediate constant operands.
>
> For example, on i686-pc-linux-gnu, the following source code generates
> an "imul $3, 8(%ebp), %eax" instruction.
>
> int foo(int x)
> {
> int y = 3;
> return x*y;
> }
IMHO, I'd say we have a "bug" in the tree SSA optimizers if we end up
discovering in a RTL optimizer that one of the operands of a
multiplication is constant. (Currently, the tree SSA optimizers do
not do instruction combination among other things done at RTL level,
so it is possible that we are missing opportunities to discover some
constants.)
Currently, the combiner does not seem to convert "a * 2 + a" into
"a * 3". In other words, the combiner does not cancel what the
multiplication expander does, so provided that the tree SSA optimizers
do a good job on constant propagation, your proposed peephole2's may
not trigger at all. (However, we *can* use your patch to detect missed
constant propagation opportunities at RTL level.)
Kazu Hirata