public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "etienne_lorrain at yahoo dot fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/53507] New: ia32/amd64: bsf can be used to test null memory, bsf sets zero flag
Date: Mon, 28 May 2012 10:03:00 -0000	[thread overview]
Message-ID: <bug-53507-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53507

             Bug #: 53507
           Summary: ia32/amd64: bsf can be used to test null memory, bsf
                    sets zero flag
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: etienne_lorrain@yahoo.fr


Compiling:
int I;
void ifnull(void);
void testnull(void) {
  if (I == 0)
    ifnull();
}

void fct (unsigned u) {
  if (u != 0)
    I = __builtin_ffs(u) - 1;
}

result in for testnull():
    movl    I, %eax
    testl    %eax, %eax
    je    .L4
    rep
    ret
.L4:
    jmp    ifnull()
It would be shorter/quicker to replace the two first lines by:
        bsfl     I, %eax
        je       ifnull()
i.e. there is no need to load the memory variable into a register with bsf/bsr.

And result for fct():
    movl    4(%esp), %eax
    testl    %eax, %eax
    je    .L5
    bsfl    %eax, %eax
    movl    %eax, I
.L5:
    rep
    ret
It would be shorter/quicker to test if the parameter u is null by the bsf
instruction:
    bsfl    4(%esp), %eax
    cmovne    %eax, I
.L5:
    rep
    ret


             reply	other threads:[~2012-05-28  9:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-28 10:03 etienne_lorrain at yahoo dot fr [this message]
2021-11-29  9:02 ` [Bug target/53507] " 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-53507-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).