From patchwork Thu Nov 3 10:21:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 80629 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp554288qge; Thu, 3 Nov 2016 03:21:27 -0700 (PDT) X-Received: by 10.98.149.140 with SMTP id c12mr15653914pfk.100.1478168487671; Thu, 03 Nov 2016 03:21:27 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id fn1si7274979pad.302.2016.11.03.03.21.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Nov 2016 03:21:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-440277-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-440277-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440277-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=SMApTSDZTHA9JQWSy7ZCrjKH3+mAMYPF4WCeP2SA2DpjnI WTuhBJ01kZjO7lOOdWtjJOiG0O88yT2fogfMFMmyL6rsbGM+FEmphqYkz2ftonPc wHY8wSjVZzysPchaGwoH+v8MbdEoRJdDQ3nXGcwP093+ZwfTz5uY+Y18OFeIk= 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=0kxMaJ+FNCbesyx2LzVgQ04t2qI=; b=TVO/d/Demgj8QMGYAnac BbDSYtZYABBLv5W34HAHBkwZOoeDEcKkUojJpHXpjEiq0jbzjKEAOERRqjIdTnG2 tAdzeQolV3TDU7005wg5Hl/RYKYW8sryf7Hovd9y+w0qOp+A8Lt25o03wBsRJaPG /aySR2KNSBNrNqZcDs7rhwI= Received: (qmail 112601 invoked by alias); 3 Nov 2016 10:21:16 -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 112584 invoked by uid 89); 3 Nov 2016 10:21:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy= X-HELO: mail-oi0-f51.google.com Received: from mail-oi0-f51.google.com (HELO mail-oi0-f51.google.com) (209.85.218.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Nov 2016 10:21:05 +0000 Received: by mail-oi0-f51.google.com with SMTP id 62so77458090oif.1 for ; Thu, 03 Nov 2016 03:21:05 -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=dBdNy8W+Km6CuuuVnB3Yd0T/nfEidSjfSXH4QrPQgdk=; b=i45HHA484Id8J/w4yhBPXo1VbICx3rqLEmsEGoAJuJU1AKJa1e6lUSMczMaNxX5wSv J8qySrcBgORH6N/uUoq0xbU+6Z3F3PnhylYnq1KRNw0fgnsvjkUBqSTQGiNySzcWBLoe Af2WJHsEBeAmG+5/zR6Yx3VqZvt8wUHqGruAD3Xbqktog1scMG4Q4sDFsmE5vvJoyhRi x+rs3ozqVTHtlEs9fC9KqClJPyBVqU7cD0zp+HyvyKdrWWwYj8Og7D3suwrTAUhtpUjF /EvYCMCBklpJkT5rXXanlVI5eecB+rSlJqM6Po/P9Brc1uLN1mcWD5+96HRc3LaL2YJS 7MCA== X-Gm-Message-State: ABUngvd+k2m9VqMB7xY4SsaoQAUy2EdUpdzG4Iis08QOooyRxXmreSkGVcVedZkhAms8FtDy1DR3zQndr5f44xZA X-Received: by 10.107.3.168 with SMTP id e40mr957838ioi.89.1478168463985; Thu, 03 Nov 2016 03:21:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.12.169 with HTTP; Thu, 3 Nov 2016 03:21:03 -0700 (PDT) From: Prathamesh Kulkarni Date: Thu, 3 Nov 2016 15:51:03 +0530 Message-ID: Subject: [match.pd] Fix for PR35691 To: gcc Patches , Richard Biener X-IsSubscribed: yes Hi Richard, The attached patch tries to fix PR35691, by adding the following two transforms to match.pd: (x == 0 && y == 0) -> (x | typeof(x)(y)) == 0. (x != 0 || y != 0) -> (x | typeof(x)(y)) != 0. For GENERIC, the "and" operator is truth_andif_expr, and it seems for GIMPLE, it gets transformed to bit_and_expr so to match for both GENERIC and GIMPLE, I had to guard the for-stmt: #if GENERIC (for op (truth_andif truth_orif) #elif GIMPLE (for op (bit_and bit_ior) #endif Is that OK ? Bootstrap+test running on x86_64-unknown-linux-gnu. Thanks, Prathamesh 2016-11-03 Prathamesh Kulkarni PR middle-end/35691 * match.pd: Add following two patterns: (x == 0 & y == 0) -> (x | typeof(x)(y)) == 0. (x != 0 | y != 0) -> (x | typeof(x)(y)) != 0. testsuite/ * gcc.dg/pr35691-1.c: New test-case. * gcc.dg/pr35691-2.c: Likewise. * gcc.dg/pr35691-3.c: Likewise. * gcc.dg/pr35691-4.c: Likewise. diff --git a/gcc/match.pd b/gcc/match.pd index 48f7351..65930bb 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -519,6 +519,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (TYPE_UNSIGNED (type)) (bit_and @0 (bit_not (lshift { build_all_ones_cst (type); } @1))))) +/* PR35691: Transform + (x == 0 & y == 0) -> (x | typeof(x)(y)) == 0. + (x != 0 | y != 0) -> (x | typeof(x)(y)) != 0. */ + +#if GENERIC +(for op (truth_andif truth_orif) +#elif GIMPLE +(for op (bit_and bit_ior) +#endif + cmp (eq ne) + (simplify + (op (cmp @0 integer_zerop) (cmp @1 integer_zerop)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1))) + (cmp (bit_ior @0 (convert @1)) { build_zero_cst (TREE_TYPE (@0)); })))) + /* Fold (A & ~B) - (A & B) into (A ^ B) - B. */ (simplify (minus (bit_and:cs @0 (bit_not @1)) (bit_and:cs @0 @1)) diff --git a/gcc/testsuite/gcc.dg/pr35691-1.c b/gcc/testsuite/gcc.dg/pr35691-1.c new file mode 100644 index 0000000..25a7ace --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr35691-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-gimple" } */ + +int foo1(int z0, unsigned z1) +{ + return (z0 == 0) && (z1 == 0); +} + +/* { dg-final { scan-tree-dump-not "z1.\[0-9\]*_\[0-9\]* = (int) z1" "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/pr35691-2.c b/gcc/testsuite/gcc.dg/pr35691-2.c new file mode 100644 index 0000000..5211f815 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr35691-2.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop-details" } */ + +int foo(int z0, unsigned z1) +{ + int t0 = (z0 == 0); + int t1 = (z1 == 0); + int t2 = (t0 && t1); + return t2; +} + +/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/pr35691-3.c b/gcc/testsuite/gcc.dg/pr35691-3.c new file mode 100644 index 0000000..134bbdf --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr35691-3.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-gimple" } */ + +int foo1(int z0, unsigned z1) +{ + return (z0 != 0) || (z1 != 0); +} + +/* { dg-final { scan-tree-dump-not "z1.\[0-9\]*_\[0-9\]* = (int) z1" "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/pr35691-4.c b/gcc/testsuite/gcc.dg/pr35691-4.c new file mode 100644 index 0000000..90cbf6d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr35691-4.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop-details" } */ + +int foo(int z0, unsigned z1) +{ + int t0 = (z0 != 0); + int t1 = (z1 != 0); + int t2 = (t0 || t1); + return t2; +} + +/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */