This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Move some bit and binary optimizations in simplify and match
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Bernd Schmidt <bschmidt at redhat dot com>
- Cc: "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 8 Oct 2015 18:03:00 +0000
- Subject: Re: Move some bit and binary optimizations in simplify and match
- Authentication-results: sourceware.org; auth=none
- References: <SN2PR0701MB10242B9E56933B072C29DE698E360 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <5616A0B1 dot 9050503 at redhat dot com>
On Thu, 8 Oct 2015, Bernd Schmidt wrote:
> On 10/07/2015 11:54 AM, Hurugalawadi, Naveen wrote:
> > Move Fold X & (X ^ Y) as X & ~Y to match.pd.
> > Move Fold X & (Y ^ X) as ~Y & X to match.pd.
>
> I wonder if we shouldn't try to autogenerate patterns such as these. I did
> something like that for a different project a long time ago. Generate
> expressions up to a certain level of complexity, identify which ones are
> equivalent, and pick the one with the lowest cost for simplifications...
Any bitwise expression whose ultimate operands are X, Y, 0 and -1
(possibly with conversions among types of the same width) could be
canonicalized to one of: 0, -1, X, Y, ~X, ~Y, X^Y, X^~Y, A&B or A|B (where
A is X or ~X and B is Y or ~Y). I don't guarantee those are the best
canonical forms, but if you're folding this sort of expression you ought
to be able to make GCC fold all such expressions down to some such form
(and fold away all equality comparisons among such expressions with
constant value).
Now, such canonicalization could be done with a finite number of
autogenerated patterns (if you can fold ~(A BINOP B), (A BINOP B) BINOP C
and (A BINOP B) BINOP (C BINOP D), for A, B, C, D from 0, -1, X, Y, ~X,
~Y, folding for more complicated expressions falls out). I don't know if
that's the best way to do such folding or not.
Given such folding, autogenerating expressions of the form ((A BINOP B)
BINOP (C BINOP D)) == CANONICAL_FORM seems a plausible way of getting
testsuite coverage for the folding (and for that matter for seeing what
such folding is missing at present).
--
Joseph S. Myers
joseph@codesourcery.com