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" } } */ From patchwork Wed Jun 7 21:32:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 104713 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp495445vqr; Wed, 7 Jun 2023 14:34:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6INTnWbK69FFpgUMLaIIlnVEZ6YuLKUDlJ1FVW7ogOh9yKr8GVn8ORsnJWhYdPt9C9Oyj+ X-Received: by 2002:a17:907:da1:b0:977:ccc6:1d73 with SMTP id go33-20020a1709070da100b00977ccc61d73mr7655444ejc.71.1686173696670; Wed, 07 Jun 2023 14:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686173696; cv=none; d=google.com; s=arc-20160816; b=ULVIya6fpuLdKMj7KVZ0o1JRUTd5GQY5AvA0+mZrPoQszfR6GEHIX0ykKrNrXvkljJ uq+z6St2W1kFuFYZMrehzf7tTkPM2xjhkhxV30LzVNRfCsuKG0/0Y03lmMcQ1aRL5mvc 4X+QWSNl7bqFYwF89QiGRMDpnLr3EYlGr1vWUVlVB2n4WwJFimksrPN4q9NZdwJQOu4/ lIoJeFbhfWuMbn1dAXKBnw+yXjEsnZ2VYW1V4ODzGUnUM9PNgvSZXOhUs4ttdMT8wZ4L dnkRT3fSBlW3ybc4AENF4vFuxNr/cMIrY43issSSX4ZJk6TszZPmlapdZdOfWjHVBsTQ v8qg== 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=KMkmgCNfKgi3WzDhObxEB5urzlXMO29exQ9Ky/b/KQA=; b=pc5lixDCj0VBKyXohefoyFS+VMQe9WtHNaFEJzSNdbkvYGXfAZLk2hgPW7jmrybm5X bb8hMRZp5bvO7lMdO3UngsiM1D4AgKhHZxIZe/AyndIgS2uQtfpQ08BkJeQ2IZz3CJCq qqJQ0NDEdEpRsVVpoYqQFPDUA/NdT3hDW4aze3tchDogisHNicl8TI4GnEdnZ+fKm+t8 WVnF9YqdTcwgVbAM6ugCTm4ESPYyUDPMOnADiQUvWvfYCTBqYMw3Y2hI+WpUhZfQm5/V d+q7fqGrFzhKxDUYQXTiUnoW8qGY66lZyh/sYPsiM/GB7oyTyRcIqyIxBoxK4h5yAQbQ y4EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gz6IKZYX; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gs40-20020a1709072d2800b00977e1dabf12si5634323ejc.165.2023.06.07.14.34.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 14:34:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gz6IKZYX; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 F0465385589E for ; Wed, 7 Jun 2023 21:34:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0465385589E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686173673; bh=KMkmgCNfKgi3WzDhObxEB5urzlXMO29exQ9Ky/b/KQA=; 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=Gz6IKZYXaUB2Qjxl//ZcVugy0LFzzmaComl00dc3j8qXpQepu+edsOP+UL3Jd0HV9 meR4Fy9WVEamvycIWiYHICdWpS3sp0264/K1UeSEYGJaMcs5FkT2JauDX5Fxe1H37z rk2KZp5peO79bS5KldBxvLrAJAXpZ0yWB1Pbt+bM= 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 D7AC83857031 for ; Wed, 7 Jun 2023 21:33:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7AC83857031 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 357Jt1Y8020044 for ; Wed, 7 Jun 2023 14:33:08 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3r30eu08e7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 07 Jun 2023 14:33:08 -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:06 -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:06 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id BBFBE3F70A9; Wed, 7 Jun 2023 14:33:01 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/3] Change the `zero_one ==/!= 0) ? y : z y` patterns to use multiply rather than `(-zero_one) & z` Date: Wed, 7 Jun 2023 14:32:16 -0700 Message-ID: <20230607213217.3052696-2-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: i2Utq0dC70sFC4NumLzLSL6M1Cr_Z0C0 X-Proofpoint-GUID: i2Utq0dC70sFC4NumLzLSL6M1Cr_Z0C0 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.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PLING_QUERY, 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?1768081270098400238?= X-GMAIL-MSGID: =?utf-8?q?1768081270098400238?= Since there is a pattern to convert `(-zero_one) & z` into `zero_one * z` already, it is better if we don't do a secondary transformation. This reduces the extra statements produced by match-and-simplify on the gimple level too. gcc/ChangeLog: * match.pd (`zero_one ==/!= 0) ? y : z y`): Use multiply rather than negation/bit_and. --- gcc/match.pd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 7b95b63cee4..c38b39fb45c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3688,7 +3688,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond (le @0 integer_zerop@1) (negate@2 @0) integer_zerop@1) (max @2 @1)) -/* (zero_one == 0) ? y : z y -> (-(typeof(y))zero_one & z) y */ +/* (zero_one == 0) ? y : z y -> ((typeof(y))zero_one * z) y */ (for op (bit_xor bit_ior) (simplify (cond (eq zero_one_valued_p@0 @@ -3698,9 +3698,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) > 1 && (INTEGRAL_TYPE_P (TREE_TYPE (@0)))) - (op (bit_and (negate (convert:type @0)) @2) @1)))) + (op (mult (convert:type @0) @2) @1)))) -/* (zero_one != 0) ? z y : y -> (-(typeof(y))zero_one & z) y */ +/* (zero_one != 0) ? z y : y -> ((typeof(y))zero_one * z) y */ (for op (bit_xor bit_ior) (simplify (cond (ne zero_one_valued_p@0 @@ -3710,7 +3710,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) > 1 && (INTEGRAL_TYPE_P (TREE_TYPE (@0)))) - (op (bit_and (negate (convert:type @0)) @2) @1)))) + (op (mult (convert:type @0) @2) @1)))) /* Simplifications of shift and rotates. */ 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" } } */