From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 97105 invoked by alias); 28 Aug 2018 15:34:13 -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 96982 invoked by uid 89); 28 Aug 2018 15:34:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=dates X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.15.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Aug 2018 15:34:10 +0000 Received: from [195.155.102.117] ([195.155.102.117]) by web-mail.gmx.net (3c-app-mailcom-bs01.server.lan [172.19.170.58]) (via HTTP); Tue, 28 Aug 2018 17:34:04 +0200 MIME-Version: 1.0 Message-ID: From: "MCC CS" To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Optimize more boolean functions Content-Type: text/plain; charset=UTF-8 Date: Tue, 28 Aug 2018 15:34:00 -0000 X-SW-Source: 2018-08/txt/msg01778.txt.bz2 Hi again, I guess I haven't been clear enough. I don't have push access, is it possible for you to push my patch to trunk? The same patch as: https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01688.html but updated dates. 2018-08-28 MCC CS gcc/ PR tree-optimization/87009 * match.pd: Add boolean optimizations. 2018-08-28 MCC CS gcc/testsuite/ PR tree-optimization/87009 * gcc.dg/pr87009.c: New test. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 263646) +++ gcc/match.pd (working copy) @@ -776,6 +776,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_not (bit_and:cs (bit_not @0) @1)) (bit_ior @0 (bit_not @1))) +/* ~(~a | b) --> a & ~b */ +(simplify + (bit_not (bit_ior:cs (bit_not @0) @1)) + (bit_and @0 (bit_not @1))) + /* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */ #if GIMPLE (simplify @@ -981,6 +986,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0))) (bit_and @0 @1)) +/* (~x | y) & (x | ~y) -> ~(x ^ y) */ +(simplify + (bit_and (bit_ior:cs (bit_not @0) @1) (bit_ior:cs @0 (bit_not @1))) + (bit_not (bit_xor @0 @1))) + +/* (~x | y) ^ (x | ~y) -> x ^ y */ +(simplify + (bit_xor (bit_ior:c (bit_not @0) @1) (bit_ior:c @0 (bit_not @1))) + (bit_xor @0 @1)) + /* ~x & ~y -> ~(x | y) ~x | ~y -> ~(x & y) */ (for op (bit_and bit_ior) Index: gcc/testsuite/gcc.dg/pr87009.c =================================================================== --- gcc/testsuite/gcc.dg/pr87009.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr87009.c (working copy) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-original" } */ +/* { dg-final { scan-tree-dump-times "return s \\^ x;" 4 "original" } } */ + +int f1 (int x, int s) +{ + return ~(~(x|s)|x)|~(~(x|s)|s); +} + +int f2 (int x, int s) +{ + return ~(~(~x&s)&~(x&~s)); +} + +int f3 (int x, int s) +{ + return ~((x|~s)&(~x|s)); +} + +int f4 (int x, int s) +{ + return (x|~s)^(~x|s); +}