On 09/13/2017 03:22 AM, Jackson Woodruff wrote:
> On 09/12/2017 11:43 PM, Jeff Law wrote:
>> On 09/06/2017 03:54 AM, Jackson Woodruff wrote:
>>> Hi all,
>>>
>>> This patch is split from part (1/2). It includes the patterns that have
>>> been moved out of fold-const.c
>>>
>>>
>>> It also removes an (almost entirely) redundant pattern:
>>>
>>>      (A / C1) +- (A / C2) -> A * (1 / C1 +- 1 / C2)
>>>
>>> which was only used in special cases, either with combinations
>>> of flags like -fno-reciprocal-math -funsafe-math-optimizations
>>> and cases where C was sNaN, or small enough to result in infinity.
>>>
>>> This pattern is covered by:
>>>
>>>     (A / C1) +- (A / C2) -> (with O1 and reciprocal math)
>>>     A * (1 / C1) +- A * (1 / C2) ->
>>>     A * (1 / C1 +- 1 / C2)
>>>
>>> The previous pattern required funsafe-math-optimizations.
>>>
>>> To adjust for this case, the testcase has been updated to require O1 so
>>> that the optimization is still performed.
>>>
>>>
>>> This pattern is moved verbatim into match.pd:
>>>
>>>      (A / C) +- (B / C) -> (A +- B) / C.
>>>
>>> OK for trunk?
>>>
>>> Jackson
>>>
>>> gcc/
>>>
>>> 2017-08-30  Jackson Woodruff  <jackson.woodr...@arm.com>
>>>
>>>      PR 71026/tree-optimization
>>>      * match.pd: Move RDIV patterns from fold-const.c
>>>      * fold-const.c (distribute_real_division): Removed.
>>>      (fold_binary_loc): Remove calls to distribute_real_divison.
>>>
>>> gcc/testsuite/
>>>
>>> 2017-08-30  Jackson Woodruff  <jackson.woodr...@arm.com>
>>>
>>>      PR 71026/tree-optimization
>>>      * gcc/testsuire/gcc.dg/fold-div-1.c: Use O1.
>>
>> Didn't you lose the case where the operator is MULT_EXPR rather than
>> RDIV_EXPR?
>>
>> If I'm reading things correctly, arg0 and arg1 could be a RDIV_EXPR or a
>> MULT_EXPR and we distribute both cases (as long as they are both the
>> same code). >
>> Your match.pd pattern only handle rdiv.
>>
> 
> In the fold_plusminus_mult_expr function in fold-const.c, we still do
> the simplification:
> 
> (A * C) +- (B * C) -> (A+-B) * C
> 
> So the pattern I introduced only needs to handle the division case.
OK.  I was hoping that we had code elsewhere to handle the MULT case.

> 
>> Now it may be the case that MULT_EXPR doesn't happen anymore in practice
>> -- the code in fold-const is quote old and much of it was written before
>> we regularly added tests for optimization and canonicalization.  So I'm
>> not surprised nothing in this testsuite trips over this omission.
> 
> In gcc.dg/fold-plusmult.c, we test whether 2*a + 2*a is folded into a *
> 4, which comes close.
> 
> There are also a few tests for this in gcc.dg/tree-ssa/pr23294.c,
> although again, they are use constants for A and B.
Great.  Thanks for verifying we've got at least some minimal coverage.

Do you have commit privs?  I'm going to give the patch a final looksie
shortly.

jeff

Reply via email to