From patchwork Mon Nov 27 04:33:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1868606 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=gyRleUE7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4Sdt5d4Kccz1yS6 for ; Mon, 27 Nov 2023 15:34:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 529023858428 for ; Mon, 27 Nov 2023 04:34:05 +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 E4AAC3858D33 for ; Mon, 27 Nov 2023 04:33:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E4AAC3858D33 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 E4AAC3858D33 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=1701059634; cv=none; b=i4Q+AFa6zfUyAKJyCQmlw+avTTiHz13Ph2hCoxd5xlfrrk2xapogPxreWFS0nS86k/pxqqWizZo/y8kOuUPK9wGfLPZgQvBcJ+hUffwcCge9qX5gncAoOa6iRDtFy6eN7m8mqF0a/AoydimyreutuIcqZhoyOPwmoJs2jTPEFuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701059634; c=relaxed/simple; bh=G9ZFabytDZ0RRS0zTRSuTk1U4+eVAOW7W5Ov+JSooBw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uvqictccMtRQMqu0c0RAxND6EDGDmOtkMdztvO+JZw8D8IwdD0fhE/PVMIbrUDxk/KHHebaOuyfRIixinhoBWKDjdgn3Hay+OYGvNeDd0DPEv5yd9N6wFPruand7f5ZUN1cXYYgH2DJLLwBjLd4ui0hpgBqfYPzTAY/dLyKiTZY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AR32xhT013780 for ; Mon, 27 Nov 2023 04:33:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=kA+PT/quHgq52Bcpi8+M0CDP0DSy4o27WAdfBMuvrQM=; b=gyRleUE71afcjzdfDZfhZNGo79IcH+k3ulei1gXjDBBQU2CziXhz+U0mj2zoi7JPMqXe tM3HFjBNb/01OGfMGV+RsRaj8ONDHUycZk0Ay5KMV4q1y5QzchBaQVVCenjTHONmzcWP ATa5dyfaxTJCWCwNm9gJAbv1sQkq7lKwqvMpdLTnre9Sp2i4DjSsAPB2caT8OnSgX2xL kgTCh4JZm0LLAN5D15eE6XNxbPPhwxr4nftGO98n/hwInckRagzamV7WAlPwVbRM/agq r/4XaFRh90hJtIglRK0CECuWPDCfNZ43N9L+iIuCPCV5MAtd3zUI3+XZD681xO98LThI WQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uk69ubetg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 Nov 2023 04:33:50 +0000 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 3AR4XmCr003298 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 Nov 2023 04:33:48 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.1118.40; Sun, 26 Nov 2023 20:33:48 -0800 From: Andrew Pinski To: Subject: [PATCH] aarch64: Improve cost of `a ? {-,}1 : b` Date: Sun, 26 Nov 2023 20:33:33 -0800 Message-ID: <20231127043333.1955900-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-ORIG-GUID: ba9q6Fw2noggF2YmV7vEZO47_4Aq12hQ X-Proofpoint-GUID: ba9q6Fw2noggF2YmV7vEZO47_4Aq12hQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-26_25,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 adultscore=0 spamscore=0 mlxlogscore=466 mlxscore=0 phishscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270032 X-Spam-Status: No, score=-13.2 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 PR 112454, I found the cost for `(if_then_else (cmp) (const_int 1) (reg))` was being recorded as 8 (or `COSTS_N_INSNS (2)`) but it should have been 4 (or `COSTS_N_INSNS (1)`). This improves the cost by not adding the cost of `(const_int 1)` to the total cost. It does not does not fix PR 112454 as that requires other changes to forwprop the `(const_int 1)` earlier than combine. Bootstrapped and tested on aarch64-linux-gnu with no regressions. gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_if_then_else_costs): Don't add the cost of `1` or `-1`. Signed-off-by: Andrew Pinski --- gcc/config/aarch64/aarch64.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index f6f6f94bf43..63241c5aaa5 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -11642,9 +11642,16 @@ aarch64_if_then_else_costs (rtx op0, rtx op1, rtx op2, int *cost, bool speed) /* CSINV/NEG with zero extend + const 0 (*csinv3_uxtw_insn3). */ op1 = XEXP (inner, 0); } - - *cost += rtx_cost (op1, VOIDmode, IF_THEN_ELSE, 1, speed); - *cost += rtx_cost (op2, VOIDmode, IF_THEN_ELSE, 2, speed); + if (op2 == constm1_rtx || op2 == const1_rtx) + *cost += rtx_cost (op1, VOIDmode, IF_THEN_ELSE, 1, speed); + else if (op1 == constm1_rtx || op1 == const1_rtx) + *cost += rtx_cost (op2, VOIDmode, IF_THEN_ELSE, 2, speed); + else + { + *cost += rtx_cost (op1, VOIDmode, IF_THEN_ELSE, 1, speed); + *cost += rtx_cost (op2, VOIDmode, IF_THEN_ELSE, 1, speed); + } + return true; }