public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113764] New: [X86] Generates lzcnt when bsr is sufficient
@ 2024-02-05 11:38 chfast at gmail dot com
  2024-02-08  0:35 ` [Bug target/113764] " roger at nextmovesoftware dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: chfast at gmail dot com @ 2024-02-05 11:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113764
           Summary: [X86] Generates lzcnt when bsr is sufficient
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chfast at gmail dot com
  Target Milestone: ---

When lzcnt instructions is enabled (-mlzcnt) the compiler generates lzcnt for
__builtin_clz() in the context where the bsr instruction is sufficient and
better.

unsigned bsr(unsigned x)
{
    return __builtin_clz(x) ^ 31;
}

bsr:
  xor eax, eax
  lzcnt eax, edi
  xor eax, 31
  ret


Without -mlzcnt the generated code is optimal.

bsr:
  bsr eax, edi
  ret


https://godbolt.org/z/5qcTq18nr

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

end of thread, other threads:[~2024-02-11 11:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 11:38 [Bug target/113764] New: [X86] Generates lzcnt when bsr is sufficient chfast at gmail dot com
2024-02-08  0:35 ` [Bug target/113764] " roger at nextmovesoftware dot com
2024-02-09 18:35 ` roger at nextmovesoftware dot com
2024-02-09 21:58 ` jakub at gcc dot gnu.org
2024-02-11 11:34 ` [Bug target/113764] [X86] __builtin_clz generates " roger at nextmovesoftware 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).