public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug middle-end/114661] New: Bit operations not optimized to multiplication @ 2024-04-09 16:11 antoshkka at gmail dot com 2024-04-09 19:55 ` [Bug middle-end/114661] " pinskia at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: antoshkka at gmail dot com @ 2024-04-09 16:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114661 Bug ID: 114661 Summary: Bit operations not optimized to multiplication Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the example: unsigned mul(unsigned char c) { if (c > 3) __builtin_unreachable(); return c << 18 | c << 15 | c << 12 | c << 9 | c << 6 | c << 3 | c; } GCC with -O2 generates the following assembly: mul(unsigned char): movzx edi, dil lea edx, [rdi+rdi*8] lea eax, [0+rdx*8] mov ecx, edx sal edx, 15 or eax, edi sal ecx, 9 or eax, ecx or eax, edx ret However it could be optimized to just: mul(unsigned char): imul eax, edi, 299593 ret Compiling with -Os does not help. Godbolt playground: https://godbolt.org/z/YszzMbovK P.S.: without `c << 18 | c << 15 |` the bit operations are transformed to multiplication. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/114661] Bit operations not optimized to multiplication 2024-04-09 16:11 [Bug middle-end/114661] New: Bit operations not optimized to multiplication antoshkka at gmail dot com @ 2024-04-09 19:55 ` pinskia at gcc dot gnu.org 2024-04-09 19:57 ` pinskia at gcc dot gnu.org 2024-04-09 22:04 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-09 19:55 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114661 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/114661] Bit operations not optimized to multiplication 2024-04-09 16:11 [Bug middle-end/114661] New: Bit operations not optimized to multiplication antoshkka at gmail dot com 2024-04-09 19:55 ` [Bug middle-end/114661] " pinskia at gcc dot gnu.org @ 2024-04-09 19:57 ` pinskia at gcc dot gnu.org 2024-04-09 22:04 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-09 19:57 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114661 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pinskia at gcc dot gnu.org --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Seems like another example where -fwrapv improves code ... ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/114661] Bit operations not optimized to multiplication 2024-04-09 16:11 [Bug middle-end/114661] New: Bit operations not optimized to multiplication antoshkka at gmail dot com 2024-04-09 19:55 ` [Bug middle-end/114661] " pinskia at gcc dot gnu.org 2024-04-09 19:57 ` pinskia at gcc dot gnu.org @ 2024-04-09 22:04 ` pinskia at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-09 22:04 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114661 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2024-04-09 Ever confirmed|0 |1 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-09 22:04 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-04-09 16:11 [Bug middle-end/114661] New: Bit operations not optimized to multiplication antoshkka at gmail dot com 2024-04-09 19:55 ` [Bug middle-end/114661] " pinskia at gcc dot gnu.org 2024-04-09 19:57 ` pinskia at gcc dot gnu.org 2024-04-09 22:04 ` 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).