[PATCH, PR40815] Remove redundant negate

Richard Guenther richard.guenther@gmail.com
Mon Mar 15 12:34:00 GMT 2010


On Mon, Mar 15, 2010 at 12:42 PM, Maxim Kuvyrkov <maxim@codesourcery.com> wrote:
> The following patch fixes <http://gcc.gnu.org/PR40815>.
>
> The problem is in `a + (-b)' expression surviving till expand and then (-b)
> being hoisted out of the loop, which inhibits combiner from optimizing the
> sequence to `a - b'.  So, instead of
>
> <loop>:
>  c = a - b
>  ...
>
> the code becomes (on ARM)
>
>  reg = -b
> <loop>:
>  c = a + reg
>  ...
>
> This wastes an instruction and a register.
>
> As Richard G. pointed out in the PR, the problem can be fixed in the tree
> re-association pass.
>
> One of the things that re-association pass does is breaking up subtacts into
> plus-negate pairs, then optimizing expressions, and then reassembling
> plus-negate pairs [the ones that were not optimized] back into subtracts.
>  Unfortunately, the pass only reassembles the plus-negate pairs that it
> itself has created and does not handle the pairs that were already present.
>  The reassembly takes place in repropagate_negates() and it uses a list of
> trees constructed while breaking up the pairs.
>
> The attached patch fixes the problem by moving the action of adding the
> elements to the list, that repropagate_negates() will process, to a better
> location.  Population of the list for repropagate_negates() now piggy-backs
> eliminate_plus_minus_pair().  As far as I understand, all potential cases,
> that repropogate_negates() can optimize, pass through this point.
>
> Bootstrap and testing of the all default languages on x86_64-linux-gnu did
> not detect a single expression that was missing from the list for
> repropagate_negates() compared to the original place where elements were
> added.
>
> Bootstrapped and regtested on x86_64-linux-gnu with no regressions. Fixes
> the ARM testcase too.
>
> OK for 4.6?

Ok if you add a testcase along gcc.dg/tree-ssa/reassoc-*.c.

Thanks,
Richard.

> --
> Maxim Kuvyrkov
> CodeSourcery
> maxim@codesourcery.com
> (650) 331-3385 x724
>



More information about the Gcc-patches mailing list