[2/3] Change the `zero_one ==/!= 0) ? y : z <op> y` patterns to use multiply rather than `(-zero_one) & z`
Message ID | 20230607213217.3052696-2-apinski@marvell.com |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> 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 <ouuuleilei@gmail.com> (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 <ouuuleilei@gmail.com>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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: <gcc-patches@gcc.gnu.org> CC: Andrew Pinski <apinski@marvell.com> Subject: [PATCH 2/3] Change the `zero_one ==/!= 0) ? y : z <op> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Andrew Pinski via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Andrew Pinski <apinski@marvell.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768081270098400238?= X-GMAIL-MSGID: =?utf-8?q?1768081270098400238?= |
Series |
[1/3] MATCH: Allow unsigned types for `X & -Y -> X * Y` pattern
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Andrew Pinski
June 7, 2023, 9:32 p.m. UTC
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 <op> y`): Use multiply rather than negation/bit_and. --- gcc/match.pd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Comments
On 6/7/23 15:32, Andrew Pinski via Gcc-patches wrote: > 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 <op> y`): Use > multiply rather than negation/bit_and. Don't you need to check the types in a manner similar to what the A & -Y -> X * Y pattern does before you make this transformation? jeff
On Wed, Jun 7, 2023 at 3:57 PM Jeff Law via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > On 6/7/23 15:32, Andrew Pinski via Gcc-patches wrote: > > 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 <op> y`): Use > > multiply rather than negation/bit_and. > Don't you need to check the types in a manner similar to what the A & -Y > -> X * Y pattern does before you make this transformation? No, because the convert is in a different order than in that transformation; a very subtle difference which makes it work. In A & -Y it was matching: (bit_and (convert? (negate But here we have: (bit_and (negate (convert Notice the convert is in a different location, in the `A & -Y` case, the convert needs to be a sign extending (or a truncation) of the negative value. Here we are converting the one_zero_value to the new type so we get zero_one in the new type and then doing the negation getting us 0 or -1 value. Thanks, Andrew > > jeff >
On 6/7/23 17:05, Andrew Pinski wrote: > On Wed, Jun 7, 2023 at 3:57 PM Jeff Law via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> >> >> On 6/7/23 15:32, Andrew Pinski via Gcc-patches wrote: >>> 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 <op> y`): Use >>> multiply rather than negation/bit_and. >> Don't you need to check the types in a manner similar to what the A & -Y >> -> X * Y pattern does before you make this transformation? > > No, because the convert is in a different order than in that > transformation; a very subtle difference which makes it work. > > In A & -Y it was matching: > (bit_and (convert? (negate > But here we have: > (bit_and (negate (convert > Notice the convert is in a different location, in the `A & -Y` case, > the convert needs to be a sign extending (or a truncation) of the > negative value. Here we are converting the one_zero_value to the new > type so we get zero_one in the new type and then doing the negation > getting us 0 or -1 value. THanks for the clarification. OK for the trunk. jeff
On Wed, Jun 7, 2023 at 4:11 PM Jeff Law <jeffreyalaw@gmail.com> wrote: > > > > On 6/7/23 17:05, Andrew Pinski wrote: > > On Wed, Jun 7, 2023 at 3:57 PM Jeff Law via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> > >> > >> On 6/7/23 15:32, Andrew Pinski via Gcc-patches wrote: > >>> 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 <op> y`): Use > >>> multiply rather than negation/bit_and. > >> Don't you need to check the types in a manner similar to what the A & -Y > >> -> X * Y pattern does before you make this transformation? > > > > No, because the convert is in a different order than in that > > transformation; a very subtle difference which makes it work. > > > > In A & -Y it was matching: > > (bit_and (convert? (negate > > But here we have: > > (bit_and (negate (convert > > Notice the convert is in a different location, in the `A & -Y` case, > > the convert needs to be a sign extending (or a truncation) of the > > negative value. Here we are converting the one_zero_value to the new > > type so we get zero_one in the new type and then doing the negation > > getting us 0 or -1 value. > THanks for the clarification. OK for the trunk. So even though my transformation is correct based on what was done in match.pd but that was broken already for signed one bit integers: ``` struct s { int t : 1; }; int f(struct s t, int a, int b) { int bd = t.t; if (bd) a|=b; return a; } ``` I am going to withdraw this patch and fix that up first. Thanks, Andrew > > jeff
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 <op> y -> (-(typeof(y))zero_one & z) <op> y */ +/* (zero_one == 0) ? y : z <op> y -> ((typeof(y))zero_one * z) <op> 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 <op> y : y -> (-(typeof(y))zero_one & z) <op> y */ +/* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> 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. */