From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4766 invoked by alias); 11 Jun 2015 12:07:38 -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 4756 invoked by uid 89); 11 Jun 2015 12:07:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 11 Jun 2015 12:07:36 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id A57ECB6F47; Thu, 11 Jun 2015 12:07:35 +0000 (UTC) Received: from redhat.com (ovpn-204-44.brq.redhat.com [10.40.204.44]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5BC7WHV025770 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Thu, 11 Jun 2015 08:07:34 -0400 Date: Thu, 11 Jun 2015 12:14:00 -0000 From: Marek Polacek To: Richard Biener Cc: GCC Patches Subject: Re: match.pd: Optimize (x & y) ^ (x | y) Message-ID: <20150611120732.GA2756@redhat.com> References: <20150611110432.GY2756@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-06/txt/msg00836.txt.bz2 On Thu, Jun 11, 2015 at 01:08:41PM +0200, Richard Biener wrote: > If the pattern doesn't exist in fold-const.c (obviously it doesn't) > then I think it makes sense to only add testcases to match this on > GIMPLE (because in the long run we'd like to _not_ transform things > in GENERIC, at least not without -O). > > Thus sth like > > > +int > > +fn1 (signed int x, signed int y) > > +{ > signed int tem1 = x & y; > singed int tem2 = x | y; > > + return tem1 ^ tem2; > > +} > > and scanning the first DCE dump (cddec1) for the applied transform. Makes sense. Fixed. > Otherwise the patch is of course ok. (take the suggestion above > for followup patches) I'll commit the following version if testing passes then, thanks. 2015-06-11 Marek Polacek * match.pd ((x & y) ^ (x | y) -> x ^ y): New pattern. * gcc.dg/fold-xor-3.c: New test. diff --git gcc/match.pd gcc/match.pd index 33fa717..9a1317e 100644 --- gcc/match.pd +++ gcc/match.pd @@ -320,6 +320,12 @@ along with GCC; see the file COPYING3. If not see (bitop:c (rbitop:c @0 @1) (bit_not@2 @0)) (bitop @1 @2))) +/* (x & y) ^ (x | y) -> x ^ y */ +(simplify + (bit_xor:c (bit_and@2 @0 @1) (bit_ior@3 @0 @1)) + (if (single_use (@2) && single_use (@3)) + (bit_xor @0 @1))) + (simplify (abs (negate @0)) (abs @0)) diff --git gcc/testsuite/gcc.dg/fold-xor-3.c gcc/testsuite/gcc.dg/fold-xor-3.c index e69de29..c2c0af6 100644 --- gcc/testsuite/gcc.dg/fold-xor-3.c +++ gcc/testsuite/gcc.dg/fold-xor-3.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +int +fn1 (signed int x, signed int y) +{ + signed int tem1 = x & y; + signed int tem2 = x | y; + return tem1 ^ tem2; +} + +unsigned int +fn2 (unsigned int x, unsigned int y) +{ + unsigned int tem1 = x & y; + unsigned int tem2 = x | y; + return tem1 ^ tem2; +} + +int +fn3 (signed int x, signed int y) +{ + signed int tem1 = x & y; + signed int tem2 = x | y; + return tem2 ^ tem1; +} + +unsigned int +fn4 (unsigned int x, unsigned int y) +{ + unsigned int tem1 = x & y; + unsigned int tem2 = x | y; + return tem2 ^ tem1; +} + +/* { dg-final { scan-tree-dump-not " & " "cddce1" } } */ +/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */ Marek