public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/53507] New: ia32/amd64: bsf can be used to test null memory, bsf sets zero flag
@ 2012-05-28 10:03 etienne_lorrain at yahoo dot fr
  2021-11-29  9:02 ` [Bug target/53507] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: etienne_lorrain at yahoo dot fr @ 2012-05-28 10:03 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug target/53507] ia32/amd64: bsf can be used to test null memory, bsf sets zero flag
  2012-05-28 10:03 [Bug rtl-optimization/53507] New: ia32/amd64: bsf can be used to test null memory, bsf sets zero flag etienne_lorrain at yahoo dot fr
@ 2021-11-29  9:02 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-29  9:02 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|rtl-optimization            |target
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2021-11-29
             Status|UNCONFIRMED                 |NEW
             Target|                            |x86_64 i?86
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
LLVM does:
testnull():                           # @testnull()
        .cfi_startproc
# %bb.0:
        cmpl    $0, I
        je      .LBB0_2
# %bb.1:
        retl
.LBB0_2:
        jmp     ifnull()

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

end of thread, other threads:[~2021-11-29  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-28 10:03 [Bug rtl-optimization/53507] New: ia32/amd64: bsf can be used to test null memory, bsf sets zero flag etienne_lorrain at yahoo dot fr
2021-11-29  9:02 ` [Bug target/53507] " 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).