Richard Biener wrote:
> On Tue, Aug 15, 2017 at 4:11 PM, Wilco Dijkstra <wilco.dijks...@arm.com> 
> wrote:
> > Richard Biener wrote:
>>> > We also change the association of
>>> >
>>> >      x / (y * C) -> (x / C) / y
>>> >
>>> > If C is a constant.
>>>
>>> Why's that profitable?
>>
>> It enables (x * C1) / (y * C2) -> (x * C1/C2) / y for example.
>> Also 1/y is now available to the reciprocal optimization, see
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71026 for details.
>
> Sure, but on its own it's going to be slower.  So this isn't the
> correct way to enable those followup transforms.

How can it be any slower? It's one division and one multiply in both cases.

>>> >   x / (- y) -> (-x) / y
>>>
>>> Why?  (it's only one of the possible canonicalizations)
>>
>> Same here, y is now available for reciprocal optimization. The
>> negate may now be optimized, for example (a * b) / -y -> (-a*b) / y
>> will use a negated multiple on various targets.
>
> Fair enough.  Though if it were x / -(a*b) you'd regress that case.

Possibly. You might still be able to merge the negate if the result is used in 
an
addition or multiply, which wouldn't be possible if it were hiding in a 
subexpression.
Without global analysis it seems best to move constants/negates to the toplevel
if they can't be trivially removed in a subexpression. Eg. -x / (a * b * -c).

Wilco

Reply via email to