From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1880) id 04A973858D3C; Wed, 11 Jan 2023 05:54:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 04A973858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673416490; bh=U6kZ0dRrHXQJFzS9QR+zPF9BqznXHXwnAWbEKIuY3rs=; h=From:To:Subject:Date:From; b=cTeHmv17FjW6TEcVj5ELzFE8scnCu0xiHm22xVZNvQjwW1bz9gE4fSn0gBgBlR/Zd aMRL4qbtCStDdYGNQtYtylMJoO9sgbGm7f0CySELKvzB7P6oF0EcxSwUeZynUh3if7 WS3HnFeeG8lXhJulDtfokE6qqYZT839cMxLeRwTI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Max Filippov To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5098] xtensa: Make instruction cost estimation for size more accurate X-Act-Checkin: gcc X-Git-Author: Takayuki 'January June' Suwa X-Git-Refname: refs/heads/master X-Git-Oldrev: f432ad092122c36fd8dfc7738ec6814bc2bc4e63 X-Git-Newrev: b399afd22c6ea50722bbff3247d52f3bd14bf2b6 Message-Id: <20230111055450.04A973858D3C@sourceware.org> Date: Wed, 11 Jan 2023 05:54:50 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b399afd22c6ea50722bbff3247d52f3bd14bf2b6 commit r13-5098-gb399afd22c6ea50722bbff3247d52f3bd14bf2b6 Author: Takayuki 'January June' Suwa Date: Tue Jan 10 12:34:01 2023 +0900 xtensa: Make instruction cost estimation for size more accurate Until now, we applied COSTS_N_INSNS() (multiplying by 4) after dividing the instruction length by 3, so we couldn't express the difference less than modulo 3 in insn cost for size (e.g. 11 Bytes and 12 bytes cost the same). This patch fixes that. ;; 2 bytes addi.n a2, a2, -1 ; cost 3 ;; 3 bytes addmi a2, a2, 1024 ; cost 4 ;; 4 bytes movi.n a3, 80 ; cost 5 bnez.n a2, a3, .L4 ;; 5 bytes srli a2, a3, 1 ; cost 7 add.n a2, a2, a2 ;; 6 bytes ssai 8 ; cost 8 src a4, a2, a3 :: 3 + 4 bytes l32r a2, .L5 ; cost 9 ;; 11 bytes ; cost 15 ;; 12 bytes ; cost 16 gcc/ChangeLog: * config/xtensa/xtensa.cc (xtensa_insn_cost): Let insn cost for size be obtained by applying COSTS_N_INSNS() to instruction length and then dividing by 3. Diff: --- gcc/config/xtensa/xtensa.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index a1f184950ae..6cf6b35399a 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -4519,13 +4519,15 @@ xtensa_insn_cost (rtx_insn *insn, bool speed) { if (!(recog_memoized (insn) < 0)) { - int len = get_attr_length (insn), n = (len + 2) / 3; + int len = get_attr_length (insn); if (len == 0) return COSTS_N_INSNS (0); if (speed) /* For speed cost. */ { + int n = (len + 2) / 3; + /* "L32R" may be particular slow (implementation-dependent). */ if (xtensa_is_insn_L32R_p (insn)) return COSTS_N_INSNS (1 + xtensa_extra_l32r_costs); @@ -4572,10 +4574,11 @@ xtensa_insn_cost (rtx_insn *insn, bool speed) { /* "L32R" itself plus constant in litpool. */ if (xtensa_is_insn_L32R_p (insn)) - return COSTS_N_INSNS (2) + 1; + len = 3 + 4; - /* Consider ".n" short instructions. */ - return COSTS_N_INSNS (n) - (n * 3 - len); + /* Consider fractional instruction length (for example, ".n" + short instructions or "L32R" litpool constants. */ + return (COSTS_N_INSNS (len) + 1) / 3; } } }