[LLVMbugs] [Bug 14365] New: Missed optimization for a simple bit twiddling

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 16 12:21:39 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=14365

             Bug #: 14365
           Summary: Missed optimization for a simple bit twiddling
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: jkim at FreeBSD.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


I've been bit twiddling lately and found this:

% cat test.c
int test(int a) { return (a + (~(a & 0x55555555) + 1)); }
% clang -O2 -c test.c
% objdump -d test.o

test.o:     file format elf64-x86-64-freebsd

Disassembly of section .text:

0000000000000000 <test>:
   0:   89 f8                   mov    %edi,%eax
   2:   0d aa aa aa aa          or     $0xaaaaaaaa,%eax
   7:   35 55 55 55 55          xor    $0x55555555,%eax
   c:   8d 44 07 01             lea    0x1(%rdi,%rax,1),%eax
  10:   c3                      retq   

FYI, GCC nicely folded it into just one instruction:

% gcc48 -O2 -c test.c
% objdump -d test.o

test.o:     file format elf64-x86-64-freebsd

Disassembly of section .text:

0000000000000000 <test>:
   0:   89 f8                   mov    %edi,%eax
   2:   25 aa aa aa aa          and    $0xaaaaaaaa,%eax
   7:   c3                      retq

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list