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: 70760 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E931385662C for ; Wed, 7 Jun 2023 21:34:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E931385662C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686173668; 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=L+QqA/lOt0G9EN2BUz82j7e3PIlkRWALyOWxbO96FCsJ0wxhFJecdSMhpg6AHxvUY S7KJhCHdlr9HkuNMBXh3ERG3EVnMxLMuLPXLRp/hKdn4oP6gk7JILJSVR1zAXu7xa9 wNMOIEJFDwl3mEIlQs4dm2gY+776pfKuLfMAIoes= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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" } } */