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: 104712 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp494983vqr; Wed, 7 Jun 2023 14:33:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ56zNuUByZbbh4VZbzD4UqCExJTgMbflnamDvfubREcLXKpsgQgbLUI8B41YBHjzXjNd3fi X-Received: by 2002:a05:6402:14d9:b0:50d:82f9:6867 with SMTP id f25-20020a05640214d900b0050d82f96867mr5743733edx.31.1686173639336; Wed, 07 Jun 2023 14:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686173639; cv=none; d=google.com; s=arc-20160816; b=BZ1ayJdGBlhC6NVNB5CwVBaqF67FMEEJsrUJNkmrWVGnz6a++FcXNx4MG7Q5u2CNMz mMBpDEzJVvqPuiJq4W9JfPHN2MiKghKt7UEJrz89KzIUD6hk7bRitOInZOtqRWoskb9u swoX7TcxBSPj2HINFTxO/9GRFt2XuCArHBZgspr32OPj5c2LU33blSU0nkmSyrS6u5NP X6IvjCOakJYyXFHC/xT4LNQokd7HymcE+bxj0BYPJAZOV8JSwImAqlbX7hv5lGGUALw+ 5yPtW0EP2RX0Q44wazi+/R09A/5I4IoCyKF1OFJvonH7n9Tf0E4oXKupH8erH1mWVpwy hQyQ== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=P28f4fHKtVzCUNI2M67FcAMv8IfNApg44ZFi214OZKk=; b=HoeHjTfKYFDz59MmKXjDNFyJd20+SWSf6/mmOVydXUzdkYVOQNVb8rKfu/qJ5IDiOy XCx/f5sDAqYizhdCx6N71kCXv4u/PFkuwBa56VG+ZCHIBsVDWlDRczJo6fzkpNFREANb x1Z9eGaGCg/fhQmExvnkGWQZ/VtDJPurI6vFIOx+D87bC3QpFW83PEfbtGTEzjBitnLa OvI5yKmzdvFYXuMmSOTowG6vFVttTpyQEA3l9oBH+iXsWw4JDAjYS9/0UvvmYocXOBzw DqMTFA+518Ll1jpmvWW1+ect54YUgicYsTrWdnk+yXjtrUibK5uaEASTDdyhbys8NGZi 7FcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FwL64lvv; 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 e4-20020aa7d7c4000000b005149904c8f3si8400183eds.411.2023.06.07.14.33.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 14:33:59 -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=FwL64lvv; 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 044963857029 for ; Wed, 7 Jun 2023 21:33:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 044963857029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686173626; bh=P28f4fHKtVzCUNI2M67FcAMv8IfNApg44ZFi214OZKk=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FwL64lvvbrMdkCG5nuFjVfARsosaivwxW2Ix3kJMuE5Adlldg1oAswIIzfwcw0nPg O/Le6gp6vxMg0Wsw8ZokTMH7SaXnWvnlYFQ+fsDisMnHW4D1LWzdD/dQ9noLT05E9O TrNpCidN6YSx0eCpV9NuTdldsaRDYUWgGeKXyqqM= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768081210296951750?= X-GMAIL-MSGID: =?utf-8?q?1768081210296951750?= 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" } } */