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

jjk at acm dot org gcc-bugzilla@gcc.gnu.org
Tue Oct 14 09:14:00 GMT 2008


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



More information about the Gcc-bugs mailing list