public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/97756] [11/12/13/14 Regression] Inefficient handling of 128-bit arguments
Date: Mon, 13 Nov 2023 09:06:42 +0000	[thread overview]
Message-ID: <bug-97756-4-xKx3CtzRwx@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97756-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:

https://gcc.gnu.org/g:0a140730c970870a5125beb1114f6c01679a040e

commit r14-5385-g0a140730c970870a5125beb1114f6c01679a040e
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Mon Nov 13 09:05:16 2023 +0000

    i386: Improve reg pressure of double word right shift then truncate.

    This patch improves register pressure during reload, inspired by PR 97756.
    Normally, a double-word right-shift by a constant produces a double-word
    result, the highpart of which is dead when followed by a truncation.
    The dead code calculating the high part gets cleaned up post-reload, so
    the issue isn't normally visible, except for the increased register
    pressure during reload, sometimes leading to odd register assignments.
    Providing a post-reload splitter, which clobbers a single wordmode
    result register instead of a doubleword result register, helps (a bit).

    An example demonstrating this effect is:

    unsigned long foo (__uint128_t n)
    {
      unsigned long a = n & MASK60;
      unsigned long b = (n >> 60);
      b = b & MASK60;
      unsigned long c = (n >> 120);
      return a+b+c;
    }

    which currently with -O2 generates (13 instructions):
    foo:    movabsq $1152921504606846975, %rcx
            xchgq   %rdi, %rsi
            movq    %rsi, %rax
            shrdq   $60, %rdi, %rax
            movq    %rax, %rdx
            movq    %rsi, %rax
            movq    %rdi, %rsi
            andq    %rcx, %rax
            shrq    $56, %rsi
            andq    %rcx, %rdx
            addq    %rsi, %rax
            addq    %rdx, %rax
            ret

    with this patch, we generate one less mov (12 instructions):
    foo:    movabsq $1152921504606846975, %rcx
            xchgq   %rdi, %rsi
            movq    %rdi, %rdx
            movq    %rsi, %rax
            movq    %rdi, %rsi
            shrdq   $60, %rdi, %rdx
            andq    %rcx, %rax
            shrq    $56, %rsi
            addq    %rsi, %rax
            andq    %rcx, %rdx
            addq    %rdx, %rax
            ret

    The significant difference is easier to see via diff:
    <       shrdq   $60, %rdi, %rax
    <       movq    %rax, %rdx
    ---
    >       shrdq   $60, %rdi, %rdx

    Admittedly a single "mov" isn't much of a saving on modern architectures,
    but as demonstrated by the PR, people still track the number of them.

    2023-11-13  Roger Sayle  <roger@nextmovesoftware.com>

    gcc/ChangeLog
            * config/i386/i386.md (<insn><dwi>3_doubleword_lowpart): New
            define_insn_and_split to optimize register usage of doubleword
            right shifts followed by truncation.

  parent reply	other threads:[~2023-11-13  9:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-08 19:53 [Bug rtl-optimization/97756] New: " tkoenig at gcc dot gnu.org
2020-11-09  6:29 ` [Bug rtl-optimization/97756] " tkoenig at gcc dot gnu.org
2020-12-25 11:35 ` tkoenig at gcc dot gnu.org
2021-03-10 12:55 ` ppalka at gcc dot gnu.org
2021-04-28  4:58 ` pinskia at gcc dot gnu.org
2021-04-28  7:20 ` [Bug rtl-optimization/97756] [9/10/11/12 Regression] " jakub at gcc dot gnu.org
2021-06-01  8:18 ` rguenth at gcc dot gnu.org
2021-08-30  5:18 ` crazylht at gmail dot com
2022-05-27  9:43 ` [Bug rtl-optimization/97756] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07 10:38 ` [Bug rtl-optimization/97756] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-13 21:09 ` pinskia at gcc dot gnu.org
2023-07-16 11:48 ` tkoenig at gcc dot gnu.org
2023-11-07 18:38 ` tkoenig at gcc dot gnu.org
2023-11-13  9:06 ` cvs-commit at gcc dot gnu.org [this message]
2023-11-13 17:52 ` tkoenig at gcc dot gnu.org
2023-11-14 12:20 ` cvs-commit at gcc dot gnu.org
2024-04-26 12:54 ` [Bug rtl-optimization/97756] [11/12/13 " roger at nextmovesoftware dot com

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-97756-4-xKx3CtzRwx@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).