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 (QUIC)" X-Patchwork-Id: 170496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3530033vqx; Mon, 27 Nov 2023 15:09:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQ3pnj5d/D3+8v/BgumrDNWjOfVkiY2iNXaEKklBiixJp6FYf5zO54tch3RaPWAGmfHZbo X-Received: by 2002:a05:620a:1266:b0:77d:5f72:3c82 with SMTP id b6-20020a05620a126600b0077d5f723c82mr13212792qkl.32.1701126565294; Mon, 27 Nov 2023 15:09:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701126565; cv=pass; d=google.com; s=arc-20160816; b=h5uGheSmwjLu10bHOFvffjI7E0foosTZ3vCTScGOMm1t5fep5sQfUSJvPWbdy3xoTZ BQ44NpPiAV58HL6aNSITXIsssbCBALhj/2adkKxCkTYRN2z2uocNNMb8ESflRvvb+f86 u5r3zip3GouOCZ8/JG2KtJc6bZ8ve03U29skvWT6J+5ANmmb0LXgDAJvR2l5Y6gJrPN0 eqxgk/KkGiaYeOJq73Ygjmj06tIlWLFax0kDcYk7o17srQeaJ8lGGJ+TAxfjeP5HJlUO 3YcoSVAlwy5Pj5y6rPu8Vkgr5es3P9JnFM4ah7AlqjhpZsea39utCV/nafR0PNaROrmJ Uexw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=rz55fHatE1PkZ3Mt4JYMyBEodmBS4WIJeCJd5f0Vsmg=; fh=gk9A5O7Gbglvz1MjrRQ4hZ2i3c68kYkpOZJg1emXh+g=; b=NCxAElho31qprZg8r6Bav3XEemf8bvs/ZqICl9XW+7Q2V3kg2wxtgoedbbKzZ1m7mT B4jKk/eZXtNGQ7TksuUuofskyCXMeMajNaEQfpIS0IDQjDKjQ9BrSyo/KvpeApiJ/HWX OUkQQqcxA5+aEy+D4ZUxjPAOd2ml1vqJLPcabvNI94iJgXPrq4S+rLxbkJv3LPnQ1pLS 0O6a2Bnuv0NTN81mb8GG4ONiXIg8527uY5NQQUbpdqikg9TXZtp/wgvEntl3Z6EfUsRW 32UgOogh6b6SXVd+nJEsQa3Se6Ncug2G7C4ogn3gWTSOMjbwJJoEdr762rNYle60CIos sKlQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=YlqFbNs0; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bm18-20020a05620a199200b0077d9ad46191si5254375qkb.116.2023.11.27.15.09.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 15:09:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=YlqFbNs0; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A8C13858298 for ; Mon, 27 Nov 2023 23:09:25 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783690331267077388 X-GMAIL-MSGID: 1783760489389277412 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; +}