From patchwork Wed Jun 7 21:32:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 104714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp495533vqr; Wed, 7 Jun 2023 14:35:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RWFvb6USg/06elHmo/YIWp17Ehz9VIpGX0h5CnLMuTB5Nedz/j/yLdWYGgedOlL8MJoe3 X-Received: by 2002:a17:907:16a2:b0:971:eb29:a082 with SMTP id hc34-20020a17090716a200b00971eb29a082mr7949676ejc.49.1686173709682; Wed, 07 Jun 2023 14:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686173709; cv=none; d=google.com; s=arc-20160816; b=s2FA9U38Kc27FgOoAKD8orFP1aC0Mwa2ev+sQYlfBeHYAvFXlJlSAO6ThnyyyoRCtF lyp2BSfQooSRUnD65qMtqXhR3/ak+uzD1wu4tHLHM8wqzOVLPeTmyHcT8ehq+kPNIE4r XqVzu5CKEpFUy4v1Jmj59bSKYSdM1r56msOq8J8cHEP/uM8vz4qBnqr6AjwILdNzEEwp PAPl/pDtfgLnvooX5I4Dz0cF90aDmaKbdRLiApMagm6E5UqEU9YbGt50/BpNBOZT7WkJ YCCqDBY9rgFg5NjG5sAZ8Sx9PQCzns5fUsfiATeLZnAKy8xk0Cuiv+N3RlunqZCkVFkY LvIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=LxymcJhax6Akn9zoRcFKdKz5BpMPWhkQYH9Zt9QPB1g=; b=AOynwQJBMmwB2gdVKvG2pzNzIxI1Tqebgs+JRgT1EurLYAzo3R4QA5c4yYsRJrKZha csBTFZwaEQZ1piuldpU5KANHeMbpJ80woZiq3XcPVoEu1GZTP6+yp6GUmbn19gEH3Faw hYre+oqXtKmfW6QXTtK03td+5kqz4NuYVkKhP2Id1j+9+9d36AqvrExZvZXDEdkWqWsV S+LBlpESJV8tBYcl1kw1yeJ9Y6et+yhUHfuIYEWBv8xzlS9dqWSTGs3XU0GnsdjollrH tkph/m+h3rP8MUplYjuZLtDROq8rODf+gtRWIywK3UUP97BJa7gOIQ3xAZubQEYK7N4I WUmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QtvknN6t; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ex16-20020a170907955000b0097550901a57si7451863ejc.681.2023.06.07.14.35.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 14:35:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QtvknN6t; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 282D43856629 for ; Wed, 7 Jun 2023 21:34:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 282D43856629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686173683; bh=LxymcJhax6Akn9zoRcFKdKz5BpMPWhkQYH9Zt9QPB1g=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=QtvknN6t1jqrpIX8bXg00TAFb4zE9af1ZqmwGtN7X/tHG0IwEuDXJEA8Gr8OlG2fh orUhjNBMiEI4j2JkzRDr+XXz85TaaPH2odR9eceB54vB9tXsDrT3BzPu2sppN27oeT wwn1QHL46tkdokKLMXyZMBrNI8q9WMeXtiTk3Wh8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 54B643856DDE for ; Wed, 7 Jun 2023 21:33:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54B643856DDE Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 357JrfuI017357 for ; Wed, 7 Jun 2023 14:33:14 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3r30eu08ea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 07 Jun 2023 14:33:13 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 7 Jun 2023 14:33:11 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 7 Jun 2023 14:33:11 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id 6DB043F7093; Wed, 7 Jun 2023 14:33:06 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 3/3] Add Plus to the op list of `(zero_one == 0) ? y : z y` pattern Date: Wed, 7 Jun 2023 14:32:17 -0700 Message-ID: <20230607213217.3052696-3-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230607213217.3052696-1-apinski@marvell.com> References: <20230607213217.3052696-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: CHla2quLNVqA6fw7h_z-wZzzdxH-WLP6 X-Proofpoint-GUID: CHla2quLNVqA6fw7h_z-wZzzdxH-WLP6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_11,2023-06-07_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768081283933982925?= X-GMAIL-MSGID: =?utf-8?q?1768081283933982925?= This adds plus to the op list of `(zero_one == 0) ? y : z y` patterns which currently has bit_ior and bit_xor. This shows up now in GCC after the boolization work that Uroš has been doing. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/97711 PR tree-optimization/110155 gcc/ChangeLog: * match.pd ((zero_one == 0) ? y : z y): Add plus to the op. ((zero_one != 0) ? z y : y): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/branchless-cond-add-2.c: New test. * gcc.dg/tree-ssa/branchless-cond-add.c: New test. --- gcc/match.pd | 4 ++-- .../gcc.dg/tree-ssa/branchless-cond-add-2.c | 8 ++++++++ .../gcc.dg/tree-ssa/branchless-cond-add.c | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c diff --git a/gcc/match.pd b/gcc/match.pd index c38b39fb45c..f633271f76c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3689,7 +3689,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (max @2 @1)) /* (zero_one == 0) ? y : z y -> ((typeof(y))zero_one * z) y */ -(for op (bit_xor bit_ior) +(for op (bit_xor bit_ior plus) (simplify (cond (eq zero_one_valued_p@0 integer_zerop) @@ -3701,7 +3701,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (op (mult (convert:type @0) @2) @1)))) /* (zero_one != 0) ? z y : y -> ((typeof(y))zero_one * z) y */ -(for op (bit_xor bit_ior) +(for op (bit_xor bit_ior plus) (simplify (cond (ne zero_one_valued_p@0 integer_zerop) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c new file mode 100644 index 00000000000..27607e10f88 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add-2.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/97711 */ + +int f (int x) { return x & 1 ? x - 1 : x; } + +/* { dg-final { scan-tree-dump-times " & -2" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c new file mode 100644 index 00000000000..0d81c07b03a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond-add.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/110155 */ + +int f1(unsigned int x, unsigned int y, unsigned int z) +{ + return ((x & 1) == 0) ? y : z + y; +} + +int f2(unsigned int x, unsigned int y, unsigned int z) +{ + return ((x & 1) != 0) ? z + y : y; +} + +/* { dg-final { scan-tree-dump-times " \\\*" 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " \\\+ " 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & " 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */