From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89483 invoked by alias); 8 Oct 2015 18:03:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 89456 invoked by uid 89); 8 Oct 2015 18:03:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Oct 2015 18:03:07 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZkFWx-0005if-NA from joseph_myers@mentor.com ; Thu, 08 Oct 2015 11:03:03 -0700 Received: from digraph.polyomino.org.uk (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Thu, 8 Oct 2015 19:03:02 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.82) (envelope-from ) id 1ZkFWu-0000Ro-Qo; Thu, 08 Oct 2015 18:03:00 +0000 Date: Thu, 08 Oct 2015 18:03:00 -0000 From: Joseph Myers To: Bernd Schmidt CC: "Hurugalawadi, Naveen" , "gcc-patches@gcc.gnu.org" Subject: Re: Move some bit and binary optimizations in simplify and match In-Reply-To: <5616A0B1.9050503@redhat.com> Message-ID: References: <5616A0B1.9050503@redhat.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-SW-Source: 2015-10/txt/msg00888.txt.bz2 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