public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/106420] New: Missed optimization for comparisons
@ 2022-07-23  9:25 zero at smallinteger dot com
  2022-07-23  9:38 ` [Bug target/106420] " zero at smallinteger dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zero at smallinteger dot com @ 2022-07-23  9:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106420
           Summary: Missed optimization for comparisons
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zero at smallinteger dot com
  Target Milestone: ---

Created attachment 53339
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53339&action=edit
Sample code

When comparing different variables to the same constants, in some cases the
compiler could first combine the variables and then do a single compare.  In
the sample given, two variables are compared against 7.  In the slow path, GCC
produces the following with -O2.

        cmp     edi, 7
        setg    al
        cmp     esi, 7
        setg    dl
        or      eax, edx
        movzx   eax, al
        ret

In the fast path, GCC produces this instead.

        or      edi, esi
        xor     eax, eax
        cmp     edi, 7
        setg    al
        ret

Although the expression a > 7 || b > 7 is the same as (a | b) > 7, the latter
is better because it results in fewer instructions.  A quick experiment shows
the latter also runs quite faster.

Verified with Godbolt for GCC trunk.  Clang, ICC, and MSVC latest versions also
miss this opportunity as per Godbolt.

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

end of thread, other threads:[~2022-07-25  2:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-23  9:25 [Bug target/106420] New: Missed optimization for comparisons zero at smallinteger dot com
2022-07-23  9:38 ` [Bug target/106420] " zero at smallinteger dot com
2022-07-25  2:12 ` [Bug tree-optimization/106420] " crazylht at gmail dot com
2022-07-25  2:23 ` pinskia at gcc dot gnu.org
2022-07-25  2:35 ` zero at smallinteger 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).