From patchwork Wed Jun 7 21:32:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1791927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=DFGIfgfV; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qc0vS5THwz20WP for ; Thu, 8 Jun 2023 07:33:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B66F03857004 for ; Wed, 7 Jun 2023 21:33:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B66F03857004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686173602; bh=P28f4fHKtVzCUNI2M67FcAMv8IfNApg44ZFi214OZKk=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DFGIfgfVUKD4m+C6q4AFTPfR5/OGJoUiu11uqQCMVoHsuJLYWn01584+65Atfia9y 3AE3jvPkc0I9i+krzY3iaiqjM9vjoBlkAmZsocdIUuiQLKsu8NW+BAhlbjeSz7o4r6 L61sHmSCKbgvXsXLKrmb4tSglliiBWMleGdMpA7g= 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 BC79B385735E for ; Wed, 7 Jun 2023 21:33:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC79B385735E 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 357KhTtm003278 for ; Wed, 7 Jun 2023 14:33:03 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3r30eu08dw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 07 Jun 2023 14:33:03 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) 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:01 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 7 Jun 2023 14:33:01 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id C3AD33F7093; Wed, 7 Jun 2023 14:32:57 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/3] MATCH: Allow unsigned types for `X & -Y -> X * Y` pattern Date: Wed, 7 Jun 2023 14:32:15 -0700 Message-ID: <20230607213217.3052696-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jYwMBOPCHGYjTOXOFHrf0726GE3OdBDY X-Proofpoint-GUID: jYwMBOPCHGYjTOXOFHrf0726GE3OdBDY 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This allows unsigned types if the inner type where the negation is located has greater than or equal to precision than the outer type. branchless-cond.c needs to be updated since now we change it to use a multiply rather than still having (-a)&c in there. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd (`X & -Y -> X * Y`): Allow for truncation and the same type for unsigned types. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/branchless-cond.c: Update testcase. --- gcc/match.pd | 5 ++++- gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 4ad037d641a..7b95b63cee4 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2058,7 +2058,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TREE_CODE (TREE_TYPE (@0)) != BOOLEAN_TYPE - && !TYPE_UNSIGNED (TREE_TYPE (@0))) + /* Sign extending of the neg or a truncation of the neg + is needed. */ + && (!TYPE_UNSIGNED (TREE_TYPE (@0)) + || TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0)))) (mult (convert @0) @1))) /* Narrow integer multiplication by a zero_one_valued_p operand. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c index 68087ae6568..e063dc4bb5f 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/branchless-cond.c @@ -21,6 +21,6 @@ int f4(unsigned int x, unsigned int y, unsigned int z) return ((x & 1) != 0) ? z | y : y; } -/* { dg-final { scan-tree-dump-times " -" 4 "optimized" } } */ -/* { dg-final { scan-tree-dump-times " & " 8 "optimized" } } */ -/* { dg-final { scan-tree-dump-not "if" "optimized" } } */ +/* { dg-final { scan-tree-dump-times " \\\*" 4 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " & " 4 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */