public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/108471] New: Suboptimal codegen for __int128 subtraction on x86_64
@ 2023-01-19 21:48 rl.alt.accnt at gmail dot com
  2023-01-19 22:02 ` [Bug rtl-optimization/108471] " pinskia at gcc dot gnu.org
  2023-01-19 23:17 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: rl.alt.accnt at gmail dot com @ 2023-01-19 21:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108471
           Summary: Suboptimal codegen for __int128 subtraction on x86_64
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rl.alt.accnt at gmail dot com
  Target Milestone: ---

On x86_64, GCC generates an excessive amount of redundant `mov` instructions
for `__int128` subtraction in C/C++. Clicking through versions on godbolt shows 
that this started getting worse in GCC 9.1 and later versions. See also
https://godbolt.org/z/86v6ar457

The code:
```
__int128 sub(__int128 a, __int128 b) { return a - b; }
```

At -O3 or -O2, GCC (trunk) generates:
```
sub:
        mov     r8, rdi
        mov     rax, rsi
        mov     rsi, r8
        mov     rdi, rax
        mov     r8, rdx
        mov     rax, rsi
        mov     rdx, rdi
        sub     rax, r8
        sbb     rdx, rcx
        ret
```
Interestingly, the use of `r8` in the first three instructions disappears when
compiling w/ -O1, and those instructions are folded into two `mov`s instead.

By contrast, Clang (also at -O3) generates:
```
sub:
        mov     rax, rdi
        sub     rax, rdx
        sbb     rsi, rcx
        mov     rdx, rsi
        ret
```

This is probably not a high-priority bug; I just wanted to bring attention to
the fact that this is happening.

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

* [Bug rtl-optimization/108471] Suboptimal codegen for __int128 subtraction on x86_64
  2023-01-19 21:48 [Bug other/108471] New: Suboptimal codegen for __int128 subtraction on x86_64 rl.alt.accnt at gmail dot com
@ 2023-01-19 22:02 ` pinskia at gcc dot gnu.org
  2023-01-19 23:17 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-19 22:02 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization, ra
          Component|other                       |rtl-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most of this is just argument and return value register allocation issue and
not much else. There is another bug that talks about this too.

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

* [Bug rtl-optimization/108471] Suboptimal codegen for __int128 subtraction on x86_64
  2023-01-19 21:48 [Bug other/108471] New: Suboptimal codegen for __int128 subtraction on x86_64 rl.alt.accnt at gmail dot com
  2023-01-19 22:02 ` [Bug rtl-optimization/108471] " pinskia at gcc dot gnu.org
@ 2023-01-19 23:17 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-19 23:17 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 94804.

*** This bug has been marked as a duplicate of bug 94804 ***

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

end of thread, other threads:[~2023-01-19 23:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-19 21:48 [Bug other/108471] New: Suboptimal codegen for __int128 subtraction on x86_64 rl.alt.accnt at gmail dot com
2023-01-19 22:02 ` [Bug rtl-optimization/108471] " pinskia at gcc dot gnu.org
2023-01-19 23:17 ` pinskia 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).