From patchwork Sun Apr 28 06:30:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andrew Pinski (QUIC)" X-Patchwork-Id: 1928581 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=V1gi9dm3; 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 4VRxSV4xX0z23t4 for ; Sun, 28 Apr 2024 16:31:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA50C3858CDB for ; Sun, 28 Apr 2024 06:31:35 +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 08A543858D33 for ; Sun, 28 Apr 2024 06:31:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08A543858D33 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 08A543858D33 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=1714285873; cv=none; b=d+S+runl8U5lMQt/PPHMOKCGT6emU+50HGZ0Y4V+yPbxDKHYZ6NKdfxWx7F94nXeVUhl+h3OSRbGoxTZlzMG1zHeI5B6JCe3DW2IY4CVP5cQBuKGSDFiulOHUWcAqRz2VQVhITSXR+t7SNPdUfXkfTOoUDiH5SaC9J4cdLfQctc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714285873; c=relaxed/simple; bh=lkhZvMdlgTI4Guzbh9nQHMHU0p8Zj4pbcv0s8+bnBT0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ibT3F4XbITyeELFwxCPlZjyXeK/6T2bCza53D4UMeeGSwYbTEabyC9JlXTZ9Ai8IdXcJzH9bffBWvoX8WPlqZJsEiHW50FlWJPEfMaQDpabnidBp/38Rxl4KBl47YzpYwJYBI8jSLCT+ibNrAmxRyo4alU/6147NpdywWNs09bQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 43S6UZYO024457 for ; Sun, 28 Apr 2024 06:31:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=WEaG7rOtdB2RLOE1UgCvjjm+2F0sa/e6Dp6kXwq7EbA=; b=V1 gi9dm3hOlW8ctELXEmGRJUoUuMUoSLcomPs8BKPs2iUft3Fp5FpM7tfd+mmy6tI2 Cp8qix0SmSbFhO78r1/UPMGCOlKWXq4rW7paHrAsT46pxMPbMBwqdMx5II3f6ziv DdzX+GKpkmOKtEnDMPu58AcZKumtuQV0dNvAYU4hCkpXvuZ+PrSqhm/vqFiuZcCf USc4Y0jlEJdjIYGexVeTYf17lSoUoZo4gn/Q1GVhUY6V9oUs80izWKru6H7EnUYf hLbKvznmjhD9Oid2WC3+WZ1eR6a1ePXZ1peV/akwxauAqNTXzC1dnlrNxRE45Put 3xLp06uw1T9kflhYR87Q== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xrt4ksa1v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 28 Apr 2024 06:31:09 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 43S6V8a6019159 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 28 Apr 2024 06:31:08 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; Sat, 27 Apr 2024 23:31:08 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/2] PHI-OPT: speed up value_replacement slightly Date: Sat, 27 Apr 2024 23:30:55 -0700 Message-ID: <20240428063055.3807580-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240428063055.3807580-1-quic_apinski@quicinc.com> References: <20240428063055.3807580-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-GUID: HH3D0DTZnniuJTB_9dZppKN6TuyffyxZ X-Proofpoint-ORIG-GUID: HH3D0DTZnniuJTB_9dZppKN6TuyffyxZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-28_04,2024-04-26_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 impostorscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 phishscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2404280044 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 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 This adds a few early outs to value_replacement that I noticed while rewriting this to use match-and-simplify but could be committed seperately. * virtual operands won't change so return early for them * special case `A ? B : B` as that is already just `B` Also moves the check for NE/EQ earlier as calculating empty_or_with_defined_p is an IR walk for a BB and that might be big. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (value_replacement): Move check for NE/EQ earlier. Signed-off-by: Andrew Pinski --- gcc/tree-ssa-phiopt.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index f1e07502b02..a2bdcb5eae8 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -1131,6 +1131,21 @@ value_replacement (basic_block cond_bb, basic_block middle_bb, enum tree_code code; bool empty_or_with_defined_p = true; + /* Virtual operands don't need to be handled. */ + if (virtual_operand_p (arg1)) + return 0; + + /* Special case A ? B : B as this will always simplify to B. */ + if (operand_equal_for_phi_arg_p (arg0, arg1)) + return 0; + + gcond *cond = as_a (*gsi_last_bb (cond_bb)); + code = gimple_cond_code (cond); + + /* This transformation is only valid for equality comparisons. */ + if (code != NE_EXPR && code != EQ_EXPR) + return 0; + /* If the type says honor signed zeros we cannot do this optimization. */ if (HONOR_SIGNED_ZEROS (arg1)) @@ -1161,13 +1176,6 @@ value_replacement (basic_block cond_bb, basic_block middle_bb, empty_or_with_defined_p = false; } - gcond *cond = as_a (*gsi_last_bb (cond_bb)); - code = gimple_cond_code (cond); - - /* This transformation is only valid for equality comparisons. */ - if (code != NE_EXPR && code != EQ_EXPR) - return 0; - /* We need to know which is the true edge and which is the false edge so that we know if have abs or negative abs. */ extract_true_false_edges_from_block (cond_bb, &true_edge, &false_edge);