[LLVMbugs] [Bug 1979] New: Potential loop codegen improvement

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Feb 3 17:57:25 PST 2008


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

           Summary: Potential loop codegen improvement
           Product: new-bugs
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sharparrow1 at yahoo.com
                CC: llvmbugs at cs.uiuc.edu


Comparing LLVM trunk (clang -emit-llvm-bc | opt -std-compile-opts | llc) and
gcc 4.1 (gcc -O3 -S) for the following code, gcc generates a shorter main loop.

Source:
#include <stdio.h>
#include <time.h>

static int parity(unsigned x) {
  x ^= x >> 1;
  x ^= x >> 2;
  return ((x & 0x11111111) * 0x88888888) >> 31;
}

int main(void) {
  unsigned i;
  unsigned x = 0;
  time_t t1=time(0), t2;
  for (i = 0; i < 0xFFFFFFFF; i+= 1)
    x += parity(i);
  t2=time(0);
  printf("TIME: %d, RESULT: %u\n", t2-t1, x);
}

LLVM's main loop:
.LBB2_3:        # forbody14
        movl    %eax, %edx
        shrl    %edx
        xorl    %eax, %edx
        movl    %edx, %esi
        shrl    $2, %esi
        xorl    %edx, %esi
        andl    $286331153, %esi
        imull   $2290649224, %esi, %esi
        shrl    $31, %esi
        addl    %ecx, %esi
        incl    %eax
        cmpl    $4294967295, %eax
        movl    %esi, %ecx
        jne     .LBB2_3 # forbody14

gcc's main loop:
.L2:
        movl    %ecx, %eax
        shrl    %eax
        xorl    %ecx, %eax
        addl    $1, %ecx
        movl    %eax, %edx
        shrl    $2, %edx
        xorl    %edx, %eax
        andl    $286331153, %eax
        imull   $-2004318072, %eax, %eax
        shrl    $31, %eax
        addl    %eax, %ebx
        cmpl    $-1, %ecx
        jne     .L2

gcc's loop is one instruction shorter; LLVM's loop has an unnecessary movl.

This is an extremely synthetic/worthless benchmark, of course, but this bug
looks like it could affect real code.

(In case anyone's wondering, the included "parity" function computes the parity
of the input integer, i.e. it returns one if the number of set bits is odd, and
zero otherwise.)


-- 
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