public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/97503] New: Suboptimal use of cntlzw and cntlzd
@ 2020-10-20 14:44 christophe.leroy at csgroup dot eu
  2020-10-20 16:25 ` [Bug c/97503] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: christophe.leroy at csgroup dot eu @ 2020-10-20 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97503
           Summary: Suboptimal use of cntlzw and cntlzd
           Product: gcc
           Version: 10.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophe.leroy at csgroup dot eu
  Target Milestone: ---

int f(int x)
{
        return x ? __builtin_clz(x) : 32;
}

Is built as

00000000 <f>:
   0:   2c 03 00 00     cmpwi   r3,0
   4:   40 82 00 0c     bne     10 <f+0x10>
   8:   38 60 00 20     li      r3,32
   c:   4e 80 00 20     blr
  10:   7c 63 00 34     cntlzw  r3,r3
  14:   4e 80 00 20     blr


I would expect

00000000 <f>:
   0:   7c 63 00 34     cntlzw  r3,r3
   4:   4e 80 00 20     blr

Because cntlzw (Count Leading Zeros Word) is documentated in powerpc
instruction set as returning 0 to 32 inclusive

The same applies to the 64 bits version:

long f(long x)
{
        return x ? __builtin_clzll(x) : 64;
}

0000000000000000 <.f>:
   0:   2c 23 00 00     cmpdi   r3,0
   4:   41 82 00 0c     beq     10 <.f+0x10>
   8:   7c 63 00 74     cntlzd  r3,r3
   c:   4e 80 00 20     blr
  10:   38 60 00 40     li      r3,64
  14:   4e 80 00 20     blr

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

end of thread, other threads:[~2023-11-27  8:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-20 14:44 [Bug c/97503] New: Suboptimal use of cntlzw and cntlzd christophe.leroy at csgroup dot eu
2020-10-20 16:25 ` [Bug c/97503] " jakub at gcc dot gnu.org
2020-10-20 16:49 ` jakub at gcc dot gnu.org
2020-10-21  8:54 ` [Bug target/97503] " cvs-commit at gcc dot gnu.org
2023-11-09  5:59 ` lh_mouse at 126 dot com
2023-11-09  6:05 ` lh_mouse at 126 dot com
2023-11-09 16:51 ` ubizjak at gmail dot com
2023-11-09 16:53 ` ubizjak at gmail dot com
2023-11-27  8:14 ` lh_mouse at 126 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).