On Thu, May 5, 2016 at 5:33 AM, kugan <kugan.vivekanandara...@linaro.org> wrote:
> Hi,
>
> I tried to handle reassoc fails to handle FP division. I think the best way
> to do this is to do like what is done for MINUS_EXPR. I.e, convert the
> RDIV_EXPR to MULT_EXPR by (1/x) early and later in opt_rdiv_with_multiply,
> optimize it.
>
> Here is a patch that passes bootstrap and regression testing on
> x86-64-linux-gnu.
>
> Does this look Ok for trunk?

Implementation-wise I'd rather do opt_rdiv_with_multiply from
optimize_ops_list like
eliminate_plus_minus_pair is implemented.

But then in general I am concerned about not doing sth like reproagate_negates.

That is, this patch will turn a / b into a * (1/b) and I think with
just -freciprocal-math
nothing will turn it back to a / b.  We also may do sth like a * b / c
-> a * (1/c) * b
-> (a / c) * b which is generally undesirable if we are not able to
cancel out sth
due to the change of the FP outcome this generally causes.

So in the end while my suggestion in the PR "works" it may not be something
we want to implement.  Eventually we want to treat divisions as association
barriers unless we can make them cancel out.

I also don't particularly like the way reassoc handles minus/negates
by re-writing
the GIMPLE IL.  I'd very much rather have a op->negate flag (or for reciprocals
op->recip).

With -freciprocal-math we made sure (back in time) that SPEC 2006
doesn't miscompare
when using it, so I'd like to verify that is still the case when doing
sth like with this patch.

Thanks,
Richard.

> Thanks,
> Kugan
>
> gcc/testsuite/ChangeLog:
>
> 2016-05-05  Kugan Vivekanandarajah  <kug...@linaro.org>
>
>         PR middle-end/70841
>         * gcc.dg/tree-ssa/pr70841.c: New test.
>
> gcc/ChangeLog:
>
> 2016-05-05  Kugan Vivekanandarajah  <kug...@linaro.org>
>
>         PR middle-end/70841
>         * tree-ssa-reassoc.c (should_break_up_rdiv): New.
>         (break_up_rdiv): New
>         (break_up_subtract_bb): Call should_break_up_rdiv and break_up_rdiv.
>         (do_reassoc): Rename break_up_subtract_bb to
> break_up_subtract_and_div_bb.
>         (sort_cmp_int): New.
>         (opt_rdiv_with_multiply): New.
>         (reassociate_bb): Call opt_rdiv_with_multiply.
>         (do_reassoc): Renamed called function break_up_subtract_bb to
>         break_up_subtract_and_div_bb.

Reply via email to