[LLVMbugs] [Bug 3253] New: missed optimization: shl + test -> bt

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Dec 22 07:32:20 PST 2008


           Summary: missed optimization: shl + test -> bt
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Common Code Generator Code
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: edwintorok at gmail.com
                CC: llvmbugs at cs.uiuc.edu

Consider this code:
int foo(char *c)
        return strcspn(c, ":\r\n");

llvm-gcc translates this into this (which is better than gcc, which does 3

        .align  16
        .globl  foo
        .type   foo, at function
        xorl    %eax, %eax
        jmp     .LBB1_2 # bb24
.LBB1_1:        # bb23
        incq    %rax
.LBB1_2:        # bb24
        movb    (%rdi,%rax), %cl
        movl    $1, %edx
        shlq    %cl, %rdx
        cmpb    $58, %cl
        ja      .LBB1_1 # bb23
.LBB1_3:        # bb24
        movabsq $288230376151720961, %rcx
        testq   %rcx, %rdx
        je      .LBB1_1 # bb23
.LBB1_4:        # bb35
        .size   foo, .-foo

Tron on #llvm suggested that it could be improved even further:
 * movl $1, %rdx; shl %cl, %rdx; test %ecx, %edx  ==  bt
 * loading the huge constant (the instruction is 10 bytes long!) should be
moved out of the loop

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