This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/37823] New: Missed optimization - ffs() from strings.h


GCC produces some redundant addl/subl instructions for the following function,
which calls the built-in ffs():
--- snip ---
#include <strings.h>

int
foo(int i, int j)
{
  return i + ffs(j) - 1;
}
--- output of gcc -O3 -m32 -S foo.c ---
foo:
        pushl   %ebp
        xorl    %edx, %edx
        movl    %esp, %ebp
        bsfl    12(%ebp), %eax
        sete    %dl
        negl    %edx
        orl     %edx, %eax
        addl    $1, %eax
        subl    $1, %eax
        addl    8(%ebp), %eax
        popl    %ebp
        ret
--- output of gcc -O3 -S foo.c ---
foo:
        bsfl    %esi, %esi
        movl    $-1, %eax
        cmove   %eax, %esi
        addl    $1, %esi
        leal    -1(%rsi,%rdi), %eax
        ret


-- 
           Summary: Missed optimization - ffs() from strings.h
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jjk at acm dot org
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]