From patchwork Mon Nov 27 23:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1869044 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=YlqFbNs0; 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 4SfLrC2qxnz1yRy for ; Tue, 28 Nov 2023 10:09:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD24E3857BA8 for ; Mon, 27 Nov 2023 23:09:12 +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 3C1983858C2D for ; Mon, 27 Nov 2023 23:09:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C1983858C2D 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 3C1983858C2D 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=1701126541; cv=none; b=T6NPaEtrk2rt8g/id44gk1oiLW/R3PdN8/n/1/0UCdFLUOdhNvBSTkd5kAJJzC5BTkdmtoMOd20K5sAwONOaEu3KfMmlfqzwJH4V9uAAhKCjxGv3NCGP2vqioH4OQnxj0pUIIzIwDGk6JGOPc79WhoNIB5Z73p90BUlRa7VhemM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701126541; c=relaxed/simple; bh=Hmmk7Olxx0bFq9eM1EUKFqvMlH6CosZROCwLs0Ov4U4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gPEK0AbL6M0iQ0qIqhm3QSVAx7kZ+4OgpVCKHrfj4xmu04Uxxo09QYjzP/Ua4R5uk+BxcolmQdEWB7McUNOubsyrUVDw2/gyp6oZi2gfiBcomKbEX9+aFG+oIkJYIKQx/l6BnvFlS7ZaAf3LIQDJ28gBmq+LT1Z1zmVZYU249mw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ARMPQwc029771 for ; Mon, 27 Nov 2023 23:08:58 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=rz55fHatE1PkZ3Mt4JYMyBEodmBS4WIJeCJd5f0Vsmg=; b=YlqFbNs0hRAOGQ9ukm/0rzhxqkx89+WlIQVn8C/3Z/y731RVDQuiDqqdoIKPuaeh0XMq oOi3ZlxvSB8nocYtfpaCXPLpxMf0Tbl/sgoW3tPwhKuzeOt+2uULu1dHTaO0FLIv9FQj H2kCoU+zeyNuA5lgKRw9EYDk2FZTJwF8a5PPb3mzrZlL1R9EfmfCMxIfz/2u5warRtDH ohS5XD27R4xdKtyssoWculwZGJGmZnzzwevLHfVokNp8ZM/8KQOP7pnSCgfZwhdddo8/ TFZ03hoJ5vyHDQ5ztvuSmMZcbLzaXdOqdK71ihtcX2nrIDusxwjEgubBi8o2LzA+SxA8 LQ== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3umwn5s4g6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 Nov 2023 23:08:55 +0000 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 3ARN8spC003357 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 Nov 2023 23:08:54 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; Mon, 27 Nov 2023 15:08:54 -0800 From: Andrew Pinski To: Subject: [PATCH] aarch64: Improve cost of `a ? {-,}1 : b` Date: Mon, 27 Nov 2023 15:08:45 -0800 Message-ID: <20231127230845.615689-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: nalasex01b.na.qualcomm.com (10.47.209.197) 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: 0V3HEe_SZkZxOGhfBYIzB5TkzLkbLHw9 X-Proofpoint-GUID: 0V3HEe_SZkZxOGhfBYIzB5TkzLkbLHw9 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-27_19,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=493 adultscore=0 spamscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270162 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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 fully fix PR 112454 as that requires other changes to forwprop the `(const_int 1)` earlier than combine. Though we do fix the loop case where the constant was only used once. Committed as approved after bootstrapped and tested on aarch64-linux-gnu with no regressions. gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_if_then_else_costs): Handle csinv/csinc case of 1/-1. gcc/testsuite/ChangeLog: * gcc.target/aarch64/csinc-3.c: New test. Signed-off-by: Andrew Pinski --- gcc/config/aarch64/aarch64.cc | 12 ++++++++++++ gcc/testsuite/gcc.target/aarch64/csinc-3.c | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/csinc-3.c diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index b2093430937..4fd8c2de43a 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -11607,6 +11607,18 @@ 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); } + else if (op1 == constm1_rtx || op1 == const1_rtx) + { + /* Use CSINV or CSINC. */ + *cost += rtx_cost (op2, VOIDmode, IF_THEN_ELSE, 2, speed); + return true; + } + else if (op2 == constm1_rtx || op2 == const1_rtx) + { + /* Use CSINV or CSINC. */ + *cost += rtx_cost (op1, VOIDmode, IF_THEN_ELSE, 1, speed); + return true; + } *cost += rtx_cost (op1, VOIDmode, IF_THEN_ELSE, 1, speed); *cost += rtx_cost (op2, VOIDmode, IF_THEN_ELSE, 2, speed); diff --git a/gcc/testsuite/gcc.target/aarch64/csinc-3.c b/gcc/testsuite/gcc.target/aarch64/csinc-3.c new file mode 100644 index 00000000000..bde131a584e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/csinc-3.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-vectorize" } */ + +int f(int *a, int n, int *b, int d) +{ + for(int i = 0; i < n; i++) + b[i] = a[i] == 100 ? 1 : d; + /* { dg-final { scan-assembler "csinc\tw\[0-9\].*wzr" } } */ + return 0; +}