From patchwork Fri Jun 26 07:59:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 488630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B005B1400A0 for ; Fri, 26 Jun 2015 17:59:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=r0wNtI6c; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=CapiqM9GMbUjdvRV8dhcX03/w6YBbYGGPW7pRuVFIziXC/sixn iKwSsteLFqI1541hN+Nm1Z2TLtYqpFUXuSH7NsNyDTiHvPJyEOSxUoFt5VMHuAbV tH41h0uQXRePEHrYKh9TcsO78kbqQoAXoHcpPLHffHh5YU5UH2MmMsSDA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=96oBbRegJMIQHm5nrfBslKAJ+BU=; b=r0wNtI6cFs1nAgjIiuDC KLiKmDTDT5Klhx25oiT3SCUNgYkVsMwRBVaktbTw51b+eXbiTSc0QJAOen7P6o6e PwsY5qIbS1hqSUjju/F4s6blO8LWOOzK1ni0D5mBC6TZzkPgUAiJEjW0vi3q2zvn 968/Y+haQuEp/8IYVm63JM0= Received: (qmail 107129 invoked by alias); 26 Jun 2015 07:59:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 107119 invoked by uid 89); 26 Jun 2015 07:59:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham 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; Fri, 26 Jun 2015 07:59:24 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id A0B9F2BCD6D; Fri, 26 Jun 2015 07:59:23 +0000 (UTC) Received: from redhat.com (ovpn-204-67.brq.redhat.com [10.40.204.67]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5Q7xJHh027508 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Fri, 26 Jun 2015 03:59:22 -0400 Date: Fri, 26 Jun 2015 09:59:18 +0200 From: Marek Polacek To: GCC Patches Cc: Marc Glisse , Richard Biener Subject: match.pd: Optimize (x | y) & ~(x & y) and (x | y) & (~x ^ y) Message-ID: <20150626075918.GC10139@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) The following patch adds optimizing of (x | y) & ~(x & y) and (x | y) & (~x ^ y) to a single operation. No +/-/* in those, so I think we don't have to worry about saturating types this time around. For some reason I had to use more :c's in the latter pattern than usual. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-06-26 Marek Polacek * match.pd ((x | y) & ~(x & y) -> x ^ y, (x | y) & (~x ^ y) -> x & y): New patterns. * gcc.dg/fold-and-1.c: New test. * gcc.dg/fold-and-2.c: New test. Marek diff --git gcc/match.pd gcc/match.pd index 292ce6d..f242c99 100644 --- gcc/match.pd +++ gcc/match.pd @@ -367,6 +367,16 @@ along with GCC; see the file COPYING3. If not see (minus (bit_ior @0 @1) (bit_and @0 @1)) (bit_xor @0 @1)) +/* (x | y) & ~(x & y) -> x ^ y */ +(simplify + (bit_and:c (bit_ior @0 @1) (bit_not (bit_and @0 @1))) + (bit_xor @0 @1)) + +/* (x | y) & (~x ^ y) -> x & y */ +(simplify + (bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0))) + (bit_and @0 @1)) + (simplify (abs (negate @0)) (abs @0)) diff --git gcc/testsuite/gcc.dg/fold-and-1.c gcc/testsuite/gcc.dg/fold-and-1.c index e69de29..d555bb4 100644 --- gcc/testsuite/gcc.dg/fold-and-1.c +++ gcc/testsuite/gcc.dg/fold-and-1.c @@ -0,0 +1,70 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +int +fn1 (int x, int y) +{ + int tem1 = x | y; + int tem2 = ~(x & y); + return tem1 & tem2; +} + +int +fn2 (int x, int y) +{ + int tem1 = y | x; + int tem2 = ~(x & y); + return tem1 & tem2; +} + +int +fn3 (int x, int y) +{ + int tem1 = x | y; + int tem2 = ~(y & x); + return tem1 & tem2; +} + +int +fn4 (int x, int y) +{ + int tem1 = y | x; + int tem2 = ~(y & x); + return tem1 & tem2; +} + +int +fn5 (int x, int y) +{ + int tem1 = ~(x & y); + int tem2 = x | y; + return tem1 & tem2; +} + +int +fn6 (int x, int y) +{ + int tem1 = ~(x & y); + int tem2 = y | x; + return tem1 & tem2; +} + +int +fn7 (int x, int y) +{ + int tem1 = ~(y & x); + int tem2 = x | y; + return tem1 & tem2; +} + +int +fn8 (int x, int y) +{ + int tem1 = ~(y & x); + int tem2 = y | x; + return tem1 & tem2; +} + +/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */ +/* { dg-final { scan-tree-dump-not " \\& " "cddce1" } } */ +/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */ diff --git gcc/testsuite/gcc.dg/fold-and-2.c gcc/testsuite/gcc.dg/fold-and-2.c index e69de29..3df2a0b 100644 --- gcc/testsuite/gcc.dg/fold-and-2.c +++ gcc/testsuite/gcc.dg/fold-and-2.c @@ -0,0 +1,70 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +int +fn1 (int x, int y) +{ + int tem1 = x | y; + int tem2 = ~x ^ y; + return tem1 & tem2; +} + +int +fn2 (int x, int y) +{ + int tem1 = y | x; + int tem2 = ~x ^ y; + return tem1 & tem2; +} + +int +fn3 (int x, int y) +{ + int tem1 = x | y; + int tem2 = y ^ ~x; + return tem1 & tem2; +} + +int +fn4 (int x, int y) +{ + int tem1 = y | x; + int tem2 = y ^ ~x; + return tem1 & tem2; +} + +int +fn5 (int x, int y) +{ + int tem1 = ~x ^ y; + int tem2 = x | y; + return tem1 & tem2; +} + +int +fn6 (int x, int y) +{ + int tem1 = ~x ^ y; + int tem2 = y | x; + return tem1 & tem2; +} + +int +fn7 (int x, int y) +{ + int tem1 = y ^ ~x; + int tem2 = x | y; + return tem1 & tem2; +} + +int +fn8 (int x, int y) +{ + int tem1 = y ^ ~x; + int tem2 = y | x; + return tem1 & tem2; +} + +/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */ +/* { dg-final { scan-tree-dump-not " \\^ " "cddce1" } } */ +/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */