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 jos...@codesourcery.com