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: 1772311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=J0YpD84A; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q3cXp5fHbz23td for ; Sun, 23 Apr 2023 02:38:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC7F83857736 for ; Sat, 22 Apr 2023 16:38:46 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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" } } */