From patchwork Thu Oct 20 05:07:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 78402 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp599670qge; Wed, 19 Oct 2016 22:08:02 -0700 (PDT) X-Received: by 10.99.104.196 with SMTP id d187mr2696109pgc.26.1476940082047; Wed, 19 Oct 2016 22:08:02 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j3si36235576pal.99.2016.10.19.22.08.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 22:08:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439075-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439075-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439075-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=SROgBoByfplR72ra9L2+BTzwl5viblEQeRNAwh9/sQUDqG bf+TkqQPQ63E/KHp92/6GQC72RETytkFf/1A36zB6+WJTJoAUp7u20a6Ls6/baN0 yO/C5pJ9E8NwjBjGCqwdAzTwAFW/U8X0bp/1/aoJrRRhEyNFtxeQ7OnQtNk0s= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=1yZEIGwAMjpJCPNPbYsuMcCswXo=; b=GwU6XR4xPe93doymQ4m+ YbYeRkYCdXPQgq7VmVimn9BS8cT45pwXSs9UuBKISNLvihBx33yU7s55fdGSa9MN jStmHT14FEBJPGQf6myVMKFWUdr8k36MRz1N5TJPthjWLbqLO8GUhpP4GJzbrjW8 FfKnuv/htys2ReXcQd1A00E= Received: (qmail 96137 invoked by alias); 20 Oct 2016 05:07:46 -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 96112 invoked by uid 89); 20 Oct 2016 05:07:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=D*1, 2016-10-20, 20161020 X-HELO: mail-it0-f50.google.com Received: from mail-it0-f50.google.com (HELO mail-it0-f50.google.com) (209.85.214.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Oct 2016 05:07:34 +0000 Received: by mail-it0-f50.google.com with SMTP id 66so68314315itl.1 for ; Wed, 19 Oct 2016 22:07:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Y9hsZbgf2PLD1E9JVMPCx+adjs5Z3v81iwnmLUEs2bA=; b=WbgQA3vUxk0kuTlPfSP4f9PebNfQmRRlf58jWs6eUUTaKFrGMz00ZrZ0UKviVNtLPB Kfslumd6GNc5y28cZbdyuFiyW0YWHXxOSaFFVJAwDj9JO6dbn3RZFmuJsLE/Oc7bYNo4 +N0MRhxkWCEfDXr6pUdX9htx0hIN8GcGr2cACVAGPtNYFQyb4Z6rkuesQsl6vvTQWNay Ueds0XVXaI8FDFMtEhPIC7fM88fQQv0gv9RgzKbcAAhtEL3XSO1sIzS5CXmIofZojviL RG77IXZ6/Zlt9EqFTtZtxtBk/vUmSj2eFhIC2cGovWMUZOk6RxggMDILGFKa6JbbYGNm N2CQ== X-Gm-Message-State: AA6/9RlfA7VFT467yTd86bjK2so9wQ4BnS0HeAYdYYkIsW1j8FwsKolrKcrrNXUundbDLtxN/vQ8/0o5Dm87Tg+H X-Received: by 10.36.237.70 with SMTP id r67mr10487497ith.71.1476940052985; Wed, 19 Oct 2016 22:07:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.30.74 with HTTP; Wed, 19 Oct 2016 22:07:32 -0700 (PDT) From: Prathamesh Kulkarni Date: Thu, 20 Oct 2016 10:37:32 +0530 Message-ID: Subject: PR53979: add transform (a ^ b) | a -> a | b To: Richard Biener , gcc Patches X-IsSubscribed: yes Hi Richard, The attached patch adds the transform (a ^ b) | a -> a | b suggested in PR53979. Bootstrap+tested on x86_64-unknown-linux-gnu. OK to commit ? Thanks, Prathamesh 2016-10-20 Prathamesh Kulkarni PR tree-optimization/53979 * match.pd ((a ^ b) | a -> a | b): New pattern. testsuite/ * gcc.dg/pr53979-1.c: New test-case. * gcc.dg/pr53979-2.c: Likewise. diff --git a/gcc/match.pd b/gcc/match.pd index b782a1e..7888459 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -541,6 +541,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1)) (if (wi::bit_not (@2) == @1) (bit_xor @0 @1))) + +/* PR53979: Transform ((a ^ b) | a) -> (a | b) */ +(simplify + (bit_ior:c (bit_xor:c @0 @1) @0) + (bit_ior @0 @1)) + /* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */ #if GIMPLE (simplify diff --git a/gcc/testsuite/gcc.dg/pr53979-1.c b/gcc/testsuite/gcc.dg/pr53979-1.c new file mode 100644 index 0000000..aee54f5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr53979-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple" } */ + +unsigned f1(unsigned a, unsigned b) +{ + return (a ^ b) | a; +} + +/* { dg-final { scan-tree-dump "a | b" "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/pr53979-2.c b/gcc/testsuite/gcc.dg/pr53979-2.c new file mode 100644 index 0000000..be2607a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr53979-2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop-details" } */ + +unsigned f(unsigned a, unsigned b) +{ + unsigned t1 = a ^ b; + unsigned t2 = t1 | a; + return t2; +} + +/* { dg-final { scan-tree-dump "gimple_simplified to t2_\[0-9\] = a_\[0-9\]*\\(D\\) | b_\[0-9\]*\\(D\\)" "forwprop1" } } */