public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104292] New: [missed optimization] boolean addition generates suboptimal code
@ 2022-01-30 18:34 avi at scylladb dot com
  2022-01-30 18:36 ` [Bug tree-optimization/104292] " avi at scylladb dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: avi at scylladb dot com @ 2022-01-30 18:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104292
           Summary: [missed optimization] boolean addition generates
                    suboptimal code
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: avi at scylladb dot com
  Target Milestone: ---

bool bool_or(bool b1, bool b2) {
    return b1 + b2;
}

generates

bool_or(bool, bool):
        movzbl  %dil, %edi
        movzbl  %sil, %esi
        addl    %esi, %edi
        setne   %al
        ret

Whereas it could generate

bool_or(bool, bool):
        or   %edi, %esi
        mov  %esi, %eax
        ret

For a net gain of two instructions (and the final mov can often be elided, so
up to three).

I encountered this while using std::plus<> with boolean types. It could be
optimized as a specialization of std::plus, but I think a magic transformation
in the optimizer would make it apply in more places.

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

end of thread, other threads:[~2024-05-09 14:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30 18:34 [Bug tree-optimization/104292] New: [missed optimization] boolean addition generates suboptimal code avi at scylladb dot com
2022-01-30 18:36 ` [Bug tree-optimization/104292] " avi at scylladb dot com
2022-01-30 20:02 ` pinskia at gcc dot gnu.org
2022-01-30 20:05 ` pinskia at gcc dot gnu.org
2022-01-30 22:29 ` pinskia at gcc dot gnu.org
2023-06-23  0:45 ` [Bug tree-optimization/104292] (bool)(bool0 + bool1) should be simplified into bool0 | bool1 pinskia at gcc dot gnu.org
2023-06-23  0:45 ` pinskia at gcc dot gnu.org
2024-05-09 14:56 ` 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).