public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "steinar+gcc at gunderson dot no" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/94956] New: Unable to remove impossible ffs() test for zero
Date: Tue, 05 May 2020 15:38:02 +0000	[thread overview]
Message-ID: <bug-94956-4@http.gcc.gnu.org/bugzilla/> (raw)

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? :-)

             reply	other threads:[~2020-05-05 15:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05 15:38 steinar+gcc at gunderson dot no [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94956-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).