From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1251) id CF1863858C50; Sun, 23 Apr 2023 09:37:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF1863858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682242664; bh=Ph8vnHXVVIZD0P6nw1+PGFNZYdaexVVQYkS4fZppwWQ=; h=From:To:Subject:Date:From; b=aqaKVmb0GDiptDoABcuYAcnqFsVb2P0nENldTbuF0SyFlsQerVOUOVqvj7esfBPfm Nj3Ruc0ToPWQ4yDMQijqASCdf5wB9ENRDcMWScUEzbJJDHvX7xi452REvzefYhgcd8 he4rM98qPmD+T3ESCAtKnvttSFlJhECqpXiM6PTg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Roger Sayle To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-177] [xstormy16] Update xstormy16_rtx_costs. X-Act-Checkin: gcc X-Git-Author: Roger Sayle X-Git-Refname: refs/heads/master X-Git-Oldrev: 9a6e5b933fedd6a386c8bde7f93e3e0d4515030b X-Git-Newrev: 8ffff5e9de2fa8e2845c8045941afbb1e8638aed Message-Id: <20230423093744.CF1863858C50@sourceware.org> Date: Sun, 23 Apr 2023 09:37:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8ffff5e9de2fa8e2845c8045941afbb1e8638aed commit r14-177-g8ffff5e9de2fa8e2845c8045941afbb1e8638aed Author: Roger Sayle Date: Sun Apr 23 10:35:53 2023 +0100 [xstormy16] Update xstormy16_rtx_costs. 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. 2023-04-23 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. Diff: --- gcc/config/stormy16/stormy16.cc | 166 +++++++++++++++++++++++++++-- gcc/testsuite/gcc.target/xstormy16/mulhi.c | 8 ++ 2 files changed, 163 insertions(+), 11 deletions(-) diff --git a/gcc/config/stormy16/stormy16.cc b/gcc/config/stormy16/stormy16.cc index 647b72c4538..98f87fa8251 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 00000000000..885f1453b6a --- /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" } } */