public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104376] New: Failure to optimize clz equivalent to clz
@ 2022-02-04  1:10 gabravier at gmail dot com
  2022-02-04  4:26 ` [Bug tree-optimization/104376] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gabravier at gmail dot com @ 2022-02-04  1:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104376
           Summary: Failure to optimize clz equivalent to clz
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

#include <stdint.h>

uint32_t countLeadingZeros32(uint32_t x)
{
    if (x == 0)
        return 32;
    return (31 - __builtin_clz(x)) ^ 31;
}

On x86, with `-mlzcnt`, GCC outputs this:

countLeadingZeros32(unsigned int):
  mov eax, 32
  test edi, edi
  je .L1
  mov eax, 31
  lzcnt edi, edi
  sub eax, edi
  xor eax, 31
.L1:
  ret

LLVM instead outputs this:

countLeadingZeros32(unsigned int):
  lzcnt eax, edi
  ret

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

end of thread, other threads:[~2023-10-24 11:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04  1:10 [Bug tree-optimization/104376] New: Failure to optimize clz equivalent to clz gabravier at gmail dot com
2022-02-04  4:26 ` [Bug tree-optimization/104376] " pinskia at gcc dot gnu.org
2022-02-04  4:27 ` pinskia at gcc dot gnu.org
2022-02-04  7:01 ` pinskia at gcc dot gnu.org
2022-02-09  6:10 ` pinskia at gcc dot gnu.org
2022-02-09  7:40 ` pinskia at gcc dot gnu.org
2023-05-06 21:23 ` pinskia at gcc dot gnu.org
2023-10-15 18:58 ` pinskia at gcc dot gnu.org
2023-10-15 19:21 ` pinskia at gcc dot gnu.org
2023-10-24 11:17 ` cvs-commit at gcc dot gnu.org
2023-10-24 11:20 ` 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).