public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "roger at nextmovesoftware dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/113533] [14 Regression] Code generation regression after change for pr111267
Date: Tue, 23 Jan 2024 01:22:56 +0000	[thread overview]
Message-ID: <bug-113533-4-fkCMrsLeNq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113533-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113533

--- Comment #10 from Roger Sayle <roger at nextmovesoftware dot com> ---
Hi Oleg.  Great question.  The "speed" parameter passed to rtx_costs, and
address_cost indicates whether the middle-end is optimizing for peformance, and
interested in the nummber of cycles taken by each instruction, or optimizing
for size, and interested in the number of bytes used to encode the instruction.
 Previously, this speed parameter was ignored by the SH backend, so the costs
were the same independent of the objective function.

In my proposed patch, the address cost (1) when optimizing for size attempts to
return the additional size of an instruction based on the addressing mode.  For
register, and reg+reg addressing modes there is no size increase (overhead),
and for adressing modes with displacements, and displacements to address
pointers, there is a cost.  (2) when optimizing for speed, address cost remains
between 0 and 3, and is used to prioritize between (equivalent numbers of)
instructions.  Normally, rtx_costs are defined in terms of COST_N_INSNS, which
multiplies by 4.  Hence on many platforms a single instruction that references
memory may be encoded as COSTS_N_INSNS(1)+1 (or a more complex addressing mode
as COSTS_N_INSNS(1)+2) to show that this is disfavored to a single instruction
that doesn't reference memory, COSTS_N_INSNS(1)+0.

This is the fix for this particular regression; SIGN_EXTEND of a register now
costs COSTS_N_INSNS(1), and SIGN_EXTEND of a MEM now costs COSTS_N_INSNS(1)+1.

A useful way to debug rtx_costs is to use the -dP command line option, and then
look at the [c=X, l=Y] annotations in the assembly language file.  One way to
check/confirm that these are sensible is that ideally they should be correlated
when optimizing for size (with -Os or -Oz).

I've found an interesting table of SH cycle counts (for different CPUs) at
http://www.shared-ptr.com/sh_insns.html and these could be used to improve
sh_rtx_costs further.  For example, SH currently reports multiplications as
a single cycle operation, which doesn't match the hardware specs, and prevents
GCC from using synth_mult to produce faster (or shorter) sequences using shifts
and additions.  Likewise, sh_rtx_costs doesn't distinguish the machine mode,
so the costs of SImode multiplications are the same as DImode multiplications.

In comment #5 you mention GCC's defaults; it turns out that for rtx_costs the
default values that would be provided by the middle-end, may be more accurate
than the values (currently) specified by the backend.

I hope this answers your question.

  parent reply	other threads:[~2024-01-23  1:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22  2:17 [Bug rtl-optimization/113533] New: " law at gcc dot gnu.org
2024-01-22  2:23 ` [Bug rtl-optimization/113533] " pinskia at gcc dot gnu.org
2024-01-22  2:32 ` olegendo at gcc dot gnu.org
2024-01-22  2:45 ` pinskia at gcc dot gnu.org
2024-01-22  2:46 ` pinskia at gcc dot gnu.org
2024-01-22  3:05 ` olegendo at gcc dot gnu.org
2024-01-22 15:15 ` roger at nextmovesoftware dot com
2024-01-22 16:12 ` olegendo at gcc dot gnu.org
2024-01-22 23:52 ` roger at nextmovesoftware dot com
2024-01-23  0:28 ` olegendo at gcc dot gnu.org
2024-01-23  1:22 ` roger at nextmovesoftware dot com [this message]
2024-01-23  3:27 ` olegendo at gcc dot gnu.org
2024-01-26 21:30 ` roger at nextmovesoftware dot com
2024-01-27  1:37 ` olegendo at gcc dot gnu.org
2024-01-27 11:20 ` roger at nextmovesoftware dot com
2024-01-28 14:39 ` olegendo at gcc dot gnu.org
2024-03-04  4:14 ` law at gcc dot gnu.org
2024-03-10  4:37 ` [Bug rtl-optimization/113533] " law at gcc dot gnu.org
2024-03-10  4:48 ` olegendo at gcc dot gnu.org
2024-05-07  7:44 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113533-4-fkCMrsLeNq@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).