[PATCH] Fix PR 33512 Folding of x & ((~x) | y) into x & y on the tree level

Richard Guenther richard.guenther@gmail.com
Tue Apr 24 06:00:00 GMT 2012


On Mon, Apr 23, 2012 at 11:21 PM, Andrew Pinski
<andrew.pinski@caviumnetworks.com> wrote:
> On Mon, Apr 23, 2012 at 2:41 AM, Richard Guenther
> <richard.guenther@gmail.com> wrote:
>> On Sat, Apr 21, 2012 at 6:06 AM, Andrew Pinski
>> <andrew.pinski@caviumnetworks.com> wrote:
>>> This time with the patch and describing what the bug was.  The problem
>>> was defcodefor_name does not always set arg1 and arg2.  This fixes it
>>> so it is always set to NULL if they don't exist.
>>
>> Ok with ...
>>
>> +  if (code1 == SSA_NAME)
>> +    {
>> +      def = SSA_NAME_DEF_STMT (name);
>> +
>> +      if (def && is_gimple_assign (def)
>> +         && can_propagate_from (def))
>> +       {
>> +         code1 = gimple_assign_rhs_code (def);
>> +         arg11 = gimple_assign_rhs1 (def);
>> +          arg21 = gimple_assign_rhs2 (def);
>> +          arg31 = gimple_assign_rhs2 (def);
>> +       }
>> +    }
>>
>> ... recursing here instead.
>
>
> Recursing how?  Or do you mean when code1 is a SSA_NAME do a recursive
> call so that we can get some simple copy-prop happening?
> The current code does not do that though.

Ah, this is all pre-existing code.  But yes, to get simple copy-prop happening
(which is what this code seems to do, but just a single level).

The patch is ok as-is, you can improve ontop of it if you like.

Thanks,
Richard.

> Thanks,
> Andrew
>
>
>>
>> Thanks,
>> Richard.
>>
>>
>>> Thanks,
>>> Andrew
>>>
>>> On Fri, Apr 20, 2012 at 9:05 PM, Andrew Pinski
>>> <andrew.pinski@caviumnetworks.com> wrote:
>>>> On Thu, Jan 19, 2012 at 3:13 AM, Richard Guenther
>>>> <richard.guenther@gmail.com> wrote:
>>>>> On Thu, Jan 19, 2012 at 10:00 AM, Andrew Pinski
>>>>> <andrew.pinski@caviumnetworks.com> wrote:
>>>>>> On Tue, Jan 17, 2012 at 1:38 AM, Richard Guenther
>>>>>> <richard.guenther@gmail.com> wrote:
>>>>>>> On Tue, Jan 17, 2012 at 8:06 AM, Andrew Pinski
>>>>>>> <andrew.pinski@caviumnetworks.com> wrote:
>>>>>>>> Hi,
>>>>>>>>  This adds the folding of x & ((~x) | y)) into x & y on the tree
>>>>>>>> level via fold-const.c
>>>>>>>> There is already partly done on the RTL level but it would be a good
>>>>>>>> thing for the tree level also.
>>>>>>>>
>>>>>>>>
>>>>>>>> OK for 4.8 (yes I know we have not branched yet but I thought I would
>>>>>>>> send it out so I don't forget about it)?
>>>>>>>> Bootstrapped and tested on x86_64-linux-gnu with no regressions.
>>>>>>>
>>>>>>> Can you instead patch tree-ssa-forwprop.c:simplify_bitwise_binary?
>>>>>>
>>>>>> Yes and here is a new patch which also adds optimizing x | ((~x) & y)) to x | y.
>>>>>> Also it adds the optimizing x & (x | y) to x and x | (x & y) to x to
>>>>>> tree-ssa-forwprop.c:simplify_bitwise_binary
>>>>>> since it was an easy extension on top of the ~x case (well I
>>>>>> implemented the one without the ~ first).  I did not remove those
>>>>>> folding from fold-const.c though.
>>>>>>
>>>>>> Also I was thinking maybe this belongs in reassociate though I don't
>>>>>> see how to do it.
>>>>>
>>>>> I still have plans to create that piecewise gimple_fold (see my proposal
>>>>> from early last year) that would be the container for this kind of pattern
>>>>> matching.  It would then be usable from reassoc as well (but reassoc
>>>>> has the issue of only collecting one kind of op, so its simplification
>>>>> wouldn't trigger reliably on these).
>>>>>
>>>>> http://gcc.gnu.org/ml/gcc-patches/2011-03/msg01099.html
>>>>>
>>>>>> OK for 4.8, once in stage 1? Again bootstrapped and tested on
>>>>>> x86_64-linux-gnu with no regressions.
>>>>>
>>>>> Ok.
>>>>
>>>> Here is an updated patch which fixes a bug which I found while doing
>>>> the treecombine branch.  I rewrote defcodefor_name so more than
>>>> SSA_NAMEs can be passed to it.
>>>>
>>>> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
>>>>
>>>> Thanks,
>>>> Andrew Pinski
>>>>
>>>> ChangeLog:
>>>>
>>>> ChangeLog:
>>>> * tree-ssa-forwprop.c (defcodefor_name): New function.
>>>> (simplify_bitwise_binary): Use defcodefor_name instead of manually
>>>> Simplify "( X | Y) & X" to X and "( X & Y) | X" to X.
>>>> Simplify "(~X | Y) & X" to "X & Y" and
>>>> "(~X & Y) | X" to "X | Y".
>>>>
>>>> testsuite/ChangeLog:
>>>> * gcc.dg/tree-ssa/andor-3.c: New testcase.
>>>> * gcc.dg/tree-ssa/andor-4.c: New testcase.
>>>> * gcc.dg/tree-ssa/andor-5.c: New testcase.
>>>>
>>>>>
>>>>> Thanks,
>>>>> Richard.
>>>>>
>>>>>> Thanks,
>>>>>> Andrew Pinski
>>>>>>
>>>>>> ChangeLog:
>>>>>> * tree-ssa-forwprop.c (defcodefor_name): New function.
>>>>>> (simplify_bitwise_binary): Use defcodefor_name.
>>>>>> Simplify "( X | Y) & X" to X and "( X & Y) | X" to X.
>>>>>> Simplify "(~X | Y) & X" to "X & Y" and
>>>>>> "(~X & Y) | X" to "X | Y".
>>>>>>
>>>>>> testsuite/ChangeLog:
>>>>>> * gcc.dg/tree-ssa/andor-3.c: New testcase.
>>>>>> * gcc.dg/tree-ssa/andor-4.c: New testcase.
>>>>>> * gcc.dg/tree-ssa/andor-5.c: New testcase.
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Richard.
>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Andrew Pinski
>>>>>>>>
>>>>>>>> ChangeLog:
>>>>>>>> * fold-const.c (fold_binary_loc <case BIT_AND_EXPR>): Add folding of x
>>>>>>>> & (~x | y) into x & y.
>>>>>>>>
>>>>>>>> testsuite/ChangeLog:
>>>>>>>> * gcc.dg/tree-ssa/andor-3.c: New testcase.



More information about the Gcc-patches mailing list