This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Peephole x86 multiplications by 3, 5 and 9


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]