[LLVMbugs] [Bug 11735] New: Poor optimization of switch statement

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jan 10 06:57:56 PST 2012


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

             Bug #: 11735
           Summary: Poor optimization of switch statement
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: jmuizelaar at mozilla.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


for the following code:
int foo(int a)
{
        switch(a) {
                case 5:
                        return 17;
                case 9:
                        return 12;
                case 11:
                        return 10;
                case 18:
                        return 5;
                case 2:
                        return 3;
                case 6:
                        return 1;
                case 1:
                        return 19;
                default:
                        return 6;
        }
}

clang produces:

    .globl    __Z3fooi
__Z3fooi:                               ## @_Z3fooi
Ltmp2:
## BB#0:                                ## %entry
    pushq    %rbp
    movq    %rsp, %rbp
                                        ## kill: EDI<def> EDI<kill> RDI<def>
    cmpl    $17, %edi
    jg    LBB0_5
## BB#1:                                ## %entry
    decl    %edi
    cmpl    $10, %edi
    ja    LBB0_10
## BB#2:                                ## %entry
    movl    $17, %eax
    leaq    LJTI0_0(%rip), %rdx
    movslq    (%rdx,%rdi,4), %rcx
    addq    %rdx, %rcx
    jmpq    *%rcx
LBB0_3:                                 ## %sw.bb1
    movl    $12, %eax
    popq    %rbp
    ret
LBB0_4:                                 ## %sw.bb2
    movl    $10, %eax
    popq    %rbp
    ret
LBB0_5:                                 ## %entry
    cmpl    $18, %edi
    jne    LBB0_10
## BB#6:                                ## %sw.bb3
    movl    $5, %eax
    popq    %rbp
    ret
LBB0_7:                                 ## %sw.bb4
    movl    $3, %eax
    popq    %rbp
    ret
LBB0_8:                                 ## %sw.bb5
    movl    $1, %eax
    popq    %rbp
    ret
LBB0_9:                                 ## %sw.bb6
    movl    $19, %eax
    popq    %rbp
    ret
LBB0_10:                                ## %sw.default
    movl    $6, %eax
LBB0_11:                                ## %return
    popq    %rbp
    ret
Ltmp6:
Leh_func_end0:
    .align    2, 0x90
L$start$jt32$0:
L0_0_set_9 = LBB0_9-LJTI0_0
L0_0_set_7 = LBB0_7-LJTI0_0
L0_0_set_10 = LBB0_10-LJTI0_0
L0_0_set_11 = LBB0_11-LJTI0_0
L0_0_set_8 = LBB0_8-LJTI0_0
L0_0_set_3 = LBB0_3-LJTI0_0
L0_0_set_4 = LBB0_4-LJTI0_0
LJTI0_0:
    .long    L0_0_set_9
    .long    L0_0_set_7
    .long    L0_0_set_10
    .long    L0_0_set_10
    .long    L0_0_set_11
    .long    L0_0_set_8
    .long    L0_0_set_10
    .long    L0_0_set_10
    .long    L0_0_set_3
    .long    L0_0_set_10
    .long    L0_0_set_4

where as gcc 4.6 produces:
        .text
        .align 4,0x90
        .globl __Z3fooi
__Z3fooi:
LFB0:
        subl    $1, %edi
        movl    $6, %eax
        cmpl    $17, %edi
        ja      L2
        leaq    _CSWTCH.1(%rip), %rax
        movl    (%rax,%rdi,4), %eax
L2:
        rep
        ret
LFE0:
        .const
        .align 5
_CSWTCH.1:
        .long   19
        .long   3
        .long   6
        .long   6
        .long   17
        .long   1
        .long   6
        .long   6
        .long   12
        .long   6
        .long   10
        .long   6
        .long   6
        .long   6
        .long   6
        .long   6
        .long   6
        .long   5

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