public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94956] New: Unable to remove impossible ffs() test for zero
@ 2020-05-05 15:38 steinar+gcc at gunderson dot no
  2020-05-05 15:39 ` [Bug tree-optimization/94956] " steinar+gcc at gunderson dot no
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: steinar+gcc at gunderson dot no @ 2020-05-05 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94956
           Summary: Unable to remove impossible ffs() test for zero
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: steinar+gcc at gunderson dot no
  Target Milestone: ---

Hi,

Given GCC 10 x86-64, and this code:

#include <stdint.h>
#include <string.h>

int foo(uint32_t x) {
        if (x == 0) __builtin_unreachable();
        return ffs(x) - 1;
}

I get this assembler:

atum17:~> gcc-10 -O2 -c test.c 
atum17:~> objdump --disassemble test.o

The cmovne test is rather expensive for me due to high instruction latency,and
I can never have zero in my situation. (It costs ~10% in a much larger graph
algorithm.) I'm unable to get GCC to understand that it doesn't need it, save
for using an explicit asm statement.

By contrast, Clang 10 gets this right:

atum17:~> clang-10 -O2 -c test.c        
atum17:~> objdump --disassemble test.o

test.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <foo>:
   0:   0f bc c7                bsf    %edi,%eax
   3:   c3                      retq   

Is it possible to get access to the raw instruction by some clever means? :-)

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

end of thread, other threads:[~2021-08-03  2:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 15:38 [Bug tree-optimization/94956] New: Unable to remove impossible ffs() test for zero steinar+gcc at gunderson dot no
2020-05-05 15:39 ` [Bug tree-optimization/94956] " steinar+gcc at gunderson dot no
2020-05-05 17:21 ` jakub at gcc dot gnu.org
2020-05-05 18:21 ` jakub at gcc dot gnu.org
2020-05-06  6:58 ` rguenth at gcc dot gnu.org
2020-05-08  7:34 ` cvs-commit at gcc dot gnu.org
2020-05-08  7:51 ` jakub at gcc dot gnu.org
2020-05-08  7:53 ` steinar+gcc at gunderson dot no
2021-06-20  9:50 ` steinar+gcc at gunderson dot no
2021-08-03  2:09 ` 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).