On Fri, Feb 26, 2016 at 4:02 AM, kugan <kugan.vivekanandara...@linaro.org> wrote: > > > Hi, > > This is an attempt to fix missed optimization: x + (-y * z * z) => x - y * z > * z as reported in PR40921. > > Regression tested and bootstrapped on x86-64-linux-gnu with no new > regressions. > > Is this OK for next stage1?
Err. I think the way you implement that in reassoc is ad-hoc and not related to reassoc at all. In fact what reassoc is missing is to handle -y * z * (-w) * x -> y * x * w * x thus optimize negates as if they were additional * -1 entries in a multiplication chain. And then optimize a single remaining * -1 in the result chain to a negate. Then match.pd handles x + (-y) -> x - y (independent of -frounding-math btw). So no, this isn't ok as-is, IMHO you want to expand the multiplication ops chain pulling in the * -1 ops (if single-use, of course). Richard. > Thanks, > Kugan > > > gcc/ChangeLog: > > 2016-02-26 Kugan Vivekanandarajah <kug...@linaro.org> > > PR middle-end/40921 > * tree-ssa-reassoc.c (propagate_neg_to_sub_or_add): New. > (reassociate_bb): Call propagate_neg_to_sub_or_add. > > > gcc/testsuite/ChangeLog: > > 2016-02-26 Kugan Vivekanandarajah <kug...@linaro.org> > > PR middle-end/40921 > * gcc.dg/tree-ssa/pr40921.c: New test.