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)) From patchwork Mon May 27 00:46:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1939540 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=fn7Fq5qu; 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 4VncSw6bNYz20KL for ; Mon, 27 May 2024 10:48:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 258583858289 for ; Mon, 27 May 2024 00:48:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id B4E603858D34 for ; Mon, 27 May 2024 00:46:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4E603858D34 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 B4E603858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716770820; cv=none; b=mDABNRjxDW6dY/WhCWd9ZU3vPgDA1Bxep1t3sqkubTDK6amWMwCUY5FP4dOmz7YImCg7qpKkVKAY+YXn8ZzwcWBsNySpaxgCywLI6ufDu1ANkH9ZjjKd+5NvmKC6qYDQLm2lQpxvV0757FFkEZw8nybDYBKYJflYpfZnxCu7btI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716770820; c=relaxed/simple; bh=WT5OA8lPFiC+9jSKjlobGadXm4/gXO0CVsBQOkHqjk4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sAdzr2mI59D9FwGVTixHkWfwTvgr/ao0FsurW7Gi2oULMlt8aQO6awMOHKT6My+lawYMb9FkQLDhZR0sfrdkxn4eZ0wbUUN0gp1SOD6mbhMvHjL1/2ufNdH26p6JIQrg/sWckFQOKNDmAucyD24dJrdvgvSaCExGkiOhUA77cp0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44QNF88F032036 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:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= aMUSbueI3TPEpfs8Jxi0FXnj36HwjrmlMVkVg4PrK+0=; b=fn7Fq5quMZ5G6Qhk IDxwWZEmQrlqzH4BJW0omWprY0Cjlq7EteSPFBfWgBTysUUBibzvo/QMknrJ5WlS axiIqzxeoiGp7h8jDPwGMJit/UogqtXGU4E1qL8+qm7QLnSM53gG08sYMI3bkiqU ajhVYKKxpXvXar5XVX4aFFgwxM2dFCWq7+FB2FINgytZgQHHtR7teAsbYCLTeWlB xRdFzlDFk/RCjt0QWH0mWThkkAvl7LA4usin9eagbnBg1ImIxOBzzf310Yp5eW15 /lZFbJY9X24ld65Sbwy1viAVWMmxbWaDBmP3aUPzehR4zZ+ZWC/4CTdsT2br6kfb vfwfYg== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba0pj9cv-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 NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44R0kuR6025238 (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 2/2] match: Add support for `a ^ CST` to bitwise_inverted_equal_p [PR115224] Date: Sun, 26 May 2024 17:46:43 -0700 Message-ID: <20240527004643.990621-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527004643.990621-1-quic_apinski@quicinc.com> References: <20240527004643.990621-1-quic_apinski@quicinc.com> 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-ORIG-GUID: OxVd-TRBARzM03kT_geJVYpiTrao36Fo X-Proofpoint-GUID: OxVd-TRBARzM03kT_geJVYpiTrao36Fo 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 mlxlogscore=999 bulkscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 impostorscore=0 malwarescore=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 looking into something else, I noticed that `a ^ CST` needed to be special casing to bitwise_inverted_equal_p as it would simplify to `a ^ ~CST` for the bitwise not. Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/115224 gcc/ChangeLog: * generic-match-head.cc (bitwise_inverted_equal_p): Add `a ^ CST` case. * gimple-match-head.cc (gimple_bit_xor_cst): New declaration. (gimple_bitwise_inverted_equal_p): Add `a ^ CST` case. * match.pd (bit_xor_cst): New match. (maybe_bit_not): Add bit_xor_cst case. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/bitops-8.c: New test. Signed-off-by: Andrew Pinski --- gcc/generic-match-head.cc | 10 ++++++++++ gcc/gimple-match-head.cc | 13 +++++++++++++ gcc/match.pd | 4 ++++ gcc/testsuite/gcc.dg/tree-ssa/bitops-8.c | 15 +++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bitops-8.c diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc index e2e1e4b2d64..3709fe5456d 100644 --- a/gcc/generic-match-head.cc +++ b/gcc/generic-match-head.cc @@ -156,6 +156,16 @@ bitwise_inverted_equal_p (tree expr1, tree expr2, bool &wascmp) if (TREE_CODE (expr2) == BIT_NOT_EXPR && bitwise_equal_p (expr1, TREE_OPERAND (expr2, 0))) return true; + + /* `X ^ CST` and `X ^ ~CST` match for ~. */ + if (TREE_CODE (expr1) == BIT_XOR_EXPR && TREE_CODE (expr2) == BIT_XOR_EXPR + && bitwise_equal_p (TREE_OPERAND (expr1, 0), TREE_OPERAND (expr2, 0))) + { + tree cst1 = uniform_integer_cst_p (TREE_OPERAND (expr1, 1)); + tree cst2 = uniform_integer_cst_p (TREE_OPERAND (expr2, 1)); + if (cst1 && cst2 && wi::to_wide (cst1) == ~wi::to_wide (cst2)) + return true; + } if (COMPARISON_CLASS_P (expr1) && COMPARISON_CLASS_P (expr2)) { diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc index 49b1dde6ae4..d5908f4e9a6 100644 --- a/gcc/gimple-match-head.cc +++ b/gcc/gimple-match-head.cc @@ -283,6 +283,7 @@ gimple_bitwise_equal_p (tree expr1, tree expr2, tree (*valueize) (tree)) bool gimple_bit_not_with_nop (tree, tree *, tree (*) (tree)); bool gimple_maybe_cmp (tree, tree *, tree (*) (tree)); +bool gimple_bit_xor_cst (tree, tree *, tree (*) (tree)); /* Helper function for bitwise_inverted_equal_p macro. */ @@ -299,6 +300,18 @@ gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, bool &wascmp, tree (*va if (operand_equal_p (expr1, expr2, 0)) return false; + tree xor1[2]; + tree xor2[2]; + /* `X ^ CST` and `X ^ ~CST` match for ~. */ + if (gimple_bit_xor_cst (expr1, xor1, valueize) + && gimple_bit_xor_cst (expr2, xor2, valueize)) + { + if (operand_equal_p (xor1[0], xor2[0], 0) + && (wi::to_wide (uniform_integer_cst_p (xor1[1])) + == ~wi::to_wide (uniform_integer_cst_p (xor2[1])))) + return true; + } + tree other; /* Try if EXPR1 was defined as ~EXPR2. */ if (gimple_bit_not_with_nop (expr1, &other, valueize)) diff --git a/gcc/match.pd b/gcc/match.pd index 090ad4e08b0..480e36bbbaf 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -174,6 +174,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (match (bit_not_with_nop @0) (convert (bit_not @0)) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))))) +(match (bit_xor_cst @0 @1) + (bit_xor @0 uniform_integer_cst_p@1)) (for cmp (tcc_comparison) (match (maybe_cmp @0) (cmp@0 @1 @2)) @@ -195,6 +197,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (INTEGER_CST@0)) (match (maybe_bit_not @0) (maybe_cmp@0 @1)) +(match (maybe_bit_not @0) + (bit_xor_cst@0 @1 @2)) /* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR ABSU_EXPR returns unsigned absolute value of the operand and the operand diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bitops-8.c b/gcc/testsuite/gcc.dg/tree-ssa/bitops-8.c new file mode 100644 index 00000000000..40f756e4455 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/bitops-8.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/115224 */ + +int f1(int a, int b) +{ + a = a ^ 1; + int c = ~a; + return c | (a ^ b); + // ~((a ^ 1) & b) or (a ^ -2) | ~b +} +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "bit_ior_expr, " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "bit_not_expr, " 1 "optimized" } } */ +