From patchwork Sat Apr 22 16:38:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 86608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1797950vqo; Sat, 22 Apr 2023 09:39:06 -0700 (PDT) X-Google-Smtp-Source: AKy350bAuKI1tQhY3rUCaG1ym9QrajD5pqg3GEOUbOclGpg9MyOh38wvxg3hJDEGnvINAXdSUq1v X-Received: by 2002:a17:906:9144:b0:94e:8431:4767 with SMTP id y4-20020a170906914400b0094e84314767mr5826815ejw.38.1682181546429; Sat, 22 Apr 2023 09:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682181546; cv=none; d=google.com; s=arc-20160816; b=nlhILcJnLFkvwjDp4GLfC5L/KRC4X53ToYHwJHoaJhZzckcYGaHTRzoKAcaIOz8qy3 CKWUBvoj5kh9Q2ykZe7DdZOuLeiLUJTt8GGw88D2ZMi7+u4c+hlP32p93RLREenvCXMq tph8caixzpy211/RKqOXzuO2PVIUbIBv7k+dzjzpJ49JiEuAgzOz5hPv83WFE/uxX5qa RQ+gYLc7tSVwbS+/Tg/VeKvcYjsV9XsB7lko+m4OhzzuVJDdcOwRYUFzgssxYgXLlGf5 aNJeH1+1iG8rUVpG0wbOCHUyE13B2bMh/qMaALG/ukhPUwcWe9a7mPSYOKliKdtl4nYB EN6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=LU/DqndoV5d164/9uLHcfuh1FEAhwo9b1LeLnnCM38s=; b=hJ2dyZQtU7tD+LUGpdGfwmw9DbQAESrRP7vUcVJgGOOt2SZKpMSQXw6E/nCMl03mo0 OtncUJSNi5EiWH8Ix7n3mn8APPfzMIqXIA+aSw0UmGv8Xl1Cqi+I7MMPzwgzII4672ZN U6b4MzyffsOPVb1gkXBNGRGvB/S1UvcvXozVN2k4udZKB8IommosX0Xqd2+o2f7/e0mr v4sKclN1LHtvduNGSGjVJJycPgseltaZQ5prTy8ptAQjpnU367hMUn7UYEAsxYazhj62 lxbsbSMRYvH3Jr1aRn5OCni4Fvqy5QCGbVYvyfgAKQZX13nGZ1U39+xU5BGXEZ1Sr5PT tJ0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=J0YpD84A; 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" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hb8-20020a170906b88800b00953464e6dabsi6023007ejb.194.2023.04.22.09.39.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 09:39:06 -0700 (PDT) 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=fail header.i=@nextmovesoftware.com header.s=default header.b=J0YpD84A; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E56573857013 for ; Sat, 22 Apr 2023 16:38:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 94B183858C83 for ; Sat, 22 Apr 2023 16:38:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94B183858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LU/DqndoV5d164/9uLHcfuh1FEAhwo9b1LeLnnCM38s=; b=J0YpD84ABhChjVlHadSiBSY9Fv VMAeMQOiAeSaJcqsDt5jm7LbmOIIODWzeoEF6S60NbLmAPQQb22aQYIm9kFK31nUEwJhz9tKQ+Dfn temD6fU9iJ6H/JSvxFPaQehYikvFWhLwA1gMG504i77LC5Io8mWKM8N6NrawaNwYEwsrsjX/QDIBi j2wY8jlaW4U9yDJ86OaOj8xWOMbBf2mGRXTkOfPGZ+IPjRVrZAJnk3LlFqxwuPOiHMAccK9lzg7s+ AIa+0X4v2oIVi80Ds/9p0NW980yS+Gg/dgqR61wr0nn/wiVMrl7EHzX2H1g73y+SzynF1UC1DJFsc kVeTXEHw==; Received: from [185.62.158.67] (port=60217 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pqGFs-0003Rp-2L for gcc-patches@gcc.gnu.org; Sat, 22 Apr 2023 12:38:32 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [xstormy16 PATCH] Update xstormy16_rtx_costs. Date: Sat, 22 Apr 2023 17:38:30 +0100 Message-ID: <007101d97538$e0734790$a159d6b0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adl1OJMpG54z7JZbQCOVze8Rw1xAAg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763895197244183186?= X-GMAIL-MSGID: =?utf-8?q?1763895197244183186?= This patch provides an improved rtx_costs target hook on xstormy16. The current implementation has the unfortunate property that it claims that zero_extendhisi2 is very cheap, even though the machine description doesn't provide that instruction/pattern. Doh! Rewriting the xstormy16_rtx_costs function has additional benefits, including making more use of the (short) "mul" instruction when optimizing for size with -Os. This patch has been tested by building a cross-compiler to xstormy-elf on x86_64-pc-linux-gnu, and confirming that the new test case passes with "make -k check-gcc". Many thanks to Jeff Law for additional testing. Ok for mainline? 2023-04-22 Roger Sayle gcc/ChangeLog * config/stormy16/stormy16.cc (xstormy16_rtx_costs): Rewrite to provide reasonable values for common arithmetic operations and immediate operands (in several machine modes). gcc/testsuite/ChangeLog * gcc.target/xstormy16/mulhi.c: New test case. Roger diff --git a/gcc/config/stormy16/stormy16.cc b/gcc/config/stormy16/stormy16.cc index 1ed619a..e6d6fbd 100644 --- a/gcc/config/stormy16/stormy16.cc +++ b/gcc/config/stormy16/stormy16.cc @@ -72,19 +72,23 @@ static GTY(()) section *bss100_section; scanned. In either case, *TOTAL contains the cost result. */ static bool -xstormy16_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, +xstormy16_rtx_costs (rtx x, machine_mode mode, int outer_code ATTRIBUTE_UNUSED, - int opno ATTRIBUTE_UNUSED, int *total, - bool speed ATTRIBUTE_UNUSED) + int opno ATTRIBUTE_UNUSED, int *total, bool speed_p) { - int code = GET_CODE (x); + rtx_code code = GET_CODE (x); switch (code) { case CONST_INT: - if (INTVAL (x) < 16 && INTVAL (x) >= 0) - *total = COSTS_N_INSNS (1) / 2; - else if (INTVAL (x) < 256 && INTVAL (x) >= 0) + if (mode == SImode) + { + HOST_WIDE_INT lo_word = INTVAL (x) & 0xffff; + HOST_WIDE_INT hi_word = INTVAL (x) >> 16; + *total = COSTS_N_INSNS (IN_RANGE (lo_word, 0, 255) ? 1 : 2); + *total += COSTS_N_INSNS (IN_RANGE (hi_word, 0, 255) ? 1 : 2); + } + else if (mode == QImode || IN_RANGE(INTVAL (x), 0, 255)) *total = COSTS_N_INSNS (1); else *total = COSTS_N_INSNS (2); @@ -97,12 +101,152 @@ xstormy16_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, *total = COSTS_N_INSNS (2); return true; + case PLUS: + case MINUS: + if (mode == SImode) + { + if (CONST_INT_P (XEXP (x, 1))) + { + HOST_WIDE_INT lo_word = INTVAL (XEXP (x, 1)) & 0xffff; + HOST_WIDE_INT hi_word = INTVAL (XEXP (x, 1)) >> 16; + if (IN_RANGE (lo_word, 0, 16)) + *total = COSTS_N_INSNS (1); + else + *total = COSTS_N_INSNS (2); + if (IN_RANGE (hi_word, 0, 16)) + *total += COSTS_N_INSNS (1); + else + *total += COSTS_N_INSNS (2); + } + else + { + *total = COSTS_N_INSNS (2); + *total += rtx_cost (XEXP (x, 1), mode, code, 0, speed_p); + } + *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); + return true; + } + else + { + if (CONST_INT_P (XEXP (x, 1))) + { + if (IN_RANGE (INTVAL (XEXP (x, 1)), 0, 16)) + *total = COSTS_N_INSNS (1); + else + *total = COSTS_N_INSNS (2); + } + else + { + *total = COSTS_N_INSNS (1); + *total += rtx_cost (XEXP (x, 1), mode, code, 0, speed_p); + } + *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed_p); + return true; + } + return false; + case MULT: - *total = COSTS_N_INSNS (35 + 6); - return true; + if (mode == QImode) + *total = COSTS_N_INSNS (speed_p ? 18 + 5 : 6); + else if (mode == SImode) + *total = COSTS_N_INSNS (speed_p ? 3 * 18 + 14 : 17); + else + *total = COSTS_N_INSNS (speed_p ? 18 + 3 : 4); + return false; + case DIV: - *total = COSTS_N_INSNS (51 - 6); - return true; + case MOD: + if (mode == QImode) + *total = COSTS_N_INSNS (speed_p ? 19 + 6 : 7); + else if (mode == SImode) + *total = COSTS_N_INSNS (speed_p ? 100 : 7); + else + *total = COSTS_N_INSNS (speed_p ? 19 + 3 : 4); + return false; + + case UDIV: + case UMOD: + if (mode == QImode) + *total = COSTS_N_INSNS (speed_p ? 18 + 7 : 8); + else if (mode == SImode) + *total = COSTS_N_INSNS (speed_p ? 100 : 7); + else + *total = COSTS_N_INSNS (speed_p ? 18 + 3 : 4); + return false; + + case ASHIFT: + case ASHIFTRT: + case LSHIFTRT: + if (REG_P (XEXP (x, 0)) + && CONST_INT_P (XEXP (x, 1))) + { + if (mode == HImode) + { + /* asr/shl/shr. */ + *total = COSTS_N_INSNS (1); + return true; + } + else if (mode == QImode) + { + /* (shl+shr)+shr. */ + *total = COSTS_N_INSNS (3); + return true; + } + else if (mode == SImode) + { + if (IN_RANGE (INTVAL (XEXP (x, 1)), 16, 31)) + *total = COSTS_N_INSNS (3); + else + *total = COSTS_N_INSNS (5); + return true; + } + } + return false; + + case ZERO_EXTEND: + if (mode == HImode) + { + if (GET_MODE (XEXP (x, 0)) == QImode) + /* shl+shr. */ + *total = COSTS_N_INSNS (2); + } + else if (mode == SImode) + { + if (GET_MODE (XEXP (x, 0)) == HImode) + /* mov+mov. */ + *total = COSTS_N_INSNS (2); + else if (GET_MODE (XEXP (x, 0)) == QImode) + /* mov+shl+shr+mov. */ + *total = COSTS_N_INSNS (4); + } + return false; + + case SIGN_EXTEND: + if (mode == HImode) + { + if (GET_MODE (XEXP (x, 0)) == QImode) + /* cbw. */ + *total = COSTS_N_INSNS (1); + } + else if (mode == SImode) + { + if (GET_MODE (XEXP (x, 0)) == HImode) + /* mov+asr. */ + *total = COSTS_N_INSNS (2); + else if (GET_MODE (XEXP (x, 0)) == QImode) + /* mov+shl+shr+mov. */ + *total = COSTS_N_INSNS (3); + } + return false; + + case SET: + if (REG_P (XEXP (x, 0))) + { + if (!REG_P (XEXP (x, 1))) + *total = rtx_cost (XEXP (x, 1), mode, SET, 1, speed_p); + return true; + } + return false; default: return false; diff --git a/gcc/testsuite/gcc.target/xstormy16/mulhi.c b/gcc/testsuite/gcc.target/xstormy16/mulhi.c new file mode 100644 index 0000000..885f145 --- /dev/null +++ b/gcc/testsuite/gcc.target/xstormy16/mulhi.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ +unsigned short foo(unsigned short x) +{ + return x*91; +} + +/* { dg-final { scan-assembler "mul" } } */