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: 1780887 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=JYTd6sPu; 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 4QJ9Zh4cj4z20dC for ; Sat, 13 May 2023 13:09:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EEDBA385701E for ; Sat, 13 May 2023 03:08:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEDBA385701E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683947335; 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=JYTd6sPuhb9lgsrJMBOLXhF6Y/KOU+jStbbij9qWbqgUcMpxzjttKCPcJw4pmCOrR 3Zw5gZA0BgomtbSHHI+qmMQNOW0wFKHEFLxisPomWni4XJPcsazRdVay2tHp8sow58 7/t7b497E5/2LK7D2bUGIQD4xKfsnjIyFlkd+oYk= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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"} } */