public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/99087] New: suboptimal codegen for division by constant 3
@ 2021-02-13 15:33 vanyacpp at gmail dot com
  2021-02-15  8:26 ` [Bug target/99087] " rguenth at gcc dot gnu.org
  2023-10-19 16:35 ` vanyacpp at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: vanyacpp at gmail dot com @ 2021-02-13 15:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99087
           Summary: suboptimal codegen for division by constant 3
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

These two are functionally the same, but generate different code with g++ -O2:

unsigned long long foo(unsigned long long a)
{
    return a / 3;
}

unsigned long long bar(unsigned long long a)
{
    return (unsigned __int128)a * 0xAAAA'AAAA'AAAA'AAAB >> 65;
}

foo(unsigned long long):
        movabs  rdx, -6148914691236517205
        mov     rax, rdi
        mul     rdx
        mov     rax, rdx
        shr     rax
        ret
bar(unsigned long long):
        movabs  rax, -6148914691236517205
        mul     rdi
        mov     rax, rdx
        shr     rax
        ret

For some reason for division GCC chooses different argument order which causes
generation of one extra mov.

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

* [Bug target/99087] suboptimal codegen for division by constant 3
  2021-02-13 15:33 [Bug middle-end/99087] New: suboptimal codegen for division by constant 3 vanyacpp at gmail dot com
@ 2021-02-15  8:26 ` rguenth at gcc dot gnu.org
  2023-10-19 16:35 ` vanyacpp at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-15  8:26 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-02-15

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

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

* [Bug target/99087] suboptimal codegen for division by constant 3
  2021-02-13 15:33 [Bug middle-end/99087] New: suboptimal codegen for division by constant 3 vanyacpp at gmail dot com
  2021-02-15  8:26 ` [Bug target/99087] " rguenth at gcc dot gnu.org
@ 2023-10-19 16:35 ` vanyacpp at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: vanyacpp at gmail dot com @ 2023-10-19 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

Ivan Sorokin <vanyacpp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Ivan Sorokin <vanyacpp at gmail dot com> ---
Since GCC 12 the issue no longer reproduces. Closing as fixed.

https://godbolt.org/z/ss7Y84a9f

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

end of thread, other threads:[~2023-10-19 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-13 15:33 [Bug middle-end/99087] New: suboptimal codegen for division by constant 3 vanyacpp at gmail dot com
2021-02-15  8:26 ` [Bug target/99087] " rguenth at gcc dot gnu.org
2023-10-19 16:35 ` vanyacpp at gmail dot com

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