From patchwork Mon May 27 00:46:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1939539 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=atLBPqMF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VncS13B69z20KL for ; Mon, 27 May 2024 10:47:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F7333858D28 for ; Mon, 27 May 2024 00:47:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id 58D5E3858D28 for ; Mon, 27 May 2024 00:46:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58D5E3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58D5E3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716770819; cv=none; b=Kgi0Ex0edWG2sctypcVxLVTbDhWKRr3G8hn4ZZBBnijE2C9Fk8cl4i54Mdi4MFoXHKsrAjdvOsiz2qlu24zrBnMvIlucBfQ8pKUQtTNcB/kux0FU6Z2vWPTkdoGHUSU/sr8VT6Lo47EtnzbrnQ6d8zW+i+W8d9gOvvLRXxQUKbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716770819; c=relaxed/simple; bh=DIIrDvr8AQVAWsnOTZe+BQlsWdWCpSMKvABaLeK8bhI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jDLtWbxhpnel12flYL1p+MYOXvjSyHOrx8CdbggDZubQ8E5XguZxcYyIUEQdmd/Wg76intKvIKqCCsv01T2u4drnxZzqQFJE6VxqIGRIUZm8P5VwxPBB4Z5tMR1QzN1cAYfB6ZbZOJUMzveftOg4YsC5KjVnUUrP9JROfSRqQ2c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44QN8vQ1029895 for ; Mon, 27 May 2024 00:46:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=HxI5ZFRylDtrIFyTy/ycGj kYhE+aGiT+pag35slYrZs=; b=atLBPqMFRlBQbRC0Nld48Dw0j+f6yvgoVjuQ88 wTPluwSnn2Rz0TXT8r8GSyExnJDvzmG4sKT/v1TZkY4YyG9kyyJuNlbLIA0Wbb59 7avanss9zDnFMgruDcwjEpOfuBBvTsyOO3Set9bOTF5Z6CiXX0AO419yMmqFL4OE dyjnb8wdGFuDbUQrFOQnvtZkpvqLk4/jLR+f/3Jr96oJT9Ia/yoN+vmVUhMnREJR hNE2k/jcFjq+hXb6A3xWNpX5k+9jXvp/HXmg3MSI0SDpgN8yMyF+3SEZ6iwtIx67 r3PeskLb9HcsusJaHbmHoBhjyYrAY5BQVgKrc2Uphq39xQ6w== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yb9yj2acp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 May 2024 00:46:57 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44R0kumw016838 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 May 2024 00:46:56 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 26 May 2024 17:46:56 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/2] Match: Add maybe_bit_not instead of plain matching Date: Sun, 26 May 2024 17:46:42 -0700 Message-ID: <20240527004643.990621-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: uren6vUwaK1cgMc0itW9MNu5Tgvq5dXs X-Proofpoint-ORIG-GUID: uren6vUwaK1cgMc0itW9MNu5Tgvq5dXs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-26_09,2024-05-24_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405270004 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org While working on adding matching of negative expressions of `a - b`, I noticed that we started to have "duplicated" patterns due to not having a way to match maybe negative expressions. So I went back to what I did for bit_not and decided to improve the situtation there so for some patterns where we had 2 operands of an expression where one could have been a bit_not, add back maybe_bit_not. This does not add maybe_bit_not in every place were bitwise_inverted_equal_p is used, just the ones were 2 operands of an expression could be swapped. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd (bit_not_with_nop): Unconditionalize. (maybe_cmp): Likewise. (maybe_bit_not): New match pattern. (`~X & X`): Use maybe_bit_not and add `:c` back. (`~x ^ x`/`~x | x`): Likewise. Signed-off-by: Andrew Pinski --- gcc/match.pd | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 024e3350465..090ad4e08b0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -167,7 +167,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0))) && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@0)))))) -#if GIMPLE /* These are used by gimple_bitwise_inverted_equal_p to simplify detection of BIT_NOT and comparisons. */ (match (bit_not_with_nop @0) @@ -188,7 +187,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_xor@0 @1 @2) (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1))) -#endif +/* maybe_bit_not is used to match what + is acceptable for bitwise_inverted_equal_p. */ +(match (maybe_bit_not @0) + (bit_not_with_nop@0 @1)) +(match (maybe_bit_not @0) + (INTEGER_CST@0)) +(match (maybe_bit_not @0) + (maybe_cmp@0 @1)) /* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR ABSU_EXPR returns unsigned absolute value of the operand and the operand @@ -1332,7 +1338,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Simplify ~X & X as zero. */ (simplify - (bit_and (convert? @0) (convert? @1)) + (bit_and:c (convert? @0) (convert? (maybe_bit_not @1))) (with { bool wascmp; } (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1)) && bitwise_inverted_equal_p (@0, @1, wascmp)) @@ -1597,7 +1603,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* ~x ^ x -> -1 */ (for op (bit_ior bit_xor) (simplify - (op (convert? @0) (convert? @1)) + (op:c (convert? @0) (convert? (maybe_bit_not @1))) (with { bool wascmp; } (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1)) && bitwise_inverted_equal_p (@0, @1, wascmp))