public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/115749] Non optimal assembly for integer modulo by a constant on x86-64 CPUs
Date: Tue, 02 Jul 2024 18:41:01 +0000	[thread overview]
Message-ID: <bug-115749-4-9jJP9MC9eK@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-115749-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to kim.walisch from comment #4)
> One possible explanation for why GCC's current integer division by a
> constant assembly sequence was chosen back in the day (I guess one or two
> decades ago) is that GCC's current assembly sequence uses only 1 mul
> instruction whereas Clang uses 2 mul instructions.
> 
> Historically, multiplication instructions used to be slower than add, sub
> and shift instructions on nearly all CPU architectures and so it made sense
> to avoid mul instructions whenever possible. However in the past decade this
> performance gap has narrowed and now it is more important to avoid long
> instruction dependency chains which GCC's current integer modulo by a
> constant assembly sequence suffers from.

Note the way GCC has handled mult->shift/add (and even the divide/mod
expansion) is via a target independent part which querries the target on the
costs of specific instructions (mult, shift, add, etc.). So if the target has
the cost not modeled correctly, you get the less efficient sequence. This is
why I said it was a cost model issue and why PR 115756 is asking for the
changing of the default (generic) output. 
So yes the cost might be based on the older cores and not been retuned since.
Anyways the middle-end is doing the correct thing based on what the target is
giving it.

  parent reply	other threads:[~2024-07-02 18:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-02  9:31 [Bug c++/115749] New: Missed BMI2 optimization on x86-64 kim.walisch at gmail dot com
2024-07-02 11:36 ` [Bug c++/115749] " kim.walisch at gmail dot com
2024-07-02 11:44 ` [Bug target/115749] Non optimal assembly for integer modulo by a constant on x86-64 CPUs pinskia at gcc dot gnu.org
2024-07-02 11:59 ` kim.walisch at gmail dot com
2024-07-02 12:17 ` kim.walisch at gmail dot com
2024-07-02 17:21 ` pinskia at gcc dot gnu.org
2024-07-02 17:58 ` pinskia at gcc dot gnu.org
2024-07-02 18:14 ` pinskia at gcc dot gnu.org
2024-07-02 18:41 ` pinskia at gcc dot gnu.org [this message]
2024-07-03 17:29 ` kim.walisch at gmail dot com
2024-07-04  1:17 ` liuhongt at gcc dot gnu.org
2024-07-16  8:18 ` lingling.kong7 at gmail dot com
2024-07-16 21:29 ` roger at nextmovesoftware dot com
2024-07-25  1:45 ` cvs-commit at gcc dot gnu.org
2024-08-15  5:11 ` liuhongt at gcc dot gnu.org
2024-08-15  5:35 ` liuhongt at gcc dot gnu.org
2024-08-16  5:00 ` sjames 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-115749-4-9jJP9MC9eK@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).