https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116463

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Tamar Christina from comment #11)
> (In reply to Richard Biener from comment #6)
> > I think
> > 
> >   a - ((b * -c) + (d * -e))  ->  a + (b * c) + (d * e)
> > 
> > is a good simplification to be made, but it's difficult to do this with
> > canonicalization only.  Like a * -b -> -(a * b) as the negate might
> > combine with both other negates down and upstream.  But for
> > a*-b + c * -d it might be more obvious to turn that into
> > -a*b - c*d.
> 
> Yeah, my expectation was that this would be an easier transform to avoid
> the sharing problem we discussed before and that indeed the transform
> looks at the entire chain not just transforming a * -b.
> 
> a*-b + c * -d -> -a*b - c*d
> 
> has the property of still maintaining the FMS and FMNS chains and can
> get further simplified in the above case.
> 
> > 
> > Maybe reassoc can be of help here - IIRC it turns b * -c into
> > b * c * -1, undistribute_ops_list might get that.
> 
> hmm I see, but don't we have a higher chance that folding will just
> fold it back into the multiply?
> 
> For this to work we'd have to do
> 
>   (b * -c) + (d * -e) -> -(b * c + d * e)
> 
> in one transformation no? since I'd imagine
> 
>   (b * c * -1) + (d * e * -1)
> 
> would just be undone by match.pd?

The * -1 is something reassoc does only internally, it then distributes
that back to generate an outer plus or minus.

Note for the x86 testcases there isn't any such simplification opportunity,
but the reassoc heuristics correctly mangle the expression to no longer
match the expected SLP complex patterns.  There's also the re-association
of chains done by SLP discovery itself which could be a problem.

I'd say fixing this fallout is quite low priority at the moment, the
simple cases could be re-associated by reassoc into a recognizable
complex op order but even there it's a bit difficult as the operations
span two "chains" (a multiplication and addition chain) where reassoc
looks at them separately (apart from undistribution).

Reply via email to