public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/110717] New: Double-word sign-extension missed-optimization
@ 2023-07-18 14:32 jakub at gcc dot gnu.org
  2023-07-18 14:33 ` [Bug rtl-optimization/110717] " jakub at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-07-18 14:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110717
           Summary: Double-word sign-extension missed-optimization
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

While working on _BitInt, I've noticed that we don't emit very good code at
least on x86_64 -m64/-m32 -O2 for:
#ifdef __SIZEOF_INT128__
unsigned __int128
foo (unsigned __int128 x)
{
  x <<= 59;
  return ((__int128) x) >> 59;
}
#else
unsigned long long
foo (unsigned long long x)
{
  x <<= 27;
  return ((long long) x) >> 27;
}
#endif

The sign-extension from 69 resp. 37 bits could be limited solely to the upper
word,
but we uselessly shift the lower word with it as well:
        movq    %rdi, %rax
        movq    %rsi, %rdx
        shldq   $59, %rdi, %rdx
        salq    $59, %rax
        shrdq   $59, %rdx, %rax
        sarq    $59, %rdx
        ret
for -m64 and
        movl    4(%esp), %eax
        movl    8(%esp), %edx
        shldl   $27, %eax, %edx
        sall    $27, %eax
        shrdl   $27, %edx, %eax
        sarl    $27, %edx
        ret
for -m32.
LLVM emits even more horrible code for -m64, but
        movl    4(%esp), %eax
        movl    8(%esp), %edx
        shll    $27, %edx
        sarl    $27, %edx
        retl
for -m32, which looks to me like what we want.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-05-07  7:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 14:32 [Bug rtl-optimization/110717] New: Double-word sign-extension missed-optimization jakub at gcc dot gnu.org
2023-07-18 14:33 ` [Bug rtl-optimization/110717] " jakub at gcc dot gnu.org
2023-07-18 14:54 ` jakub at gcc dot gnu.org
2023-07-19  6:38 ` rguenth at gcc dot gnu.org
2023-07-19  8:55 ` ubizjak at gmail dot com
2023-07-19  9:00 ` jakub at gcc dot gnu.org
2023-07-19  9:30 ` ubizjak at gmail dot com
2023-07-20 18:56 ` cvs-commit at gcc dot gnu.org
2023-07-20 19:03 ` ubizjak at gmail dot com
2023-07-20 19:19 ` jakub at gcc dot gnu.org
2023-07-20 19:21 ` jakub at gcc dot gnu.org
2023-07-21  9:06 ` jakub at gcc dot gnu.org
2023-07-21 10:53 ` segher at gcc dot gnu.org
2023-07-21 16:28 ` segher at gcc dot gnu.org
2023-07-21 16:46 ` pinskia at gcc dot gnu.org
2023-08-04 15:26 ` cvs-commit at gcc dot gnu.org
2023-10-30 16:18 ` cvs-commit at gcc dot gnu.org
2023-12-13 13:37 ` cvs-commit at gcc dot gnu.org
2024-05-07  7:41 ` rguenth at gcc dot gnu.org

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).