From patchwork Sat May 13 03:08:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 93475 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5530696vqo; Fri, 12 May 2023 20:09:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QKHKrOYQNUCOo3hCNOOgqRrDmZw3WYw9jdKYypGSGb5n6ajHXvFzw2X5Qzlu+gEB2NTdb X-Received: by 2002:a17:907:1b29:b0:94f:2d5f:6949 with SMTP id mp41-20020a1709071b2900b0094f2d5f6949mr28584835ejc.42.1683947360572; Fri, 12 May 2023 20:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683947360; cv=none; d=google.com; s=arc-20160816; b=GvvTGO7rhb54lq7KkjEdMICd2lj68FakrxETy4kEd546aG0WoQzmq/O1gZOuPN4w0x nPdFBMCC0O4dBKKvkBFFd9jJzdZ4ClLGKPzqXpigSFf2w/ezIitDJ0sIhtmTQsDVoG6D 4Gvq3vwMcqtqHHxmyMqDLttOK+X3TRJU3P+JoYvWGNRHyu6PXqeCsPubO/czSSsm3P3B PWGhuCPdr+fst3w2OEh7Xuh1SPpz/yHUA24WZ4tG8msJH67mM7eh+uFbwUf+eyDO82X9 F/HbJGgWdCrm/2xuXh5nlFcnhqVY3oEF11AzYhYO2n9XPX7aeuHHa0ecKjEmlhdFebK9 opGA== 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=u0IQrjvd5LXF/3sVaiV+7hAS0lqDPx8u0StkdvmWrhk=; b=pxFpEbkHKutHbJVsnTx4ZMJ/CVPIM+cR3m5Mf9jKt8dg6aGxTsmUnfQZUMkQwFiDgi 4SPuybIuahc00cEq+ELwjsoO2itP1W1+POOmrQuWtF7iBK+CaUfIh4o4+dWJcP4weXTd 3N2bfdBTHjsfigs7QbJyHsywCTwbFq/d0//eJqssZvvB/IPKvYORzIlnX6AKyzq+DerY cB3GpJlAV8+ivrPUx+WXAPUIkqvFr71K7sTFOJVordgLWcj+wGxD3BGJ7HYsUadVyBFA GOZHA210Eh5QL2ddCz6UXB0xmlxn9j6n3xweeEw+RO2z06NRP3MBuHrueyBpjw567MAj zRlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oDDVPQKx; 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 p17-20020a05640210d100b0050bf9cf06a6si6745300edu.303.2023.05.12.20.09.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 20:09:20 -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=oDDVPQKx; 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 30D45385840E for ; Sat, 13 May 2023 03:09:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30D45385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683947359; bh=u0IQrjvd5LXF/3sVaiV+7hAS0lqDPx8u0StkdvmWrhk=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=oDDVPQKxLgXuZLiVchiSrT9jRUdNWL/XPbrbl3ZP5+CJlmfUkGxEFHdlBxJmPXynf WZgGu56pYeLtO4acazw/FvhV0DKqVxarYJXroOTJPnGFUIdz3kOxvhZK9GxYGsef+F T9fmKT3VtTtpppwyF5nICD/FxNrsYJZQlg8FdW2w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 671333858CDB for ; Sat, 13 May 2023 03:08:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 671333858CDB Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34CKN74Y026546 for ; Fri, 12 May 2023 20:08:34 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qhs82sveg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 12 May 2023 20:08:34 -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; Fri, 12 May 2023 20:08:32 -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; Fri, 12 May 2023 20:08:32 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id D70833F70D3; Fri, 12 May 2023 20:08:29 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Fix PR 109834, ICE with popcount combined with bswap Date: Fri, 12 May 2023 20:08:22 -0700 Message-ID: <20230513030822.1481372-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: 9YtoajabLVkAw7wcat3P3hrZ0XpuTUz- X-Proofpoint-ORIG-GUID: 9YtoajabLVkAw7wcat3P3hrZ0XpuTUz- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-12_16,2023-05-05_01,2023-02-09_01 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_NONE, 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?1765746787759993356?= X-GMAIL-MSGID: =?utf-8?q?1765746787759993356?= After r14-673-gc0dd80e4c4c3, there was a check in the match patterns which was checking the type is unsigned but instead of using the type, the patch used the expression. This adds the needed TREE_TYPE so get the correct answer and don't ICE. Committed as obvious after a bootstrap/test on x86_64-linux-gnu. PR tree-optimizion/109834 gcc/ChangeLog: * match.pd (popcount(bswap(x))->popcount(x)): Fix up unsigned type checking. (popcount(rotate(x,y))->popcount(x)): Likewise. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr109834-1.c: New test. * gcc.dg/tree-ssa/pr109834-1.c: New test. --- gcc/match.pd | 4 ++-- gcc/testsuite/gcc.c-torture/compile/pr109834-1.c | 4 ++++ gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr109834-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 60b01643be5..3089fe309fd 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7867,7 +7867,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && INTEGRAL_TYPE_P (TREE_TYPE (@1))) (with { unsigned int prec0 = TYPE_PRECISION (TREE_TYPE (@0)); unsigned int prec1 = TYPE_PRECISION (TREE_TYPE (@1)); } - (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (@1))) + (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (TREE_TYPE (@1)))) (popcount @2))))))) /* popcount(rotate(X Y)) is popcount(X). */ @@ -7880,7 +7880,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (GIMPLE || !TREE_SIDE_EFFECTS (@3))) (with { unsigned int prec0 = TYPE_PRECISION (TREE_TYPE (@0)); unsigned int prec1 = TYPE_PRECISION (TREE_TYPE (@1)); } - (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (@1))) + (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (TREE_TYPE (@1)))) (popcount @2))))))) /* Canonicalize POPCOUNT(x)&1 as PARITY(X). */ diff --git a/gcc/testsuite/gcc.c-torture/compile/pr109834-1.c b/gcc/testsuite/gcc.c-torture/compile/pr109834-1.c new file mode 100644 index 00000000000..e6c015249b2 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr109834-1.c @@ -0,0 +1,4 @@ +int f (char v) +{ + return __builtin_popcount((int)__builtin_bswap16(v)); +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c new file mode 100644 index 00000000000..f2af18b0cd0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr109834-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +int f (char v) +{ + return __builtin_popcount((int)__builtin_bswap16(v)); +} + +/* We should be able to remove the bswap here as it does not matter + for the popcount. */ +/* { dg-final { scan-tree-dump-not "bswap" "optimized"} } */